A low pass digital filter (IIR) is designed based on given specifications. Butterworth analog
filter
Analytical procedure is illustrated below and simplified to allow one to more easily program the algorithm. Four different numerical examples are used to illustrate the procedure.
This report derives a symbolic procedure to design a low pass IIR digital filter from an analog Butterworth filter using 2 methods: impulse invariance and bilinear transformation. Two numerical examples are used to illustrate using the symbolic procedure.
There are a total of 13 steps. A Mathematica program with GUI is written to enable one to use this design for different parameters. A Matlab script is written as well.
Filter specifications are 5 parameters. The frequency specifications use analog frequencies, while the attenuation for the passband and the stopband are given in db units.
|
The sampling frequency in Hz |
|
The passband cutoff frequency in Hz |
| The stopband corner frequency in Hz |
| The attenuation in db at |
|
The attenuation in db at |
This diagram below illustrates these specifications
The frequency specifications are in hz, and they are first converted to digital frequencies
The analytical design procedure is given below.
Analog specifications is converted to digital specifications:
Therefore
Notice that
Hence
For impulse invariance,
Changing inequalities to equalities and simplifying gives
Dividing the above two equations results in
The above is later rounded to the nearest integer using the Ceiling function
For impulse invariance method, using equation (1) above to solve for
Now that
Only the LHS poles needs to be found, and these are located at
Now the analog filter is generated based on the above selected poles, which for impulse
invariance gives
The poles are written in non-polar form and substituted into (3) which gives
Now that
First step is to convert analog specifications to digital specifications:
Converting the criteria relative to the digital normalized scale gives
Hence
Butterworth analog filter squared magnitude Fourier transform is given by
Values for
Changing inequalities to equalities and simplifying gives
Dividing the above 2 equations results in
The above is rounded to the nearest integer using the Ceiling function. i.e.
For bilinear transformation equation (2) is used to find
Now that
Only need the LHS poles are needed, which are located at
Table with the derivation equations is made to follow to design in either bilinear or impulse
invariance. Note that the same steps are used in both designs except for step
.
step | Impulse invariance | common equation | bilinear |
|
|
||
|
|
||
|
|
||
|
|
||
|
|
| |
|
|
| |
|
| ||
| | |
|
| poles of H(S) | ||
|
|
||
|
|
| |
do partial fractions: | |||
|
|
||
|
|
| |
Sampling frequency
step | Impulse invariance |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
poles of H(S) |
| |
| |
|
|
|
|
| |
|
|
|
|
|
|
|
partial fraction |
|
|
|
|
|
|
|
|
|
|
|
|
Using the above design table, these are the numerical values:
step | Bilinear |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
poles of H(S) |
| |
| |
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sampling frequency
step | Impulse invariance |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
poles of H(S) |
|
|
|
|
|
|
|
partial fraction |
|
|
|
|
step | Impulse invariance |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| poles of H(S) |
|
|
|
|
|
|
|
|
|
|
|
|
Mathematica GUI program is written to implement the above. It can be downloaded from here
Also a Matlab script nma_filter.m.txt was written (no GUI) to implement this design.
This script (written on Matlab 2007a). This script does not handle the conversion from H(s) to H(z) well yet, need to work more on this... of course, one can just use Matlab butter() function for this.
Example output of the above Matlab script is matlab_output.txt
This is another small note on IIR design for minimum order filter.
This document describes how to design an IIR digital filter given a specification in which the filter order is specified.
Given the following diagram, the specifications for the design will be
We first convert analog specifications to digital specifications:
Then the cutoff frequency
Next find the poles of
We need to make sure that we multiply poles of complex conjugates with each others to make the result simple to see.
Now that we have
We first convert analog specifications to digital specifications:
Now
Now that we have
Now we need to write poles in non-polar form and plug them into (3)
The following is listing of the Matlab script, and a sample run output
%Simple matlab script to design an IIR low pass filter using %butterworth in either impulse inv. or bilinear method. % % EE 420, CSU Fullerton % % by Nasser M. Abbasi % 5/5/201 % Filter SPECIFICATIONS clear all; close all; Fs=10000; fp=1000; fs=2000; dbp=-3; dbs=-10; BILINEAR=1; %set this to 0 to do impulse inv. %%%%%%%%%%%%%%%%%%%% fprintf('***** STARTING DESIGN *******\n'); fprintf('Sampling frequency=%f Hz\n',Fs); fprintf('freq at passband=%f Hz\n',fp); fprintf('freq at stopband=%f Hz\n',fs); fprintf('db at passband=%f \n',dbp); fprintf('db at stopband=%f \n',dbs); if BILINEAR fprintf('Doing Bilinear method\n'); else fprintf('Doing impulse invariance method\n'); end if BILINEAR T=1/Fs; else T=1; end fprintf('T=%f\n',T); wp=2*pi*fp/Fs; ws=2*pi*fs/Fs; alphap=1/(10^(dbp/10)); alphas=1/(10^(dbs/10)); if BILINEAR gammap=2/T * tan(wp/2); else gammap=wp/T; end if BILINEAR gammas=2/T * tan(ws/2); else gammas=ws/T; end oldn=.5*(log10(alphap-1)-log10(alphas-1))/(log10(gammap)-log10(gammas)); n=ceil(oldn); fprintf('n=%f, rounded to %d\n',oldn,n); if BILINEAR gammaC=gammas/(10^(1/(2*n)*log10(alphas-1))); else gammaC=gammap/(10^(1/(2*n)*log10(alphap-1))); end fprintf('Gamma C =%f\n',gammaC); poles_of_hs=zeros(n,1); for i=0:n-1 poles_of_hs(i+1)=gammaC*exp(sqrt(-1)*(pi*(1+2*i+n)/(2*n))); end fprintf('POLES Of H(s)\n'); poles_of_hs k=prod(-poles_of_hs); den=poly(poles_of_hs); fprintf('k=%d\n',k); fprintf('H(s)=\n',k); if BILINEAR hs=tf(k,den) else hs=tf(T*k,den) end [r,p,k]=residue(k,den); hzp=zeros(n,1); for i=1:n hzp(i)=exp(p(i)*T); end fprintf('POLES Of H(z)\n'); hzp [B,A]=residue(r,hzp); fprintf('H(z)=\n',k); hz=tf(T*B',A')
***** STARTING DESIGN ******* Sampling frequency=20000.000000 Hz freq at passband=2000.000000 Hz freq at stopband=3000.000000 Hz db at passband=-1.000000 db at stopband=-15.000000 Doing impulse invariance method T=1.000000 n=5.885783, rounded to 6 Gamma C =0.703205 POLES Of H(s) poles_of_hs = -0.182002858631059 + 0.679243915533887i -0.497241056902828 + 0.497241056902828i -0.679243915533887 + 0.182002858631059i -0.679243915533887 - 0.182002858631059i -0.497241056902828 - 0.497241056902828i -0.182002858631059 - 0.679243915533887i k=1.209183e-001 H(s)= Warning: Transfer function has complex coefficients. > In tf.tf at 246 In nma_filter at 92 Transfer function: (0.1209-1.041e-016i) ---------------------------------------------------------------------------- s^6 + (2.717-4.441e-016i) s^5 + (3.691-1.998e-015i) s^4 + (3.179 -2.22e-015i) s^3 + (1.825-1.554e-015i) s^2 + (0.6644-4.996e-016i) s + (0.1209-1.041e-016i) POLES Of H(z) hzp = 0.534553736986506 + 0.290115961427623i 0.534553736986506 - 0.290115961427623i 0.648579932539211 + 0.523670977796743i 0.648579932539211 - 0.523670977796743i 0.498626135868541 - 0.0917668874413562i 0.498626135868543 + 0.0917668874413561i H(z)= Warning: Transfer function has complex coefficients. > In tf.tf at 246 In nma_filter at 107 Transfer function: -(0.9938-0.8577i) s^4 - (0.22-0.703i) s^3 + (1.377+1.095i) s^2 - (0.6574 +2.854i) s - (0.9146-1.114i) -------------------------------------------------------------------------- -(0.6979+1.411i) s^4 + (0.6009-0.8998i) s^3 - (0.03618-0.9428i) s^2 + (0.1901+0.7751i) s - (0.6018+0.246i) ============================================================= ***** STARTING DESIGN ******* Sampling frequency=20000.000000 Hz freq at passband=2000.000000 Hz freq at stopband=3000.000000 Hz db at passband=-1.000000 db at stopband=-15.000000 Doing Bilinear method T=0.000050 n=5.304446, rounded to 6 Gamma C =15324.588619 POLES Of H(s) poles_of_hs = -3966.29539304108 + 14802.4159246557i -10836.1205316146 + 10836.1205316146i -14802.4159246557 + 3966.29539304109i -14802.4159246557 - 3966.29539304109i -10836.1205316146 - 10836.1205316146i -3966.29539304108 - 14802.4159246557i k=1.295188e+025 H(s)= Warning: Transfer function has complex coefficients. > In tf.tf at 246 In nma_filter at 90 Transfer function: (1.295e025-1.288e010i) -------------------------------------------------------------------------- s^6 + (5.921e004-7.276e-012i) s^5 + (1.753e009-3.576e-007i) s^4 + (3.29e013-0.01172i) s^3 + (4.117e017-224i) s^2 + (3.265e021 -2.49e006i) s + (1.295e025-1.288e010i) POLES Of H(z) hzp = 0.498385402712059 + 0.299971817994199i 0.49838540271206 - 0.299971817994199i 0.467705977269569 - 0.0939883945094121i 0.605559876472429 + 0.553064536118524i 0.467705977269569 + 0.0939883945094127i 0.60555987647243 - 0.553064536118524i H(z)= Warning: Transfer function has complex coefficients. > In tf.tf at 246 In nma_filter at 107 Transfer function: -(0.5053-1.947i) s^4 + (0.02086-1.348i) s^3 - (0.9771+0.04836i) s^2 + (0.01411+0.02526i) s - (0.3816-0.3931i) -------------------------------------------------------------------------- (0.1988-1.53i) s^4 + (0.6374+0.9373i) s^3 - (1.064+0.2778i) s^2 - (0.7076-0.6148i) s + (0.4667-0.6282i) ================================================================= Sampling frequency=10000.000000 Hz freq at passband=1000.000000 Hz freq at stopband=2000.000000 Hz db at passband=-3.000000 db at stopband=-10.000000 Doing impulse invariance method T=1.000000 n=1.588388, rounded to 2 Gamma C =0.629065 POLES Of H(s) poles_of_hs = -0.444816082052343 + 0.444816082052343i -0.444816082052343 - 0.444816082052343i k=3.957227e-001 H(s)= Warning: Transfer function has complex coefficients. > In tf.tf at 246 In nma_filter at 92 Transfer function: (0.3957-8.327e-017i) --------------------------------------------------- s^2 + (0.8896-5.551e-017i) s + (0.3957-8.327e-017i) POLES Of H(z) hzp = 0.578571949761589 + 0.275792192443573i 0.578571949761589 - 0.275792192443573i H(z)= Warning: Transfer function has complex coefficients. > In tf.tf at 246 In nma_filter at 107 Transfer function: (-6.9e-016+1.253i) ====================================== Sampling frequency=10000.000000 Hz freq at passband=1000.000000 Hz freq at stopband=2000.000000 Hz db at passband=-3.000000 db at stopband=-10.000000 Doing Bilinear method T=0.000100 n=1.368163, rounded to 2 Gamma C =8389.390482 POLES Of H(s) poles_of_hs = -5932.19490014964 + 5932.19490014964i -5932.19490014964 - 5932.19490014964i k=7.038187e+007 H(s)= Warning: Transfer function has complex coefficients. > In tf.tf at 246 In nma_filter at 90 Transfer function: (7.038e007-2.235e-008i) --------------------------------------------------------- s^2 + (1.186e004-9.095e-013i) s + (7.038e007-2.235e-008i) POLES Of H(z) hzp = 0.458140439181504 - 0.308891358305335i 0.458140439181504 + 0.308891358305335i H(z)= Warning: Transfer function has complex coefficients. > In tf.tf at 246 In nma_filter at 107 Transfer function: (2.058e-016-1.78i) EDU>>