Digital Signal Processing using Matlab 5.3
     <<Home Lab 10                                    (Design of IIR Filters)
   

MATLAB has a number of built-in functions for IIR filter design, Some of these include following.

butter                            % Analog Butterwoth filter

buttord                         % order of butterworth filter

cheby1                          % Type 1 Chebyshev filter

impinvar                        % Impulse inversion method

bilinear                          % Bilinear Transformation

 Conversion of analogue filter into digital filter                                                                                                                                                                                                                               

Example 1                                                                                                                                 

 It is required to design a digital filter to a design a digital filter to approximate the following normalized analog transfer function:

H(s) = 1/(s2+1.414s+1)

Use the impulse invariant method to obtain the transfer function, H(z), of the digital filter, assuming a 3dB cut-off frequency of 150Hz and a sampling frequency of 1.28kHz.

 Solution                                                                                                                                   

n=2;

fs=1280;

fc=150;

wc=2*pi*fc;

[num,den]=butter(n,wc,'s');

[numd,dend]=impinvar(num,den,fs);

[h,f]=freqz(numd,dend,512,fs);

h1=abs(h);

mag=20*log10(h1);

plot(f,mag); grid;

ylabel('Magnitude response(dB)');

xlabel('Frequency(Hz)');

Result                                                                                                                                       

               

               

 Transfer function using bilinear transformation                                                                            

                                                                                                                                                 

Example 2                                                                                                                                 

 A requirement exists to simulate in a digital computer an analogue system with the following normalized characteristics:

H(s) = 1/(s2 + 1.414s + 1)

Obtain a transfer function using the bilinear transformation.

Assume a sampling frequency of 1.28 kHz and a 3 dB cut-off frequency of 150Hz.

Plot pole-zero diagram, impulse response and step response.

 Solution                                                                                                                                   

     clear

fs=1280;

wp=2*pi*150;

fn=fs/2;

t=1/fs;

wpp=tan(wp*t/2);

[num,den]=butter(2,1,'s'); %analog

printsys(num,den);

[num1,den1]=lp2lp(num,den,wpp);% denormailized

printsys(num1,den1);

[numd,dend]=bilinear(num1,den1,fn/fs);% digital reponse

printsys(numd,dend,'z');

[h,f]=freqz(numd,dend,512,fs);

mag=abs(h);

plot(f,mag); grid;

ylabel('Magnitude response(dB)');

xlabel('Frequency(Hz)');

figure

poles=roots(numd)

zeros=roots(dend)

zplane(numd,dend);

figure;

dimpulse(numd,dend);

figure;

dstep(numd,dend);

Result                                                                                                                                       

Normalized analog Butterworth filter

                                 1

 num/den  =    ------------------

                     s^2 + 1.4142 s + 1

     

Low pass to low pass transformation

                                0.1488
 num/den  = ------------------------
                     s^2 + 0.54552 s + 0.1488

 

Bilinear transformation

 

                        0.087821 z^2 + 0.17564 z + 0.087821
num/den  =     ------------------------------------------
                              z^2 - 1.0048 z + 0.35606

 

poles =

-1.00000004470348
-0.99999995529652


zeros =

0.50238610485153 + 0.32197133163019i
0.50238610485153 - 0.32197133163019i

                   

                                  

 Second order high pass digital filter                                                                                           

                                                                                                                                                 

Exercise 2                                                                                                                                 

  Design a second order high pass digital filter with cut off frequency of 30Hz and a sampling frequency of 150Hz. Sketch magnitude response, phase response, impulse response, step response and pole-zero diagram of the filter.

Hint: replace the command lp2lp lp2hp in example 2.

 Solution                                                                                                                                    

     clear

fs=150;

wp=2*pi*30; % fc=30Hz cut off frequency

fn=fs/2;

t=1/fs;

wpp=tan(wp*t/2);

[num,den]=butter(2,1,'s'); %analog

printsys(num,den);

[num1,den1]=lp2hp(num,den,wpp);% denormailized

printsys(num1,den1);

[numd,dend]=bilinear(num1,den1,fn/fs);% digital reponse

printsys(numd,dend,'z');

[h,f]=freqz(numd,dend,512,fs);

mag=20*log10(abs(h));

plot(f,mag); grid;

ylabel('Magnitude response(dB)');

xlabel('Frequency(Hz)');

figure

poles=roots(numd)

zeros=roots(dend)

zplane(numd,dend);

figure;

dimpulse(numd,dend);

figure;

dstep(numd,dend);

 Result                                                                                                                                       

 A discrete time bandpass filter with Butterworth characteristic                                                    

                                                                                                                                                  

Example 3                                                                                                                                  

  A discrete time band-pass filter with Butterworth characteristics  meeting the following specifications is required:

band-pass                            200 - 300 Hz

Sampling frequency           2 kHz

Filter order                           2

 Solution                                                                                                                                    

     fs=2000;

