Вы находитесь на странице: 1из 7

Expt. No.

IIR FILTER DESIGN USING MATLAB

Objectives: a) To design IIR digital filter using Butterworth analog filter b) To design IIR digital filter using Chebyshev (Type I and II) analog filters Equipments required: PC installed with MATLAB Theory: References:

1) Sanjith K. Mitra, Digital Signal Processing- A Computer-Based Approach, 3e (Chapter 9) 2) Vinay K. Ingle & John G. Proakis, Digital Signal Processing- A MATLAB-Based Approach (Chapter 8) 3) Emmanuel C. Ifeachor & Barrie W Jervis, Digital Signal Processing- A Practical Approach 2e (Chapter 8)

Attention:
Those who are not completed the theory and pre-lab assignments should not be allowed to do the experiment.
 IIR Filter Basics: (All of you prepare the details of the followings) 1. Ideal frequency spectrum of filters: 2. Practical magnitude spectrum of low pass filter 3. Recursive equation for IIR filters 4. Transfer function of IIR filter IIR filter design through analog filters: (All of you prepare the details of the followings) 1. How the IIR filters are designed using analog filters? 2. Transformation methods: a) Impulse invariant Mapping equations Analog and digital frequency relationship b) Bilinear Mapping equations Analog and digital frequency relationship MATLAB functions: 1)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. % EXAMPLE: Illustrate the relationship between digital and analog % magnitude responses. [b,a] = butter(4,0.3,'s'); [bz,az] = impinvar(b,a,10); [Ha,Wa] = freqs(b,a,512); [Hz,Wz] = freqz(bz,az,512,10); plot(Wa/(2*pi),20*log10(abs(Ha))); hold on; plot(Wz,20*log10(abs(Hz))) 2) BILINEAR Bilinear transformation with optional frequency prewarping. [Zd,Pd,Kd] = BILINEAR(Z,P,K,Fs) converts the s-domain transfer function specified by Z, P, and K to a z-transform discrete equivalent obtained from the bilinear transformation: where column vectors Z and P specify the zeros and poles, scalar K specifies the gain, and Fs is the sample frequency in Hz. [NUMd,DENd] = BILINEAR(NUM,DEN,Fs), where NUM and DEN are row vectors containing numerator and denominator transferfunction coefficients, NUM(s)/DEN(s), in descending powers of s, transforms to z-transform coefficients NUMd(z)/DENd(z). 3.Butterworth Approximation: (All of you prepare the details of the followings) 1. Magnitude response for different order of the filter 2. Transfer function of the Butterworth filter H(j ) 3. Equation for order of the filter N 4. Equation for Cut-off frequency C 5. Transfer function of the filter H(s) and equations for the coefficients 6. Steps to design a filter using the following parameters: a) Pass band and stop band ripples in dB b) Pass band and stop band edge frequencies

