Chapter 6
Infinite Impulse Response Filter Design
Objectives
• Describe the general concepts and approaches in IIR filter design.• Demonstrate the design of digital oscillators by pole location.• Demonstrate the design of sharp notch filters by pole-zero location.• Describe the characteristics of the four types of classical prototype
analog filters• Demonstrate the design of analog filter prototypes with MATLAB®.• Derive and describe the bilinear transformation.• Demonstrate the bilinear transformation method of IIR filter design.• Demonstrate the use of MATLAB functions for IIR design of filters
with the response of classical analog filters.• Demonstrate the effect of coefficient quantization on the
performance of IIR filters.
Concepts in IIR Filter Design
• The frequency response of a DSP filter is the value of the z-domain transfer function on the unit circle
• The location of the poles and zeros determines the shape of the transfer function in the complex plane
• The poles must be inside the unit circle for stability
2 30 1 2 3
2 30 1 2 3
...( ) ...
j j j j MM
j j j j NN
b b e b e b e b eH
a a e a e a e a e
Typical IIR Filter Designs
• Digital Oscillators• Notch Filters• Digital Equivalents of Classical Analog
Prototypes:– Butterworth– Chebyshev I– Chebyshev II– Elliptic or Cauer
Digital Oscillators
Oscillator with frequency Ω0
H(z)
ImpulseDigital Sinusoid
X(z) Y(z)
1 10
10 0
0 2 1 20 0
( ) ( ) ( )( ) [ ] 1
( ) ( )
( ) ( ) sin( ) [ ]
sin( ) sin( )sin( ) [ ] ( )
2cos( ) 1 1 2cos( )
Y z H z X zX z Z n
soY z H z
Z Y z Z H z A n u n
A z A zZ A n u n H z
z z z z
Digital Oscillator Transfer Function
• Ω0 is the oscillator digital frequency in radians• A is the amplitude of the resulting sinusoid• Often called a “two-pole resonator” because the transfer function
has 2 poles at +/- Ω0 exactly on the unit circle (“meta-stable”)
• For Hertzian frequencies use Ω = 2πf/fs
10
1 20
sin( )( ) 1 2cos( )
A zH zz z
Oscillator Design Example
Design an oscillator with a frequency of 200 Hz in a system operating with a sampling frequency of 8 kHz. The MATLAB solution is:
>> f=200;>> fs=8000;>> omega=2*pi*f/fs;>> b=[0,sin(omega)];>> a=[1,-2*cos(omega),1];>> fvtool(b,a) % Use fvtool to display various results
Oscillator Design Example Results
0 20 40 60 80 100 120 140 160 180-1.5
-1
-0.5
0
0.5
1
1.5
Samples
Impulse Response
Ampl
itude
At a sampling frequency of 8 kHz each sample is 0.125 ms. 40 samples = 5 ms = the period of a 200 Hz sine function.
Oscillator Design Example Results
-1.5 -1 -0.5 0 0.5 1 1.5
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Real Part
Imag
inar
y Pa
rt
Pole/Zero Plot
Pole locations = ±Ω0 = ±2π (200/8000) = ±0.1571 radians
Notch Filters
• Notch filters are designed by “pole/zero location”• The zeros are located at the Ω notch frequencies• Poles are placed close to the zeros locations, just inside
the unit circle, to control the notch width.• A gain factor is included to hold the filter gain to unity at
all other frequencies• Notch filters for multiple frequencies can be designed by
cascading filters or, equivalently, by convolving the “a” and “b” coefficient vectors of individual filters
Notch Filter Transfer Function
1 20 0
1 2 20
[1 2cos( ) ]( )
1 2 cos( )g z z
H zr z r z
20
00
|1 2 cos( ) | 2 |1 cos( ) |r rg
1 2
r
The following is the transfer function for a notch filter for a notch frequency Ω0 and -3 dB width ΔΩ (or quality factor Q). The parameter r is the pole radius. The gain factor is g0. Note the trade-off between pole radius and notch width.
0Q
Notch Filter Design Example
Design a notch filter in MATLAB with a notch frequency of Ω0 = π/4 and a Q factor of 20
>> omega=pi/4;>> Q=20;>> delta_omega=omega/Q;>> r=1-delta_omega/2;>> g=abs(1-2*r*cos(omega)+r^2)/(2*abs(1-cos(omega))); % The g0 factor>> bn=g*[1,-2*cos(omega),1]; % The b coefficients of the notch filter>> an=[1,-2*r*cos(omega),r^2]; %The a coefficients of the notch filter>> fvtool(bn,an)
Design Example Results
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.90
0.2
0.4
0.6
0.8
1
1.2
1.4
Normalized Frequency ( rad/sample)
Mag
nitu
deMagnitude Response
Design Example Results
-1.5 -1 -0.5 0 0.5 1 1.5
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Real Part
Imag
inar
y Pa
rtPole/Zero Plot
Note the zeros on the unit circle and corresponding poles just inside the unit circle at Ω0 = π/4
Analog Filter Prototypes
Analog Filter Type Pass-Band Ripple Stop-Band Ripple Transition Band
Butterworth Monotonic
(Maximally Flat)
Monotonic Wide
Chebyshev-I Equi-ripple Monotonic Narrow
Chebyshev-II Monotonic Equi-ripple Narrow
Elliptic (Cauer) Equi-ripple Equi-ripple Very Narrow
Filter Specifications
Transfer Functions
1 20 1 2
1 21 2
...( )( ) ( ) ...
m m mm
n n nn
b s b s b s bY sH sX s s a s a s a
1 20 1 2
1 20 1 2
...( )( )( ) ...
MM
NN
b b z b z b zY zH zX z a a z a z a z
Analog Filter:
Digital Filter:
MATLAB Prototype Filter Design Commands
• [B,A] = BUTTER(N,Wn)• [B,A] = CHEBY1(N,R,Wn)• [B,A] = CHEBY2(N,R,Wn)• [B,A] = ELLIP(N,Rp,Rs,Wn)
– N = filter order– R = pass band ripple (cheby1) or stop-band ripple
(cheby2) in dB. (Rp and Rs respectively for the elliptic filter)
– Wn = cut-off frequency (radians/sec for analog filters or normalized digital frequencies for digital filters)
– [B,A] = filter coefficients, s-domain (analog filter) or z-domain (digital filter)
Analog Design Example
Design an order 4 Elliptic analog filter with a cutoff frequency of 10 Hz, a maximum pass-band ripple of 1 dB, and a minimum stop-band attenuation of -20 dB.
>> cutoff=2*pi*10; % Set the filter parameters>> order=4; >> Rp=1;>> Rs=20;>> [b,a]=ellip(order,Rp,Rs,cutoff,'s'); % Note the “s” option for an analog filter>> W=linspace(0,2*pi*20); % Create a 100 point linear frequency vector 0 to 20 Hz>> [H,f]=freqs(b,a,W); % The freqs command returns the complex value of the transfer function for the frequency vector
W (copied into the vector f) >> plot(f/(2*pi),abs(H)) % Plot the magnitude of H versus the frequency in Hertz>> title('Order 4 Elliptic Filter with 10 Hz Cutoff Frequency')>> xlabel('Frequency, Hz')>> ylabel('Magnitude Response')
Analog Design Example Results
0 2 4 6 8 10 12 14 16 18 200
0.2
0.4
0.6
0.8
1
1.2
1.4Order 4 Elliptic Filter with 10 Hz Cutoff Frequency
Frequency, Hz
Mag
nitu
de R
espo
nse
Digital Design of Analog PrototypesThe Bilinear Transformation
• The bilinear transformation maps the complex variable “s” in the analog transfer function to the complex variable “z” in the digital transfer function
2 1 1
2 2
zsT z
orsTzsT
Bilinear Transformation Mapping
jω
σ
σ < 0|z| < 1
Z - PlaneS - Plane
Bilinear Mapping
0 0 1
“Pre-Warping” Equation
/ 2 / 2 / 2
/ 2 / 2 / 2
-1
2 1 2 11 1
2 [ ][ ]
2 sin2 2
2cos2
2 tan2
2 tan 2
orT2tan
2
j
j
j j j
j j j
z es jT z T e
e e eT e e e
j
T
jT
or
T
Design Steps for a DSP Implementation of an Analog Design
• Determine the desired cut-off frequency for the digital filter, Ω0
• Compute the equivalent cut-off frequency for the analog filter, ω0, using the pre-warping equation.
• Design the analog filter (i.e., find its a and b coefficient vectors)
• Using the bi-linear transformation (s →z), compute the coefficients of the digital filter
MATLAB IIR Design ToolsGeneral Design Approach
• The MATLAB method for IIR filter design is a two command process; first, to determine the order and critical frequencies, second to compute the filter coefficients. For the a Butterworth filter:
[N, Wn] = BUTTORD(Wp, Ws, Rp, Rs)[B,A] = BUTTER(N,Wn,'type') where the option “type” can be either “high” or “stop” if specified.
• The command parameters are:– Wp = Ω pass-band edges in units of π– Ws = Ω stop-band edges in units of π– Rp = pass-band ripple in dB– Rs = stop-band ripple in dB
Design Example
• Filter Specifications:– Butterworth response– Pass-band edges = 400 Hz and 600 Hz– Stop-band edges = 300 Hz and 700 Hz– Pass-band ripple = 1 dB– Stop-band attenuation = -20 dB– Sampling Frequency = 2000 Hz
MATLAB Code for Design Example
>> fs=2000;>> Wp=[2*400/fs,2*600/fs]; % Normalized digital frequencies
of pass-band edges>> Ws=[2*300/fs,2*700/fs]; % Normalized digital frequencies
of stop-band edges>> [N,Wn]=buttord(Wp,Ws,1,20); % The “order” command>> [B,A]=butter(N,Wn); % The “filter” command>> fvtool(B,A)
Design Example Results
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.90
0.2
0.4
0.6
0.8
1
1.2
1.4
Frequency (kHz)
Mag
nitu
de
Magnitude Response
Band Edges
(-1dB and -20 dB)
Design ExampleChebyshev II High-Pass Filter
• Filter specifications:– Chebyshev II response (stop-band ripple)– Pass-band edge = 1000 Hz– Stop-band edge = 900 Hz– Pass-band ripple = 1 dB– Stop-band attenuation = -40 dB– Sampling frequency = 8 kHz
MATLAB Code for Design Example
>> fs=8000;>> Wp=[2*1000/fs]; % Pass-band edge normalized digital
frequency>> Ws=[2*900/fs]; % Stop-band edge normalized digital
frequency>> [N,Wn]=cheb2ord(Wp,Ws,1,40); % The “order” command>> [B,A]=cheby2(N,40,Wn,'high'); % cheby2 is the “filter” command. In this command % the syntax requires the stop-band attenuation % as the second parameter>> fvtool(B,A)
Design Example Results
0 0.5 1 1.5 2 2.5 3 3.5-100
-80
-60
-40
-20
0
20
Frequency (kHz)
Mag
nitu
de (d
B)Magnitude Response (dB)
Comparison of an Elliptic Filter with a Parks-McClellan Design
• Filter Specification:– Low-pass response– Pass-band edge = 475 Hz– Stop-band edge = 525 Hz (i.e., a transition
width of 50 Hz)– Pass-band ripple less than 0.01 in absolute
terms ( = 20log10(1-.01) = 0.0873 dB)– Stop-band attenuation greater than -40 dB
(= 0.01 ripple in absolute terms)– Sampling frequency = 2000 Hz
Finding the Order of a P-M Design
• [N,Fo,Ao,W] = FIRPMORD(F,A,DEV,Fs)• B = FIRPM(N,Fo,Ao,W)
– N = order– F = band edges, Ω in units of π, or in Hz if Fs is
specified– A = amplitudes corresponding to the bands defined
by the edges in F [length(F) must be 2*length(A)-2]– DEV = deviation (ripple) in each band defined by F
in absolute units (not dB)– Fs = sampling frequency in Hz
P-M Design to Specifications>> F = [475,525];>> A = [1,0];>> DEV = [.01,.01];>> Fs = 2000;>> [N,Fo,Ao,W] = firpmord(F,A,DEV,Fs);>> B = firpm(N,Fo,Ao,W);>> fvtool(B,1)>> NN = 78
P-M Design Results
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9-120
-100
-80
-60
-40
-20
0
20
Frequency (kHz)
Mag
nitu
de (d
B)Magnitude Response (dB)
Elliptic Filter Design to Specifications
>> fs=2000;>> fpass=475;>> fstop=525;>> Wp=2*fpass/fs;>> Ws=2*fstop/fs;>> Rp=.0873;>> Rs=40;>> [N,Wn]=ellipord(Wp,Ws,Rp,Rs);>> [Be,Ae]=ellip(N,Rp,Rs,Wn);>> fvtool(Be,Ae)>> NN = 7
Elliptic Filter Design Results
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9-120
-100
-80
-60
-40
-20
0
Frequency (kHz)
Mag
nitu
de (d
B)Magnitude Response (dB)
Coefficient Quantization
• The poles of an IIR filter must remain within the unit circle in the complex plane for stability
• Quantization and round-off errors can move the poles and create an unusable design
Effect of Coefficient Quantization Chebyshev II High-pass Filter
Double Precision vs. 16 bits
-1 -0.5 0 0.5 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Real Part
Imag
inar
y P
art
Poles and Zeros for Double Precision Coefficients
-1 -0.5 0 0.5 1 1.5 2
-1
-0.5
0
0.5
1
Real Part
Imag
inar
y P
art
Poles and Zeros for 16-bit Coefficients
>> B16=quantize(B,16);>> A16=quantize(A,16);
Summary• IIR filters can be design by pole-zero location
– Digital oscillators: poles on the unit circle– Notch filters: zeros on the unit circle with nearby poles
to control notch width• Classic analog filters can be designed using the
bilinear transformation• IIR filters have the advantage of smaller filter
order for a given frequency response.• IIR filters have the disadvantages of possible
instability due to coefficient quantization effects and non-linear phase response.