wp1=2*pi*200;

wp2=2*pi*300;

fn=fs/2;

t=1/fs;

wpp1=tan(wp1*t/2);

wpp2=tan(wp2*t/2);

w=(wpp1+wpp2)/2;

bw=wpp2-wpp1;

[num,den]=butter(1,1,'s');

printsys(num,den)

[num1,den1]=lp2bp(num,den,w,bw);

printsys(num1,den1)

[numd,dend]=bilinear(num1,den1,fn/fs);

printsys(numd,dend,'z')

[h,f]=freqz(numd,dend,512,fs);

mag=abs(h);

plot(f,mag),

grid

poles=roots(numd);

zeros=roots(dend);

figure;

zplane(numd,dend);

figure;

dimpulse(numd,dend);

figure;

dstep(numd,dend);

 Result                                                                                                                                       

 A discrete time band-stop filter with Butterworth characteristic                                                   

                                                                                                                                                  

Exercise  3                                                                                                                                 

  A discrete time band-stop filter with Butterworth characteristics  meeting the following specifications is required. Obtain the coefficients of the filter using the BLT method.

stop-band                            200 - 300 Hz

Sampling frequency           2 kHz

Filter order                           2

 Solution                                                                                                                                    

     fs=2000;

wp1=2*pi*200;

wp2=2*pi*300;

fn=fs/2;

t=1/fs;

wpp1=tan(wp1*t/2);

wpp2=tan(wp2*t/2);

w=(wpp1+wpp2)/2;

bw=wpp2-wpp1;

[num,den]=butter(1,1,'s');

printsys(num,den)

[num1,den1]=lp2bs(num,den,w,bw);

printsys(num1,den1)

[numd,dend]=bilinear(num1,den1,fn/fs);

printsys(numd,dend,'z')

[h,f]=freqz(numd,dend,512,fs);

mag=abs(h);

plot(f,mag),

grid

poles=roots(numd);

zeros=roots(dend);

figure;

zplane(numd,dend);

figure;

dimpulse(numd,dend);

figure;

dstep(numd,dend);

 Result                                                                                                                                       

Normalized analog Butterworth filter

                  1
num/den = -----
                  s + 1

Low pass to band- stop transformation

                      s^2 + 0.17407
num/den = -------------------------
                s^2 + 0.18461 s + 0.17407

Bilinear transformation
 

                 0.86413 z^2 - 1.2158 z + 0.86413
num/den = --------------------------------
                     z^2 - 1.2158 z + 0.72826

 

 HELP                                                                                                                                       

 PLOT                                                                                                                                       

 PLOT Linear plot.
PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, length(Y) disconnected points are plotted.

 C2DM                                                                                                                                      

C2DM Conversion of continuous LTI systems to discrete-time.

[Ad,Bd,Cd,Dd] = C2DM(A,B,C,D,Ts,'method') converts the continuous-time state-space system (A,B,C,D) to discrete time using 'method':
'zoh' Convert to discrete time assuming a zero order hold on the inputs.
'foh' Convert to discrete time assuming a first order hold on the inputs.
'tustin' Convert to discrete time using the bilinear (Tustin) approximation to the derivative.
'prewarp' Convert to discrete time using the bilinear  (Tustin) approximation with frequency prewarping.
Specify the critical frequency with an additional argument, i.e. C2DM(A,B,C,D,Ts,'prewarp',Wc)
'matched' Convert the SISO system to discrete time using the matched pole-zero method.

[NUMd,DENd] = C2DM(NUM,DEN,Ts,'method') converts the continuous-time polynomial transfer function G(s) = NUM(s)/DEN(s) to discrete time, G(z) = NUMd(z)/DENd(z), using 'method'.

 IMPINVAR                                                                                                                              

IMPINVAR Impulse invariance method for analog to digital filter conversion.
[BZ,AZ] = IMPINVAR(B,A,Fs) creates a digital filter with numerator and denominator coefficients BZ and AZ respectively whose impulse response is equal to the impulse response of the analog filter with  coefficients B and A sampled at a frequency of Fs Hertz. The B and A coefficients will be scaled by 1/Fs.

If you don't specify Fs, it defaults to 1 Hz.

[BZ,AZ] = IMPINVAR(B,A,Fs,TOL) uses the tolerance TOL for grouping repeated poles together. Default value is 0.001, i.e., 0.1%.


NOTE: the repeated pole case works, but is limited by the ability of the function ROOTS to factor such polynomials.


DSP Lab 1   DSP Lab2   DSP Lab 3   DSP Lab4   DSP Lab 5   DSP Lab 6   DSP Lab7  DSP Lab8  DSP Lab9  DSP Lab10   DSP Lab 11  Other material


   
 
                                                                                                                   <<Home
  
Ziauddin Siddiqui, B02ME CSN 07, Mehran University Of Engineering & Technology
Jamshoro, Sindh.
Email. [email protected]

1