Infinite Impulse Response Filter Design

advertisement
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
H ( ) 
b0  b1 e
 j
 j 2
 b2 e
a 0  a1 e
 j
 a2e
 j 2
 b3 e
 j 3
 a3e
 j 3
 ...  b M e
 j M
 ...  a N e
 j N
Typical IIR Filter Designs
• Digital Oscillators
• Notch Filters
• Digital Equivalents of Classical Analog
Prototypes:
– Butterworth
– Chebyshev I
– Chebyshev II
– Elliptic or Cauer
Digital Oscillators
Impulse
Digital
Sinusoid
Oscillator with
frequency Ω0
H(z)
X(z)
Y(z)
Y (z)  H (z) X (z)
X ( z )  Z  [ n ]  1
so
Y (z)  H (z)
Z
1
 Y ( z ) 
Z
1
 H ( z ) 
A sin(  0 n ) u [ n ]
Z  A sin(  0 n ) u [ n ]  H ( z ) 
A sin(  0 ) z
z  2 cos(  0 ) z  1
2

A sin(  0 ) z
1  2 cos(  0 ) z
1
1
z
2
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
H (z) 
A sin(  0 ) z
1  2 cos(  0 ) z
1
1
z
2
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
Impulse Response
1.5
1
Amplitude
0.5
0
-0.5
-1
-1.5
0
20
40
60
80
100
Samples
120
140
160
180
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
Pole/Zero Plot
1
0.8
0.6
Imaginary Part
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1.5
-1
-0.5
0
Real Part
0.5
1
1.5
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
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.
H (z) 
g 0 [1  2 cos(  0 ) z
1  2 r cos(  0 ) z
1
1
2
| 1  2 r co s(  0 )  r |
2 | 1  co s(  0 ) |
r  1

2
Q 
0

2
r z
2
g0 
z
]
2
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
Magnitude Response
1.4
1.2
Magnitude
1
0.8
0.6
0.4
0.2
0
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized Frequency ( rad/sample)
0.8
0.9
Design Example Results
Pole/Zero Plot
1
0.8
0.6
Imaginary Part
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1.5
-1
-0.5
0
Real Part
0.5
1
1.5
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
Monotonic
Wide
(Maximally Flat)
Chebyshev-I
Equi-ripple
Monotonic
Narrow
Chebyshev-II
Monotonic
Equi-ripple
Narrow
Elliptic (Cauer)
Equi-ripple
Equi-ripple
Very Narrow
Filter Specifications
Transfer Functions
Analog Filter:
H (s) 
Y (s)
b0 s  b1 s
m

X (s)
s  a1 s
n
m 1
n 1
 b2 s
 a2 s
m2
n2
 ...  b m
 ...  a n
Digital Filter:
H (z) 
Y (z)
X (z)

b0  b1 z
1
 b2 z
2
a 0  a1 z
1
 a2 z
2
 ...  b M z
M
 ...  a N z
N
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 zdomain (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
Order 4 Elliptic Filter with 10 Hz Cutoff Frequency
1.4
1.2
Magnitude Response
1
0.8
0.6
0.4
0.2
0
0
2
4
6
8
10
12
Frequency, Hz
14
16
18
20
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  z 1
s 

T  z 1
or
z 
2  sT
2  sT
Bilinear Transformation Mapping
S - P la n e
Z - P la n e
jω
σ < 0
|z | < 1
0
σ
B ilin e a r M a p p in g
0
1
“Pre-Warping” Equation
j
2  z 1  2  e 1 
s  j  

   j
T  z 1 T  e 1
j / 2
j / 2
 j / 2
2e
[e
e
]
  j / 2 j / 2
 j / 2 
T e
[e
e
]


2 j sin  

2
 2 
 
T 

2
cos
 

 2 



tan  
T
 2 
j2
or
 

tan  
T
 2 
2
or
-1   T 
  2tan 

 2 






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 prewarping 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
Magnitude Response
1.4
1.2
Magnitude
1
0.8
0.6
Band Edges
0.4
(-1dB and -20 dB)
0.2
0
0
0.1
0.2
0.3
0.4
0.5
0.6
Frequency (kHz)
0.7
0.8
0.9
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
Magnitude Response (dB)
20
0
Magnitude (dB)
-20
-40
-60
-80
-100
0
0.5
1
1.5
2.5
2
Frequency (kHz)
3
3.5
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
Magnitude Response (dB)
20
0
Magnitude (dB)
-20
-40
-60
-80
-100
-120
0
0.1
0.2
0.3
0.6
0.5
0.4
Frequency (kHz)
0.7
0.8
0.9
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
Magnitude Response (dB)
0
-20
Magnitude (dB)
-40
-60
-80
-100
-120
0
0.1
0.2
0.3
0.4
0.5
0.6
Frequency (kHz)
0.7
0.8
0.9
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
>> B16=quantize(B,16);
>> A16=quantize(A,16);
Poles and Zeros for 16-bit Coefficients
Poles and Zeros for Double Precision Coefficients
1
0.8
1
0.6
0.5
Imaginary Part
Imaginary Part
0.4
0.2
0
-0.2
0
-0.5
-0.4
-0.6
-1
-0.8
-1
-1
-0.5
0
Real Part
0.5
1
-1
-0.5
0
0.5
Real Part
1
1.5
2
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.
Download