IIR_Lec - University of Kentucky

advertisement
EE422
Signals and Systems Laboratory
Infinite Impulse Response (IIR)
filters
Kevin D. Donohue
Electrical and Computer Engineering
University of Kentucky
Filters
Filter are designed based on specifications given by:
 spectral magnitude emphasis
 delay and phase properties through the group delay and
phase spectrum
 implementation and computational structures
Matlab functions for filter design
 (IIR) besself, butter, cheby1, cheby2, ellip, prony, stmcb
 (FIR) fir1, fir2, kaiserord, firls, firpm, firpmord, fircls,
fircls1, cremez
 (Implementation) filter, filtfilt, dfilt
 (Analysis) freqz, fdatool, sptool
Filter Specifications
Example:Low-pass filter frequency response
1
Amplitude Scale
Cutoff Frequency
0.8
Passband
Stopband
0.6
0.4
0.2
Transitionband
0
0
0.2
Ripple
0.4
0.6
Normalize Frequency (fs/2 = 1)
0.8
1
Filter Specifications
Example Low-pass filter frequency response (in
dB)
10
Cutoff Frequency
0
Scale in dB
-10
-20
Stopband
Passband
-30
-40
Ripple
-50
-60
-70
0
Transitionband
0.2
0.4
0.6
0.8
Normalized Frequency (fs/2 = 1)
1
Filter Specifications
Example Low-pass filter frequency response (in dB) with
ripple in both bands
Filter Magnitude Response
0
Passband Ripple
Stopband Ripple
-10
dB
-20
-30
Transition
-40
-50
0
0.2
0.4
0.6
Normalize Hz
0.8
1
Difference Equation and TF
Examples
• Derive the TFs for the following difference equations (y[n] is
output and x[n] is input). (Hint: Use delay property of ZT and
assume zero for initial conditions).
• 𝑦 𝑛 = .5𝑥 𝑛 + 𝑥[𝑛 − 1] − .25𝑦 𝑛 − 1 + .125𝑦[𝑛 − 2]
Show
𝑌(𝑧)
.5 + 𝑧 −1
.5𝑧 2 + 𝑧1
𝐻 𝑧 =
=
= 2
−1
−2
𝑧 + 0.25𝑧1 − 0.125
𝑋(𝑧) 1 + 0.25𝑧 − 0.125𝑧
Does this represent an FIR or IIR filter? What are the poles and
zeros of this system?
Difference Equation and TF
Examples
• Derive the TFs for the following difference equations (y[n] is
output and x[n] is input). (Hint: Use delay property of ZT and
assume zero for initial conditions).
• 𝑦 𝑛 = 𝑥 𝑛 − .5𝑥 𝑛 − 1 + .25𝑥[𝑛 − 2] − .125𝑥[𝑛 − 3]
Show
𝑌(𝑧) 1 − 0.5𝑧 −1 + 0.25𝑧 −2 − 0.125𝑧 −3
𝐻 𝑧 =
=
1
𝑋(𝑧)
𝑧 3 − 0.5𝑧 2 + 0.25𝑧1 − 0.125
=
𝑧3
Does this represent an FIR or IIR filter? What are the poles and
zeros of this system?
Difference Equation and TF
Examples
• Derive the difference equation from the following TF (y[n] is
output and x[n] is input). (Hint: Express in terms of negative z
powers, use delay property of ZT and assume zero for initial
conditions).
• 𝐻 𝑧 =
𝑧 3 +2𝑧 1 −1
𝑧 4 −0.1𝑧 3 +0.5𝑧 2 −0.5𝑧 1 +1
• Show
• 𝑦 𝑛 = 𝑥 𝑛 − 1 + 2𝑥 𝑛 − 3 − 𝑥 𝑛 − 4 + .1𝑦 𝑛 − 1 −
.5𝑦 𝑛 − 2 + .5𝑦 𝑛 − 3 − 𝑦[𝑛 − 4]
Is it stable? How would this be represented as direct form filter in
Matlab?
Filter Specification Functions
The transfer function magnitude or magnitude
response:
H M ( f )  H( z ) z exp( j 2f )
The transfer function phase or phase response:
H P ( f )   H( z ) z exp( j 2f )
The group delay (envelope delay) :
d HP ( f )
GP ( f )  
df
Filter Analysis Example
Consider a filter with transfer
function:
Hˆ ( z ) 
1
z
1  1.2728 z 1  0.81z 2
Compute and plot the
magnitude response, phase
response, and group delay.
Note pole-zero diagram. What
would be expected for the
magnitude response?
1.5
IM
Z-Plane
1
0.5
RE
0
-0.5
-1
-1.5
-1.5
-1
-0.5
0
0.5
1
1.5
Filter Analysis Example
Hˆ ( z ) 
z 1
1  1.2728 z
1
 0.81z