MATLAB functions: 1) BUTTORD Butterworth filter order selection. [N, Wn] = BUTTORD(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Butterworth filter that loses no more than Rp dB in the passband and has at least Rs dB of attenuation in the stopband. Wp and Ws are the passband and stopband edge frequencies, normalized from 0 to 1 (where 1 corresponds to pi radians/sample). For example,

Lowpass: Wp = .1, Ws = .2 Highpass: Wp = .2, Ws = .1 Bandpass: Wp = [.2 .7], Ws = [.1 .8] Bandstop: Wp = [.1 .8], Ws = [.2 .7] BUTTORD also returns Wn, the Butterworth natural frequency (or, the "3 dB frequency") to use with BUTTER to achieve the specifications. [N, Wn] = BUTTORD(Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in which case Wp and Ws are in radians/second. When Rp is chosen as 3 dB, the Wn in BUTTER is equal to Wp in BUTTORD. 2) BUTTER Butterworth digital and analog filter design. [B,A] = BUTTER(N,Wn) designs an Nth order lowpass digital Butterworth filter and returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator). The coefficients are listed in descending powers of z. The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. If Wn is a two-element vector, Wn = [W1 W2], BUTTER returns an order 2N bandpass filter with passband W1 < W < W2. [B,A] = BUTTER(N,Wn,'high') designs a highpass filter. [B,A] = BUTTER(N,Wn,'low') designs a lowpass filter. [B,A] = BUTTER(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2]. When used with three left-hand arguments, as in [Z,P,K] = BUTTER(...), the zeros and poles are returned in length N column vectors Z and P, and the gain in scalar K. BUTTER(N,Wn,'s'), BUTTER(N,Wn,'high','s') and BUTTER(N,Wn,'stop','s') design analog Butterworth filters. In this case, Wn is in [rad/s] and it can be greater than 1.0. 4. Chebychev Approximation: (All of you prepare the details of the followings) 1. Magnitude response for different order of the filter Type-I and Type-II 2. Transfer function of the Type-I and Type-II filters H(j ) 3. Equation for Chebyshev polynomial 4. Equation for order of the filter N (Type-I and Type-II) 5. Equation for filter parameter (Type-I and Type-II) 6. Equation for Cut-off frequency C 7. Transfer function of the filter H(s) and equations for the coefficients MATLAB functions: 1) CHEB1ORD Chebyshev Type I filter order selection. [N, Wp] = CHEB1ORD(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Chebyshev Type I filter that loses no more than Rp dB in the passband and has at least Rs dB of

attenuation in the stopband. Wp and Ws are the passband and stopband edge frequencies, normalized from 0 to 1 (where 1 corresponds to pi radians/sample). For example, Lowpass: Wp = .1, Ws = .2 Highpass: Wp = .2, Ws = .1 Bandpass: Wp = [.2 .7], Ws = [.1 .8] Bandstop: Wp = [.1 .8], Ws = [.2 .7] CHEB1ORD also returns Wp, the Chebyshev natural frequency to use with CHEBY1 to achieve the specifications. [N, Wp] = CHEB1ORD(Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in which case Wp and Ws are in radians/second. 2) CHEB2ORD Chebyshev Type II filter order selection. [N, Ws] = CHEB2ORD(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Chebyshev Type II filter that loses no more than Rp dB in the passband and has at least Rs dB of attenuation in the stopband. Wp and Ws are the passband and stopband edge frequencies normalized from 0 to 1 (where 1 corresponds to pi radians/sample). For example, Lowpass: Wp = .1, Ws = .2 Highpass: Wp = .2, Ws = .1 Bandpass: Wp = [.2 .7], Ws = [.1 .8] Bandstop: Wp = [.1 .8], Ws = [.2 .7] CHEB2ORD also returns Wst, the Chebyshev natural frequency to use with CHEBY2 to achieve the specifications. [N, Ws] = CHEB2ORD(Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in which case Wp and Ws are in radians/second. 3) CHEBY1 Chebyshev Type I digital and analog filter design. [B,A] = CHEBY1(N,R,Wp) designs an Nth order lowpass digital Chebyshev filter with R decibels of peak-to-peak ripple in the passband. CHEBY1 returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator). The passband-edge frequency Wp must be 0.0 < Wp < 1.0, with 1.0 corresponding to half the sample rate. Use R=0.5 as a starting point, if you are unsure about choosing R. If Wp is a two-element vector, Wp = [W1 W2], CHEBY1 returns an order 2N bandpass filter with passband W1 < W < W2. [B,A] = CHEBY1(N,R,Wp,'high') designs a highpass filter. [B,A] = CHEBY1(N,R,Wp,'low') designs a lowpass filter. [B,A] = CHEBY1(N,R,Wp,'stop') is a bandstop filter if Wp = [W1 W2]. When used with three left-hand arguments, as in [Z,P,K] = CHEBY1(...), the zeros and poles are returned in length N column vectors Z and P, and the gain in scalar K. CHEBY1(N,R,Wp,'s'), CHEBY1(N,R,Wp,'high','s') and CHEBY1(N,R,Wp,'stop','s') design analog Chebyshev Type I filters. In this case, Wp is in [rad/s] and it can be greater than 1.0.

4) CHEBY2 Chebyshev Type II digital and analog filter design. [B,A] = CHEBY2(N,R,Wst) designs an Nth order lowpass digital Chebyshev filter with the stopband ripple R decibels down and stopband-edge frequency Wst. CHEBY2 returns the filter coefficients in length N+1vectors B (numerator) and A (denominator). The stopband-edge frequency Wst must be 0.0 < Wst < 1.0, with 1.0 corresponding to half the sample rate. Use R = 20 as a starting point, if you are unsure about choosing R. If Wst is a two-element vector, Wst = [W1 W2], CHEBY2 returns an order 2N bandpass filter with passband W1 < W < W2. [B,A] = CHEBY2(N,R,Wst,'high') designs a highpass filter. [B,A] = CHEBY2(N,R,Wst,'low') designs a lowpass filter. [B,A] = CHEBY2(N,R,Wst,'stop') is a bandstop filter if Wst = [W1 W2]. When used with three left-hand arguments, as in [Z,P,K] = CHEBY2(...), the zeros and poles are returned in length N column vectors Z and P, and the gain in scalar K. CHEBY2(N,R,Wst,'s'), CHEBY2(N,R,Wst,'high','s') and CHEBY2(N,R,Wst,'stop','s') design analog Chebyshev Type II filters. In this case, Wst is in [rad/s] and it can be greater than 1.0. 5. Frequency Band Transformation: (All of you prepare the details of the followings) 1. Analog filter: 2. Digital filters:

