Professional Documents
Culture Documents
Lecture (6) : FIR Filter Design
Lecture (6) : FIR Filter Design
v(n)
NOISE
V (F )
F0 F0 F
F0 F0 F0 F
2
Conditions for Non-Distortion
Problem: ideally we do not want the filter to distort the signal we want to
recover.
2
2
1.5
-1
FILTER -0.5
delayed.
-1
-1.5
-1.5
-2
0 200 400 600 800 1000
-2
0 200 400 600 800 1000
F 3
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.
4
Real Time Implementation
For real time implementation we also want the filter to be causal, ie.
h ( n)
y ( n ) h( k ) x ( n k )
h(n) 0 for n 0 since
k 0
n
FACT (Bad News!): by the Paley-Wiener Theorem, if h(n) is causal and with
finite energy,
ln H ( ) d
2
1 2
log H ( ) log( 0) log H ( ) d
1 5
Practical Filter specifications | H ( ) | IDEAL
Filters
Frequency-selective Filter
p
Three Stages
Specifications
Approximation of the Specifications.
Realization
6
Practical Filter specifications
In practical design the following parameters would be specified:
The maximum ripple allowed in the pass-band: p
The maximum ripple allowed in the stop-band:
s
The pass-band edge frequency: p
The stop-band edge frequency: s
7
Selection of Digital Filters (FIR & IIR)
Finite Impulse Response (FIR) filter
always stable,
the phase can be made exactly linear,
we can approximate any filter we want.
Higher order w.r.t IIR filter (we need a lot of coefficients (N large) for good
performance)
8
Design of FIR Filters
Design means calculation (determination) of the coefficients of the
difference equation or the transfer function.
M
y ( n) h( k ) x ( n k )
k 0
M
H ( z ) h( k ) z k
k 0
9
Window Method
10
Design of FIR Filters (Window Method)
Simplest way of designing FIR filters
Method is all discrete-time no continuous-time involved
Start with ideal frequency response
H d e hd ne
j j n
hd n
1
2
H d e
j
e jn
d
n
11
Design of FIR Filters (Window Method)
In general, the obtained impulse response hd n is infinite in duration and
must be truncated at some point say at: 𝑛 = 𝑀 to give an FIR filter of
length M. Truncation of hd n to a length M is equivalent to multiplying by a
rectangular window defined as:
12
13
Effect of the Window Size
As the width of the window increases, its spectrum will be sharper and
the resulting convolution will be near ideal.
14
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
>> ylabel('h[n]') the impulse response
>> fvtool(h,1)
Sample-Shifted LP Impulse Response Magnitude Response
0.25 1.4
0.2 1.2
0.15 1
Magnitude
0.1 0.8
h[n]
0.05 0.6
0 0.4
-0.05 0.2
-0.1 0
0 2 4 6 8 10 12 14 16 18 20 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
n Normalized Frequency ( rad/sample)
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)
1.4
Magnitude Response
Higher order = sharper
transition
1.2
1
Side-lobe “ripple” (Gibbs
phenomenon) due to
abrupt truncation of the
Magnitude
0.8
0.6
impulse response
18
20
Window Parameters 0
-20
attenuation
Two important parameters:
-40
-60
Main lobe width.
-80
design
The window have a small main lobe width will transition
region
ensure a fast transition from the passband to
the stopband. with 𝑴 = 𝟐𝑳 + 𝟏
The area under the side lobes small will reduce hw (n) 0.25
the ripple.
0.2
0.15
0.1
0.05
-0.05
-0.1
-100 -50 0 50 100 n
L L 19
Rectangular Window
Narrowest main lob
4/(M+1)
Sharpest transitions at discontinuities in
frequency
1 0 n M
wn
0 else
20
Bartlett (Triangular) Window
Medium main lob
8/M
Side lobs
-25 dB
Simple equation
2n / M 0 n M/2
wn 2 2n / M M / 2 n M
0 else
21
Hanning Window
Medium main lob
8/M
Side lobs
-31 dB
Side lobs
-41 dB
23
Blackman Window
Large main lob
12/M
Complex equation
2n 4n
0.42 0.5 cos 0.08 cos 0nM
wn M M
0 else
24
Example of Design of an FIR filter using Windows
Specifications:
Pass Band = 0 - 4 kHz
Stop Band > 5kHz with attenuation of at least 40dB 40dB
Sampling Frequency = 20kHz
4 5 10 F kHz
Step 1: translate specifications into digital frequency 2
5 2
Pass Band 0 2 4 / 20 2 / 5 rad
Stop Band 2 5 / 20 / 2 rad
10
Step 2: from pass band, determine ideal filter impulse
response
c c 2 2n
hd (n) sinc n sinc
5 5
25
Example of Design of an FIR filter using Windows
Step 3: from desired attenuation choose the window.
In this case we can choose the hamming window;
Step 4: from the transition region choose the length N of the impulse response.
Choose an odd number N such that:
8
N 10
So choose N = 81 which yields the shift L=40.
Finally the impulse response of the filter
2 2(n - 40) 2 n
sinc 0.54 0.46 cos , if 0 n 80,
h( n) 5 5 80
0 otherwise
26
Example of Design of an FIR filter using Windows
The Frequency Response of the Filter:
H( )
dB
H( )
rad
27
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 The Blackman tapering
window provides greater
0 suppression of stop-band
side-lobes
Magnitude (dB)
-50
-100
-150
-200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency ( rad/sample)
28
Kaiser Window (A Parametrized Window)
All the windows discussed so far can be
approximated by an equivalent Kaiser
window.
Parameterized equation forming a set of
windows
Parameter to change main-lob width,
and side-lob area trade-off.
2
I 0 1 n M / 2
wn M / 2
0nM
I 0
0 else
where
2
1
2 1 x k
I o ( x) e
x cos
.d I o ( x) 1
2 0 k! 2
k 1
I0(.) represents zero-th order modified Bessel function of first kind.
30
Design guidelines using Kaiser windows
Assume a low pass filter.
Given that Kaiser windows have linear phase, we will only focus on the
jw
function H (e ) in the approximation filter A(e jw )
Normalize H (e ) to unity for 0 c , where
jw
c is the cutoff frequency of
the ideal low pass filter.
jw
Specify A(e ) in terms of
a passband frequency p ,
a stop band frequency s ,
a maximum passband distortion of 1 ,
and a maximum stopband distortion of 2 ,
The cutoff frequency c of the ideal low pass filter is midway between p and s
1 and 2 should be equal, because of the nature of windowing.
31
Design guidelines using Kaiser windows
Let
s p
1 2
and
A 20 log10
The shape parameter should be
0.1102 A 8.7 A 50
0.5842 A 210.4 0.07886 A 21 21 A 50
A 21
0
34
Frequency Sampling Method
35
FIR Filter Design (Frequency Sampling Method)
In this approach we are given H (k ) and need to find H (z )
This is an interpolation problem and the solution is given in the DFT
part of the course
1 N 1 1 zN
H ( z ) H (k ). 2
N k 0 j k
1
1 e N .z
36
37