Lab 9:desig N A ND Implem Entat Io N of I Ir F Ilter: Digital Signal Processing Laboratory
Lab 9:desig N A ND Implem Entat Io N of I Ir F Ilter: Digital Signal Processing Laboratory
NAME:
DATE OF EXPERIMENT:
1
DIGITAL SIGNAL PROCESSING LABORATORY
1 THEORY
1.1 INTRODUCTION
The most common method of IIR lter design is based on the bilinear transformation of a
prototype analog transfer function. The analog transfer function is usually one of the following
types: Butterworth, Type 1 Chebyshev, Type 2 Chebyshev, and elliptic transfer functions. The
difference between these lter types can be explained by considering the analog lowpass lter.
The Butterworth lowpass transfer function has a maximally-at magnitude response at dc, that
is, =0, and a monotonically decreasing magnitude response with increasing frequency. The
Type 1 Chebyshev lowpass transfer function has an equiripple magnitude response in the
passband and a monotonically decreasing magnitude response with increasing frequency
outside the passband. The Type 2 Chebyshev lowpass transfer function has a monotonically
decreasing magnitude response in the passband with increasing frequency and an equiripple
magnitude response in the stopband. Finally, the elliptic lowpass transfer function has
equiripple magnitude responses both in the passband and in the stopband.
[H,W] = FREQZ(B,A,N):
When N is an integer, [H,W] = FREQZ(B,A,N) returns the N-point frequency vector W in radians
and the N-point complex frequency response vector H of the filter B/A:
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.
Y = FILTER(B,A,X):
It filters the data in vector X with the filter described by vectors A and B to create the filtered
data Y. For FIR filters A=1 because they do not contain any poles. The filter is a "Direct Form II
Transposed implementation of the standard difference equation:
2
DIGITAL SIGNAL PROCESSING LABORATORY
BUTTORD FUNCTION
The MATLAB command for estimating the order of a Butterworth lter is
where the input parameters are the normalized passband edge frequency Wp, the normalized
stopband edge frequency Ws, the passband ripple Rp in dB, and the minimum stopband
attenuation Rs in dB. Both Wp and Wsmust be a number between 0 and 1with the sampling
frequency assumed to be 2 Hz. The output data are the lowest order N meeting the specifications
and the normalized cutoff frequency Wn. If Rp = 3 dB, then Wn = Wp. Buttord can also be used to
estimate the order of a highpass, a bandpass, and a bandstop Butterworth filter. For a highpass
filter design,Wp > Ws. For bandpass and bandstop filter designs, Wp and Ws are two-element
vectors specifying both edge frequencies, with the lower edge frequency being the first element
of the vector. In the latter cases, Wn is also a two-element vector.
For estimating the order of a Type 1 Chebyshev filter, the MATLAB command is
and for designing a Type 2 Chebyshev filter, the MATLAB command for estimating the
order is
As before, Wp and Ws are the passband and stopband edge frequencies with values between 0
and 1. Likewise, Rp and Rs are the passband ripple and the minimum stopband attenuation
in dB. N contains the estimated lowest order and Wn is the cutoff frequency. It should be
noted that for bandpass and bandstop filter designs, the actual order of the transfer function
obtained using the appropriate filter design command is 2N.
BUTTER FUNCTION
After the filter type has been selected and its order estimated, the next step is to determine the
transfer function of the filter. To this endMATLAB provides functions for all four types of filters.
For designing Butterworth digital lowpass or bandpass filters, the command is
[num,den] = butter(N,Wn)
where the input parameters N and Wn are determined through the use of the function buttord,
3
DIGITAL SIGNAL PROCESSING LABORATORY
and the output is the vectors num and den containing, respectively, the coefficients of the
numerator and denominator polynomials of the transfer function in ascending powers of . If
Wn is a scalar, butter returns a lowpass transfer function of order N, and if Wn is a two-element
vector, it returns a bandpass transfer function of order 2N. For designing a Butterworth digital
highpass filter of order N, the command is
[num,den] = butter(N,Wn,high)
[num,den] = butter(N,Wn,stop)
[num,den] = cheby1(N,Rp,Wn)
[num,den] = cheby1(N,Rp,Wn,filtertype)
[num,den] = cheby2(N,Rs,Wn)
[num,den] = cheby2(N,Rs,Wn,filtertype)
[num,den] = ellip(N,Rp,Rs,Wn)
[num,den] = ellip(N,Rp,Rs,Wn,filtertype)
EXAMPLE :
4
DIGITAL SIGNAL PROCESSING LABORATORY
plot(w/pi,g);grid
axis([0 1 -60 5]);
xlabel(\omega /\pi); ylabel(Gain, dB);
title(Gain Response of a Butterworth Bandstop Filter);
2 DESIGN METHOD
1. Design a LP (low pass) butterworth filter where given matlab functions and obtain plotting
outputs
2. Do the essential changes for HP (high pass) filter and obtain plotting outputs.
3. Do the essential changes for band pass (BP) filter and obtain plotting outputs
4. Do the essential changes for band reject (BR) filter and obtain plotting outputs
3 LAB WRITEUP
Please send me a write-up of your code in pdf format. You can write it as a word file, then save as
pdf.
Each lab grade consists of two sections. 50% of your grade is for coming to the lab. 50% is for
your write-up.
If you do not send the write-up within 2 weeks of the lab, you will not be allowed to submit a lab
writeup.
If your lab writeup is found to be substantially identical to another students using our special
forensics team, you and the other student will receive a substantial reduction in your grade.
At the top of your code you should have your name, student number, lab number, date you
performed the lab.
In the lab writeup you should answer all questions in the body of the lab report.
Please clearly label every question. You will not get credit for sections that are not clearly
labeled.
5
DIGITAL SIGNAL PROCESSING LABORATORY
You must copy figures from Matlab and paste them into your word file, or save them as jpeg and
import them into your word file. All figures must have captions inside which clearly describe
what the figure is.