Sei sulla pagina 1di 40

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 3
0 1 2 3
2 3
0 1 2 3
...
( )
...
j j j j M
M
j j j j N
N
b be b e b e b e
H
a a e a e a e a e
O O O O
O O O O
+ + + + +
O =
+ + + + +
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)
Impulse
Digital
Sinusoid
X(z)
Y(z)
{ }
{ } { }
{ }
1 1
0
1
0 0
0
2 1 2
0 0
( ) ( ) ( )
( ) [ ] 1
( ) ( )
( ) ( ) sin( ) [ ]
sin( ) sin( )
sin( ) [ ] ( )
2cos( ) 1 1 2cos( )
Y z H z X z
X z Z n
so
Y z H z
Z Y z Z H z A n u n
A z A z
Z A n u n H z
z z z z
o


=
= =
=
= = O
O O
O = = =
O + O +
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 = 2f/f
s


1
0
1 2
0
sin( )
( )
1 2cos( )
A z
H z
z z


O
=
O +
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
A
m
p
l
i
t
u
d
e
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
I
m
a
g
i
n
a
r
y

P
a
r
t
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 2
0 0
1 2 2
0
[1 2cos( ) ]
( )
1 2 cos( )
g z z
H z
r z r z


O +
=
O +
2
0
0
0
| 1 2 cos( ) |

2| 1 cos( ) |
r r
g
O +
=
O
1
2
r
AO
=
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 g
0
. Note the trade-off between pole radius and
notch width.
AO
O
=
0
Q
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.9
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Normalized Frequency (t rad/sample)
M
a
g
n
i
t
u
d
e
Magnitude 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
I
m
a
g
i
n
a
r
y

P
a
r
t
Pole/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 2
0 1 2
1 2
1 2
... ( )
( )
( ) ...
m m m
m
n n n
n
b s b s b s b Y s
H s
X s s a s a s a


+ + + +
= =
+ + + +
1 2
0 1 2
1 2
0 1 2
... ( )
( )
( ) ...
M
M
N
N
b b z b z b z Y z
H z
X 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 20
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Order 4 Elliptic Filter with 10 Hz Cutoff Frequency
Frequency, Hz
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e
Digital Design of Analog Prototypes
The 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
z
s
T z
or
sT
z
sT

| |
=
|
+
\ .
+
=

Bilinear Transformation Mapping


j

< 0
|z| < 1
Z - Plane
S - Plane
Bilinear Mapping
0 0 1
Pre-Warping Equation
/ 2 / 2 / 2
/ 2 / 2 / 2
-1
2 1 2 1
1 1
2 [ ]
[ ]
2 sin
2 2
2cos
2
2
tan
2
2
tan
2
or
T
2tan
2
j
j
j j j
j j j
z e
s j
T z T e
e e e
T e e e
j
T
j
T
or
T
e
e
e
O
O
O O O
O O O
| | | |
= = =
| |
+ +
\ .
\ .
| |
=
|
+
\ .
| | O | |
| |
\ .
|
=
O
| |
|
|
|
\ .
\ .
O
| |
=
|
\ .
O
| |
=
|
\ .
| |
O =
|
\ .
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 Tools
General 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.9
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Frequency (kHz)
M
a
g
n
i
t
u
d
e
Magnitude Response
Band Edges
(-1dB and -20 dB)
Design Example
Chebyshev 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)
M
a
g
n
i
t
u
d
e

(
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)
>> N
N =
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)
M
a
g
n
i
t
u
d
e

(
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)
>> N
N =
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)
M
a
g
n
i
t
u
d
e

(
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
I
m
a
g
i
n
a
r
y

P
a
r
t
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
I
m
a
g
i
n
a
r
y

P
a
r
t
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.