IIR_Filter

University of Kentucky
EE 422G - Signals and Systems Laboratory
Lab 3 - IIR Filters
Objectives:
 Use filter design and analysis tools to create IIR filters based on general filter
specification.
 Understand the impact of different computational structures for filter
implementation
 Understand the impact of the placement of poles and zeros on the frequency
response of the filter.
1. Background
Infinite impulse response (IIR) filters are an alternative to finite impulse response (FIR)
filters. Often an IIR implementation can meet a given filter specification with less
computation than an FIR implementation, but IIR filters induce nonlinear phase, can be
potentially unstable, and are more sensitive to numerical problems.
Like FIR filters, IIR filters are linear time-invariant (LTI) systems that can recreate a
wide range of frequency responses. IIR implementations with specified stopbandattenuation and transition-band requirements, typically requires far fewer filter taps than
an FIR filter meeting the same specifications. This leads to a significant reduction in the
computational complexity required to achieve a given frequency response. However, IIR
filters have poles, which require feedback for implement and can result in instability if
not properly placed inside the unit circle. The feedback can increase the sensitivity to
errors introduced during computations, especially for fixed-point processors. In addition,
IIR filters result in nonlinear phase distortion (delaying different frequency components
of the input signals by different amounts). Some of these complications are explored in
this lab.
Up to this point most of your filter implementations have been in terms of “Direct Form,”
which is suggested by converting the transfer function directly to a difference equation:
M
H ( z) 
b
m 0
N
m
z m
1   an z
(1)
n
n 1
However, if the polynomials are factored into second order stages as such:
b0 ( p)  b1 ( p ) z 1  b2 ( p ) z 2
1  a1 ( p ) z 1  a 2 ( p ) z  2
p 1
P
H ( z )  G0 
(2)
The form of Eq. (2) suggests cascading second-order IIR filters in series (the output from
one stage becoming the input to the next). Therefore this form is referred to as the
Cascade form. For good numerical stability, the IIR filter should be implemented as a
cascade of second-order, Direct Form II sections. The data flow for a second-order,
Direct-Form II section, or bi-quad, is shown in Figure 1. Note that in Direct Form II the
delayed samples are neither the input nor the output samples, but are instead the
intermediate values w[n] .
b0
Figure 1: Second-order, Direct Form II section
There are several IIR filter design methods. The main differences between the different
methods include the way specifications can be made (i.e. form of spectral magnitude or
impulse response) and the type of optimizations used to derive the filter coefficient. The
Matlab functions for the main IIR filter designs are Elliptical (ellip), Butterworth (butter),
and Chebyshev (cheby1 and cheby2). The unique features of these approaches will all be
examined in the laboratory assignment.
2. Pre-Lab
1. Derive the transfer function of filter shown in Fig. 1. (Hint: obtain transfer function
between x and w and then between w and y and use
H ( z) 
Y ( Z ) Y ( Z ).W ( Z )

X ( Z ) W ( Z ). X ( Z )
(3)
to find the transfer function)
2. (First part is a repeat of Prelab Problem 2, from FIR lab) For a sampling rate of
48kHz design an order-40 low-pass filter having cut-off frequency 10kHz by
windowing method. In your design, use Hamming window as the windowing function
(see help on fir1). Use the freqz command to plot the filter’s magnitude response (in
dB), use the filter command to plot the impulse response, and also plot the pole-zeros
of the filter in the Z-plane. (New part) Now create a 10th order low-pass Chebyshev
Type II digital filter with a stop-band at 11.5kHz with a stop-band attenuation of 55
dB. (a) Plot the IIR filter’s magnitude response on the same graph as the previous
FIR magnitude response. Compare the graphs and discuss the advantage of the IIR
filter in this case. Likewise plot the impulse response for the FIR and IIR filter on the
same graph for at least 100 samples. Compare the impulse responses and describe the
critical differences between the 2 responses. Finally compare the pole-zero plots of
each filter. Plot the roots of the IIR denominator (poles) as red X’s and roots of IIR
numerator (zeros) as red 0’s. One the same graph plot the FIR numerator roots as
blue 0’s. Compare the 2 patterns and describe how they are both consistent with a
low-pass filter.
3. Consider the design the coefficients for a 4th order low-pass elliptical filter with a
cutoff of 1000 Hz for a sampling rate of 8000. The passband should have ripple less
than .5 dB and the stopband should have ripple less than 10 dB. Verify that this can
be done with the following command (see help ellip):
[be4,ae4] = ellip(4,.25,10,.25);
Now plot the magnitude response obtained with freqz to verify conditions are met.
Write the transfer function of the filter as a ratio of 4th order polynomials. Then use
the roots and poly commands to write this filter as a product of two 2nd order
polynomial ratios. Scale these polynomials so the gain at DC is 1. Draw a block
diagram for the implementation using the 4th order polynomials (delays of up to 4
units) and a block diagram for its implementation using two 2nd order systems. You
can use the MATLAB command tf2sos to check you work, but the script that converts
the 4th order system to 2 second order systems must be written using roots and poly.
3. In-Lab Exercise
These lab exercises focus on the effects of pole placement, robustness of filter
implementations, the nature of specifications for the different IIR filters.
1. A pole-zero diagrams are useful for understanding the approximate behavior of a
filter. Regions along the unit circle that are close to zeros will result in signal
attenuation. The closer the zero is to the unit circle the more dramatic the
attenuation. Similarly, regions along the unit circle that are close to poles indicate
frequency regions where signal will be amplified. The closer the pole is to the
unit circle the more dramatic the amplification. Consider the following transfer
function that shows the relationship between a pair of complex conjugate poles (in
polar form) and a second-order IIR filter:
(4)
Figure 2 shows the locations of the poles of this filter in the z-plane. If the system
has real coefficients, the poles must occur in complex conjugate pairs, i.e.
p1  re j , p 2  re  j where r is the distance from the origin, and  is the angle
of p1 relative to the positive real axis.
Figure 2. Pole location of an IIR Filter.
Give a system with complex conjugate poles of the form: z p  r exp(  j ) .
Calculate the magnitude responses H1 exp( j) on w <  for  

