dsp_foehu - lec 10 - fir filter design
TRANSCRIPT
درنق نصدق اننا لما ،،، نـقـدر
LECTURE (10)
FIR Filter Design
Assist. Prof. Amr E. Mohamed
Ideal Filters
One of the reasons why we design a filter is to remove disturbances
We discriminate between signal and noise in terms of the frequencyspectrum
2
)(ns
)(nv
)(nx )()( nsny FilterSIGNAL
NOISE
F
)(FS
)(FV
0F0F 0F F
)(FY
0F0F
Conditions for Non-Distortion Problem: ideally we do not want the filter to distort the signal we want to
recover.
Consequence on the Frequency Response:
3
IDEAL
FILTER
)()( tstx )()( TtAsty Same shape as s(t), just scaled and delayed.
0 200 400 600 800 1000-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
0 200 400 600 800 1000-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
0 200 400 600 800 1000-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
0 200 400 600 800 1000-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
otherwise
passbandtheinisFifAeFH
FTj
0)(
2F
F
|)(| FH
)(FH
constant
linear
Phase Distortion
Phase distortion results from a variable time delay (phase delay) fordifferent frequency components of a signal.
If the phase response of a filter is a linear function of frequency, thenthe phase delay is constant for all frequencies and no phase distortionoccurs.
4
Real Time Implementation For real time implementation we also want the filter to be causal, ie.
FACT (Bad News!): by the Paley-Wiener Theorem, if h(n) is causal and withfinite energy,
ie �(�) cannot be zero on an interval, therefore it cannot be ideal.
5
0for 0)( nnh
h n( )
n
since
0
)()()(k
knxkhny only spast value
dH )(ln
)(H
dHH )(log)0log()(log1 2
1
2
Practical Filter specifications
Filters
Frequency-selective Filter
Three Stages
Specifications
Approximation of the Specifications.
Realization
6
|)(| H
p
IDEAL
Practical Filter specifications
In practical design the following parameters would be specified:
The maximum ripple allowed in the pass-band:
The maximum ripple allowed in the stop-band:
The pass-band edge frequency:
The stop-band edge frequency:
The order of the FIR or IIR filter.
7
p
s
p
s
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 goodperformance)
Infinite Impulse Response (IIR) filter
very selective with a few coefficients
Always Nonlinear Phase.
8
Design of FIR Filters
Design means calculation (determination) of the coefficients of thedifference equation or the transfer function.
Methods of FIR Filter Design:
Window Method
Frequency sampling method.
9
M
k
knxkhny0
)()()(
M
k
kzkhzH0
)()(
Window Method
10
11
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
Choose ideal frequency response as desired response
Most ideal impulse responses are of infinite length
The easiest way to obtain a causal FIR filter from ideal is by evaluating the
IDTFT of
n
njd
jd enheH
deeHnh njjdd
2
1
jd eH
12
Design of FIR Filters (Window Method) In general, the obtained impulse response is infinite in duration and
must be truncated at some point say at: � = � to give an FIR filter oflength M. Truncation of to a length M is equivalent to multiplying by arectangular window defined as:
Thus, the impulse response of the FIR filter becomes :
else
Mnnhnh d
0
0
else
Mnnwnwnhnh d
0
01 where
nhd
nhd
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.
The rectangular window truncates the impulse response to be of
duration �. But this truncation introduces ripples (oscillations) in the
resulting frequency response characteristics (results of convolution).
14
>> 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')
>> ylabel('h[n]')
>> fvtool(h,1)
0 2 4 6 8 10 12 14 16 18 20-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25Sample-Shifted LP Impulse Response
n
h[n
]
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.90
0.2
0.4
0.6
0.8
1
1.2
1.4
Normalized Frequency ( rad/sample)
Magnitu
de
Magnitude Response
Note the linear phase properties of the impulse response
Example: 21 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)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.90
0.2
0.4
0.6
0.8
1
1.2
1.4
Normalized Frequency ( rad/sample)
Ma
gn
itude
Magnitude Response Higher order = sharper transition
Side-lobe “ripple” (Gibbs phenomenon) due to abrupt truncation of the impulse response
Example: 201 Coefficient LP Filter with Ω0 = π/4
How to reduce the Gibbs phenomenon?
1) using a window that tapers smoothly to zero at each end.
2) providing a smooth transition from the passband to the stopband.
17
Windowing in Frequency Domain
Windowed frequency response
The windowed version is smeared version of desired response
If w[n]=1 for all n, then W(ej) is pulse train with 2 period
deWeHeH jjd
j
2
1
18
Properties of Windows Prefer windows that concentrate around DC in frequency
Less smearing, closer approximation
Prefer window that has minimal span in time
Less coefficient in designed filter, computationally efficient
So we want concentration in time and in frequency
Contradictory requirements
Example: Rectangular window
2/sin
2/1sin
1
1 2/1
0
M
ee
eeeW Mj
j
MjM
n
njj
Window Parameters
Two important parameters:
Main lobe width.
Relative side lobe level.
The effect of window function on FIR filterdesign
The window have a small main lobe width willensure a fast transition from the passband tothe stopband.
The area under the side lobes small will reducethe ripple.
19
0 0.5 1 1.5 2 2.5 3-120
-100
-80
-60
-40
-20
0
20
0 0.5 1 1.5 2 2.5 3-120
-100
-80
-60
-40
-20
0
20
attenuation
transition region
-100 -50 0 50 100-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
L L
)(nhw
n
with � = ��+ �
20
Rectangular Window
else0
Mn01nw
Narrowest main lob
4/(M+1)
Sharpest transitions at discontinuities in frequency
Large side lobs
-13 dB
Large oscillation around discontinuities
Simplest window possible
21
Bartlett (Triangular) Window
else0
Mn2/MM/n22
2/Mn0M/n2
nw
Medium main lob
8/M
Side lobs
-25 dB
Hamming window performs better
Simple equation
22
Hanning Window
else0
Mn0M
n2cos1
2
1nw
Medium main lob
8/M
Side lobs
-31 dB
Hamming window performs better
Same complexity as Hamming
23
Hamming Window
Medium main lob
8/M
Side lobs
-41 dB
Simpler than Blackman
else0
Mn0M
n2cos46.054.0
nw
24
Blackman Window
else0
Mn0M
n4cos08.0
M
n2cos5.042.0
nw
Large main lob
12/M
Very good side lobs
-57 dB
Complex equation
Example of Design of an FIR filter using Windows
Specifications:
Pass Band = 0 - 4 kHz
Stop Band > 5kHz with attenuation of at least 40dB
Sampling Frequency = 20kHz
Step 1: translate specifications into digital frequency
Pass Band
Stop Band
Step 2: from pass band, determine ideal filter impulseresponse
25
2 5 20 2 / / rad
0 2 4 20 2 5 / / rad
h n ndc c( )
sinc sinc
2n
5
2
5
40dB
F kHz54 10
2
2
5
10
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:
So choose N = 81 which yields the shift L=40.
Finally the impulse response of the filter
26
8
10
N
h n
nn
( ). . cos , ,
2
5054 0 46
2
800 80sinc
2(n - 40)
5 if
0 otherwise
Example of Design of an FIR filter using Windows
The Frequency Response of the Filter:
27
H( )
H( )
dB
rad
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)
280 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
-200
-150
-100
-50
0
50
Normalized Frequency ( rad/sample)
Mag
nitu
de (
dB
)
Magnitude Response (dB)The Blackman taperingwindow provides greatersuppression of stop-bandside-lobes
Kaiser Window (A Parametrized Window)
All the windows discussed so far can beapproximated by an equivalent Kaiserwindow.
Parameterized equation forming a set ofwindows Parameter to change main-lob width, and side-lob area trade-off.
I0(.) represents zero-th order modified Besselfunction of first kind.
represent the shape parameter coefficient.29
else0
Mn0I
2/M
2/Mn1I
nw
0
2
0
Kaiser Window Filter Design Method
Parameterized equation forming a set of windows
Parameter to change main-lob width,
and side-lob area trade-off.
where
I0(.) represents zero-th order modified Bessel function of first kind.
30
else0
Mn0I
2/M
2/Mn1I
nw
0
2
0
2
0
cos .2
1)( dexI x
o
1
2
2!
11)(
k
k
o
x
kxI
Design guidelines using Kaiser windows Assume a low pass filter.
Given that Kaiser windows have linear phase, we will only focus on the
function in the approximation filter
Normalize to unity for , where is the cutoff frequency of
the ideal low pass filter.
Specify in terms of
a passband frequency ,
a stop band frequency ,
a maximum passband distortion of ,
and a maximum stopband distortion of ,
The cutoff frequency of the ideal low pass filter is midway between and
and should be equal, because of the nature of windowing.31
)( jweA)( jweH
)( jweH c 0 c
)( jweA
p
s
1
2
cp
s
1 2
Design guidelines using Kaiser windows
Let
and
The shape parameter should be
The filter order M is determined approximately by
32
ps
21
10log20A
210
50212107886.0215842.0
507.81102.04.0
A
AAA
AA
285.2
8AM
33
Example: Kaiser Window Design of a Lowpass Filter
Example: Determine , , , when
Solution: Cutoff frequency,
Since, , this means
Since, , and
Then the impulse response is given as
001.0,6.0,4.0 21 sp
5.02
ps
c
2.0ps
60log20 10 A 653.5)7.860(1102.0
3722.362.0285.2
860
M
else
MnI
nI
n
nnh
0
0653.5
5.18
5.181653.5
.5.18
5.185.0sin
0
2
0
c M
60log20A 10
34
General Frequency Selective Filters
A general multiband impulse response can be written as
Window methods can be applied to multiband filters
Example multiband frequency response
Special cases of
• Bandpass
• Highpass
• Bandstop
mbN
1k
k1kkmb
2/Mn
2/MnsinGGnh
Frequency Sampling Method
35
FIR Filter Design (Frequency Sampling Method)
In this approach we are given and need to find
This is an interpolation problem and the solution is given in the DFTpart of the course
It has similar problems to the windowing approach
36
1
0 12
.1
1).(
1)(
N
k kN
j
N
ze
zkH
NzH
)(kH )(zH
37