2
 y[n]  1.2728 y[n  1]  0.81 y[n  2]  x[n  1]
% Script to illustrate frequency analysis of filters
% given y[n] = x[n-1] + 1.2728y[n-1] - 0.81y[n-2]
fs = 8000; % Sampling frequency
% Numerator and denominator polynomials to represent filter
b = [0, 1]; % (numerator) first is element time of current output
a = [1, -1.2728, 0.81]; % (denominator) first element is time of current output
Filter Analysis Example
% Frequency response
[h,f] = freqz(b,a,1024,fs);
figure
% Magnitude
plot(f,abs(h)); xlabel('Hz'); ylabel('TF Magnitude');
figure
% Phase
plot(f,phase(h)); xlabel('Hz'); ylabel('TF Phase in Radians');
% Group delay
[d,f] = grpdelay(b,a,1024,fs);
figure
% delay in seconds
plot(f,d/fs); xlabel('Hz'); ylabel('delay in seconds');
figure
% delay in samples
plot(f,d); xlabel('Hz'); ylabel('delay in samples');
Filter Analysis Example
Magnitude Response with FREQZ
Phase Response with FREQZ
0
TF Phase in Radians
TF Magnitude
8
6
4
2
0
0
1000
2000
3000
4000
Hz
5000
6000
7000
-2
-3
-4
8000
0
1000
2000
3000
-3
Group Delay with GRPDELAY
1.2
10
4000
Hz
5000
6000
7000
8000
Group Delay
x 10
1
delay in seconds
Delay in Samples
-1
5
0.8
0.6
0.4
0.2
0
0
1000
2000
3000
4000
Hz
5000
6000
7000
8000
0
0
500
1000
1500
2000
Hz
2500
3000
3500
4000
Filter Design Examples
The following commands generate filter
coefficients for basic low-pass, high-pass, bandpass, band-stop filters:
For linear phase FIR filters: fir1
For non-linear phase IIR filter: besself, butter,
cheby1, cheby2, ellip
Example: With function fir1, design an FIR high-pass
filter for signal sampled at 8 kHz with cutoff at 500 Hz.
Use order 10 and order 50 and compare phase and
magnitude spectra with freqz command. Use grpdelay
to examine delay properties of the filter. Also use
command filter to filter a frequency swept signal from 20
to 2000 Hz over 4 seconds with unit amplitude.
Filter Design Examples
Example: With function cheby2 design an IIR Chebyshev
Type II high-pass filter for signal sampled at 8 kHz with
cutoff at 500 Hz, and stopband ripple of 30 dB down. Use
order 5 and order 10 for comparing phase and magnitude
spectra with freqz command. Use grpdelay to examine
delay characteristics. Also use command filter to filter a
frequency swept signal from 20 to 2000 Hz over 2 seconds
with unit amplitude.
Example: With function butter, design an IIR Butterworth
band-pass filter for signal sampled at 20 MHz with a sharp
passband from 3.5 MHz to 9MHz. Use order 5 and verify
design of phase and magnitude spectra with freqz command.
Computational Diagrams
For Direct form I filter below, derive difference equation and TF
x[n]
y[n]
w[n]
G0
b0
1/a0
z-1
z-1
b1
-a1
z-1
z-1
b2
-a2
Hint: Form difference equations around accumulator/register
outputs, convert to TF and try to cancel out auxiliary variables.
Computational Diagrams
For Direct form II filter below, derive difference equation and TF
x[n]
y[n]
w[n]
G0
1/a0
b0
z-1
-a1
b1
z-1
-a2
b2
Hint: Form difference equations around accumulator/register
outputs, convert to TF and try to cancel out auxiliary variables.
Download