3
for each
of the following r values.
a) r = 1.1
b) r = 0.99
c) r = 0.8
Put all three plots on the same figure for a comparison. Likewise plot the polezero diagrams for each filter on the same plot. In the discussion section comment
on how the position of the poles impacts the magnitude response. In the
discussion section comment on whether stability be inferred from the magnitude
response.
For exercises 2-5, include the magnitude response, pole-zero diagram, and impulse
response in the results section of your report.
2. Use the MATLAB command butter to design a 5th-order low-pass IIR filter
with sampling frequency of 2 kHz and a band edge of 600 Hz. Plot the magnitude
and phase frequency responses using freqz. Plot the pole and zero location
diagram using zplane. Plot the significant part of the impulse response using
filter
to give around 20 output values. Discuss briefly how the magnitude
response makes sense from the pole-zero plot.
3. Use the MATLAB command cheby1 to design a 5th-order low-pass IIR filter
with a sampling frequency of 2 kHz, a band edge of 600 Hz, and a pass-band
ripple of 0.5 dB. Plot the magnitude and the phase frequency responses. Plot the
pole and zero location diagram. Discuss briefly how the magnitude response
makes sense from the pole-zero plot.
4. Use the MATLAB command cheby2 to design a 5th-order low-pass IIR filter
with a sampling frequency of 2 kHz, a band edge of 600 Hz, and a maximum
stop-band ripple 30 dB below the pass-band response. Plot the magnitude and the
phase frequency responses. Plot the pole and zero location diagram. Discuss
briefly how the magnitude response makes sense from the pole-zero plot.
5. Use the MATLAB command ellip to design a 5th order low-pass IIR filter with a
sampling frequency of 2 kHz, a band edge of 600 Hz, a pass-band ripple of 0.5
dB, and a maximum stop-band ripple 30 dB below the pass-band response. Plot
the magnitude and the phase frequency responses. Plot the pole and zero location
diagram. Discuss briefly how the magnitude response makes sense from the polezero plot.
(Include in discussion section) In your discussion section describe the difference
between the responses of the filters in Problems 3-5. Also comment on the differences in
the pole zero-diagram and how that influences the magnitude response. Focus on those
relative differences that make each of the filters unique and highlight the advantages of
each.
6. Simulink Experiment:
Open a Simulink workspace and create the system shown below in Fig. 3.
B-FFT
Spectrum
Scope
Lin
Chirp
FDATool
Time
Scope
Digital
Filter Design
Figure 3. Simulink workspace with block for filter design experiments.
Set the source to be linear bidirectional sweep starting at 10 Hz up to 4000 with target
and sweep times to 5 seconds. Set the sampling rate to 8000 Hz. Set up the spectrum
scope to buffer inputs to 128 samples and with 64 points overlap. Set the FFT length to
256 and 1 for spectral averaging. Use the FDA tool to design a Butterworth filter with
minimum order to achieve a pass-band ripple of 1 dB and stop-band ripple of 20 dB. Set
the pass-band edge frequency of 1000 and stop-band edge frequency to 1100 Hz. Click
the design filter button compute the filter. The result should be as shown in Fig. 4. It
indicates a stable high-order filter, in cascaded second order sections.
Select “filter realization” dialog box
Figure 4. Specification dialog box for Filter Design and Analysis tool.
Now click on the “filter realization icon” (arrow points to it in Fig. 4), the display should
switch to what is shown in Fig. 5. In the text box labeled “Block Name,” type “Filter2.”
Then by clicking the “Realize Filter” button, a digital filter will be created in the simulink
workspace with the coefficients created in the specification dialog box. Attach this filter
to your system between the sources and the sinks as shown in Fig. 6. Then run the
simulation for 10 seconds. Take a screen shot of the time scope (you may need to click
the auto scale to see the full waveform, if it was cutoff) for your results section. Is this
result as you expected? Did the spectrum behave as you expected?
Now go back to the specification dialog box (Fig. 5 for icon to switch back to) and go to
the edit window and select “convert to a single stage.” Then return to the filter
realization dialog box and check the box to overwrite the new results in the same filter
block. Rerun comment on observation. You may also want to include the impulse
response for each of these cases to help in your discussion of filter stability. Now set the
stop-band to 1075 are repeat for both cascaded realization and single stage. Repeat for a
stop-band of 1050. Explain differences (if any) observed in magnitude responses, scope
output, and impulse response. Take screen shots of critical outputs for explaining what
you are seeing. In the discussion section, provide reasons for the performance changes
based on based on the implementation.
Filter Specification dialog box
Figure 5. Filter Realization Dialog box.
B-FFT
Spectrum
Scope
Lin
Digital
Filter
Chirp
Filter 2
FDATool
Time
Scope
Digital
Filter Design
Figure 6. Completed system with filter realization inserted.