Professional Documents
Culture Documents
KS Chapter 5 FIR Filter Design
KS Chapter 5 FIR Filter Design
Objectives
Describe the general approach to filter design and the design equation for
FIR filters.
Define phase distortion and show how it affects signals.
Demonstrate how linear phase response eliminates phase distortion.
Demonstrate the symmetry condition on FIR impulse response that results
in linear phase.
Derive the impulse responses of ideal low-pass and high-pass linear phase
filters.
Describe and demonstrate the window design method for linear phase FIR
filters.
Demonstrate the design of low-pass, high-pass, band-pass, and band-reject
FIR filters.
Describe and demonstrate the sampling method of linear phase FIR filter
design.
Demonstrate the tools in MATLAB for optimized FIR filter design using the
Parks-McClellan algorithm.
H ( )
h[n]e jn
1
h[n]
2
H ( )e
j n
for - n
Phase Distortion
Phase distortion results from a variable
time delay (phase delay) for different
frequency components of a signal.
If the phase response of a filter is a linear
function of frequency, then the phase
delay is constant for all frequencies and
no phase distortion occurs.
Linear Phase
An input signal (blue sinusoid) processed in the passband of a filter (output red sinusoid) will, in general,
experience a phase change (1 to 2) and a time delay (t1
to t2).
(t2 - t1 ) + ( 2 - 1 ) = 0
(t2 - t1 ) = D t = Phase delay
( 2 - 1 ) = D = Phase change
D t +D = 0
D t =-
D
D
=
2f
D =- kf
t nTs
t
n
tf s sample delay
Ts
n is a constant if t is constant
n k
k
Group delay -
dD
dW
0.6
0.4
Zero phase
change for each
sinusoid
0.2
0
-0.2
-0.4
-0.6
-0.8
10
15
20
25
milliseconds
30
35
40
1
0.8
0.6
A constant phase
change of +30
degrees for each
sinusoid results in
phase distortion.
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
10
15
20
25
milliseconds
30
35
40
0.6
0.4
0.2
0
-0.2
-0.4
D t =- .005 =-
-0.6
k =- .
01
-0.8
10
15
20
25
milliseconds
30
35
40
D =- .01f
- kf
D
k
==
2f
2
2
h[n]
-1
4. Group delay = 2
-2
-3
-1
4.5
Group Delay
3
2.8
-60
2.7
-120
1.8
-180
0.9
-240
2.6
Phase
Group
delay(degrees)
(in samples)
Magnitude
3.6
2.4
2.2
2
1.8
1.6
1.4
1.2
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized Frequency ( rad/sample)
0.8
0.9
-300
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized Frequency ( rad/sample)
0.8
0.9
0.16
100
0.14
0.8
40
0.6
-20
0.4
-80
0.2
-140
Magnitude
h[n]
0.1
0.08
0.06
0.04
0.02
0
-1
3
n
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized Frequency ( rad/sample)
0.8
0.9
-200
Phase (degrees)
0.12
)
e
d
2
1 -0 0
H() =
0 otherwise
h[n]
h[0]
1
2
e j 0 d
1
2
1
1
0 (0 ) (20 ) 0
2
2
1 0 j n
h[n]
e d
0
2
1
jn 0
e
0
2 jn
1 1 jn0
e
e jn0
n 2 j
or
0
h[n]
1 sin( n)
0
n
1
h[n]
sin(0 n)
n
or
sinc( x)
h[n]
h[n]
n0
n0
sin( x)
x
1
1
sin( 0 n)
0 n sin c( 0 n)
n
0
sinc(0 n) - n
0
h[n]
sinc(0 n) - n
Example:
21 Coefficient LP Filter with 0 = /4
>> n=0:20;
>> omega=pi/4; % This is the cut-off frequency
>> h=(omega/pi)*sinc(omega*(n-10)/pi); % Note the 10 step shift
>> stem(n,h)
>> title('Sample-Shifted LP Impulse Response')
>> xlabel('n')
Note the linear phase properties
of the impulse response
>> ylabel('h[n]')
>> fvtool(h,1)
Sample-Shifted LP Impulse Response
0.25
1.2
0.15
0.1
0.8
h[n]
Magnitude
0.2
0.05
0.6
0.4
-0.05
0.2
-0.1
10
n
12
14
Magnitude Response
1.4
16
18
20
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized Frequency ( rad/sample)
0.8
0.9
Example:
201 Coefficient LP Filter with 0 = /4
>> n=0:200;
% This sets the order of the filter where length(n)=201
>> omega=pi/4;
>> h=(omega/pi)*sinc((n-100)*omega/pi);
%Note the sample shift of 100 samples
>> fvtool(h,1)
Magnitude Response
1.4
1.2
Magnitude
1
0.8
Side-lobe ripple
(Gibbs phenomenon)
due to abrupt
truncation of the
impulse response
0.6
0.4
0.2
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Tapering Windows
Used to taper the abrupt truncation of the
impulse response towards zero
Example: Hamming window
2n
N - 1
hW [n] = w[n]h[n]
>> stem(n,w)
>> title('Hamming Window')
>> figure,stem(n,h,'ko')
>> hold
>> stem(n,hw,'bd')
>> title('Comparison of Rectangular and Hamming
Window Impulse Response')
>> legend('Rectangular','Hamming')
>> fvtool(hw,1)
0.25
Rectangular
Hamming
0.2
0.15
0.1
0.05
0
-0.05
-0.1
10
12
14
16
18
20
0.25
Rectangular
Hamming
0.2
1.2
0.15
1
Magnitude
0.1
0.05
0.8
0.6
0.4
-0.05
0.2
-0.1
Magnitude Response
1.4
10
12
14
16
18
20
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized Frequency ( rad/sample)
0.8
0.9
20
0
Magnitude (dB)
-20
-40
-60
-80
-100
-120
-140
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
2 -
p
1 - W0 jWn
1
jWn
=
e
d
W+
e
dW
2 -
2 W0
1 1 jWn - W0
1 1 jWn
=
e - +
e W
0
2 jn
2 jn
1 1 - jW0n - jn 1 1 jn
jW0n
=
e
e
+
e
e
n 2 j
n 2 j
1 1 jW0n
1 1 jn - jn
- jW0 n
=
e
+
e
+
n 2 j e - e
n 2 j
1
1
=
sin(n) sin(W0n)
n
n
W0
h[n] = sinc( n) sinc(W0 n)
- < n <
Design Example:
201 Coefficient HP with 0 = 3/4
>> n=0:200;
>> omega=3*pi/4;
>> h=sinc(n-100)-(omega/pi)*sinc(omega*(n-100)/pi); % Both terms shifted by 100
% samples
>> hw=h.*blackman(201)';
>> fvtool(hw,1)
Magnitude Response (dB)
50
Magnitude (dB)
-50
-100
-150
-200
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized Frequency ( rad/sample)
0.8
0.9
HHP
HLP
HLPH - HLPL
L
HLPL
H
HLPH
-20
-20
-40
-60
-80
-40
-60
-80
-100
-100
-120
-140
20
Magnitude (dB)
Magnitude (dB)
20
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized Frequency ( rad/sample)
0.8
0.9
-120
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized Frequency ( rad/sample)
0.8
0.9
2
1
0
-1
-2
50
100
150
200
250
200
250
2
1
0
-1
-2
50
100
150
1.4
DTFT of h1
DFT of h1
1.2
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Units of Pi
1.4
1.6
1.8
H [k ] h[n]e
j 2
k
n
N
n 0
k 0,1, 2,...N 1
Design Example 1
Sampled Frequency Response
Samples of the Frequency Response of a N=25 HP Filter with pi/2 Cutof
1.5
0.5
0.2
0.4
0.6
0.8
1
1.2
1.4
Digital Frequency in Units of Pi
1.6
1.8
Design Example 1
Impulse Response
Compute the causal frequency response:
>> M=length(x)-1;
>> H=exp(-j*f*M/2).*x;
Design Example 1
Frequency Response
Magnitude Response
1.4
1.2
Magnitude
1
0.8
0.6
0.4
0.2
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 1
Compare the sampling design with an ideal window design
>> n=0:24;
>> omega=pi/2;
>> hhp2=sinc(n-12)-(omega/pi)*sinc(omega*(n-12)/pi);
>> [Hhp1,freq]=dtft_demo(hhp1,0,pi,512);
>> [Hhp2,freq]=dtft_demo(hhp2,0,pi,512);
>> plot(freq/pi,abs(Hhp1)); %This plots the magnitude of Hhp1 versus
frequency
>> hold
>> plot(freq/pi,abs(Hhp2),'--k') %This plots the magnitude of Hhp2
versus frequency
>> xlabel('Units of Pi')
>> title('Comparison of Ideal Window and Sampling Method for HP
Design')
>> legend('Sampling Method hhp1','Windowed Method hhp2')
Design Example 1
Comparison of Ideal Window and Sampling Method for HP Design
1.4
1.2
1
0.8
0.6
0.4
0.2
0
0.1
0.2
0.3
0.4
0.5
0.6
Units of Pi
0.7
0.8
0.9
Sampling Design 2
Specifications:
low-pass filter of order 100,
a cut-off frequency 500 Hz
sampling frequency of 3000 Hz
Hamming window.
Sampling Design 2
MATLAB Code
>> n=0:100;
>> fs=3000;
>> fc=500;
>> omega_cutoff=2*pi*fc/fs;
>> [x,f]=selectH_lp(omega_cutoff,length(n)); % Create the response samples
>> M=length(x)-1;
>> H=exp(-j*f*M/2).*x; % Compute the causal filter frequency response
>> h=inv_dft_demo(H); % Compute the impulse response
>> h_hamming=h.*hamming(length(n))'; % Window with a Hamming window
>> subplot(2,1,1),dtft_demof(h,0,1500,512,3000); % Plot the magnitude
response
>> title('Sampling Design - Rectangular Window')
>> subplot(2,1,2),dtft_demof(h_hamming,0,1500,512,3000);
>> title('Sampling Design - Hamming Window')
Sampling Design 2
Results
Sampling Design - Rectangular Window
1.5
1
0.5
0
1.5
500
1000
1500
500
1000
1500
Hz
Sampling Design - Hamming Window
1
0.5
0
Hz
>> B=fir2(N,F,A)
N = order
F = Frequency break points, in units of
A = Amplitudes corresponding to the break points in F
F = [0, 0.3, 0.3, 1]
A = [1, 1, 0, 0]
0.3
1.4
1.2
1
0.8
0.6
0.4
0.2
0
500
Hz
1000
1500
The values for order, transition width, and ripple cannot be independently
specified. Specifying two of the parameters forces a particular value for
the third. For a specified ripple and transition width the order is optimal in
a Parks-McClellan design.
Filter specifications:
Order 20 low-pass
Critical frequency /4
Transition width 0.2
By specifying the order and the transition width, the forced
parameter is the pass-band and stop-band ripple
>> f=[0 .15 .35 1];
>> a=[1 1 0 0];
>> N=20;
>> h=firpm(N,f,a);
>> fvtool(h,1)
20
0
Magnitude (dB)
-20
-40
-60
-80
-100
-120
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized Frequency ( rad/sample)
0.8
0.9
Transition width 25 Hz
-40 dB ripple in both the pass-bands and stop-bands
20
0
Magnitude (dB)
-20
-40
-60
-80
-100
-120
0.5
1.5
2
2.5
Frequency (kHz)
3.5
Summary
FIR filters allow the design of linear phase
filters, which eliminate the possibility of
signal phase distortion.
Three methods of linear phase FIR design
were discussed:
The ideal window method
The sampling method
The optimal Parks-McClellan method