MATLAB functions: 1) LP2LP Lowpass to lowpass analog filter transformation. [NUMT,DENT] = LP2LP(NUM,DEN,Wo) transforms the lowpass filter prototype NUM(s)/DEN(s) with unity cutoff frequency of 1 rad/sec to a lowpass filter with cutoff frequency Wo (rad/sec). 2) LP2HP Lowpass to highpass analog filter transformation. [NUMT,DENT] = LP2HP(NUM,DEN,Wo) transforms the lowpass filter prototype NUM(s)/DEN(s) with unity cutoff frequency to a highpass filter with cutoff frequency Wo. 3) LP2BP Lowpass to bandpass analog filter transformation. [NUMT,DENT] = LP2BP(NUM,DEN,Wo,Bw) transforms the lowpass filter prototype NUM(s)/DEN(s) with unity cutoff frequency to a bandpass filter with center frequency Wo and bandwidth Bw. 4) LP2BS Lowpass to bandstop analog filter transformation. [NUMT,DENT] = LP2BS(NUM,DEN,Wo,Bw) transforms the lowpass filter prototype NUM(s)/DEN(s) with unity cutoff frequency to a bandstop filter with center frequency Wo and bandwidth Bw.

Pre-lab Assignments: 1. An IIR digital low-pass filter is required to meet the following specifications: Pass band ripple (or peak-to-peak ripple): 0.5 dB Passband edge: 1.2 kHz Stopband attenuation: 40 dB Stopband edge: 2.0 kHz Sample rate: 8.0 kHz Use the design formulas to determine the required filter order and cut-off frequency for (a) A digital Butterworth filter (b) A digital Chebyshev filter 2. We wish to design a digital bandpass filter from a second-order analog lowpass Butterworth filter prototype using the bilinear transformation. The specifications on the digital filter are shown in the following figure:

The cutoff frequencies (measured at the half power points) for the digital filter should lie at and . The analog prototype is given by

with the half-power point at = 1. Determine the system function for digital band pass filter. 3. An IIR low pass digital filter has a normalized pass band edge frequency =0.3 . What is the pass band edge frequency in Hz of the prototype analog low pass filter if the digital filter has been designed using the impulse invariance method with sampling period T=0.1ms? What is the pass band edge frequency in Hz of the prototype analog low pass filter if the digital filter has been designed using the bilinear transformation method with sampling period T=0.1ms?

Algorithm: a) Low pass Filter 1. Start 2. Enter pass band ripple and stop band ripples in dB 3. Enter pass band edge and stop band edge frequencies in Hz or in normalized form in radians 4. Enter sampling frequency in samples/second 5. Compute normalization to edge frequencies, if the entered frequencies are in Hz. Otherwise go to next step. 6. Find orders and cut-off frequencies of the filters using buttord( ), cheb1ord( ) and cheb2ord( ) functions and display the values for verification 7. Compute the transfer functions in s-domain for low pass filter using butter( ), cheby1( ) and cheby2( ) 8. Transform the transfer functions to z-domain by impinvar( ) and bilinear( ) 9. Compute the frequency responses of each type using freqz( ) function 10. Plot the each magnitude responses with suitable titles 11. Stop b)High pass filter(same steps, except 7. Use the functions for high pass filter) c)Band pass filter(same steps, except 7. Use the functions for band pass filter) d)Band stop filter(same steps, except 7. Use the functions for band stop filter) Note: MATLAB function: FREQZ Digital filter frequency response. [H,W] = FREQZ(B,A,N) returns the N-point complex frequency response vector H and the Npoint frequency vector W in radians/sample of the filter:

given numerator and denominator coefficients in vectors B and A. The frequency response is evaluated at N points equally spaced around the upper half of the unit circle. If N isn't specified, it defaults to 512. [H,W] = FREQZ(B,A,N,'whole') uses N points around the whole unit circle. H = FREQZ(B,A,W) returns the frequency response at frequencies designated in vector W, in radians/sample (normally between 0 and pi). [H,F] = FREQZ(B,A,N,Fs) and [H,F] = FREQZ(B,A,N,'whole',Fs) return frequency vector F (in Hz), where Fs is the sampling frequency (in Hz). H = FREQZ(B,A,F,Fs) returns the complex frequency response at the frequencies designated in vector F (in Hz), where Fs is the sampling frequency (in Hz). FREQZ(B,A,...) with no output arguments plots the magnitude and unwrapped phase of the filter in the current figure window.

Вам также может понравиться