You are on page 1of 37

LECTURE (6)

FIR Filter Design


Assist. Prof. Amr E. Mohamed

‫لما نصدق اننا ِن ْْقدَ ر‬ ،،، ‫نِـ ْقـدَ ر‬


Ideal Filters
 One of the reasons why we design a filter is to remove disturbances

s(n) x(n) y(n)  s(n)


SIGNAL
 Filter

v(n)
NOISE

 We discriminate between signal and noise in terms of the frequency


spectrum
S (F ) Y (F )

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

x(t )  s(t ) y(t )  As (t  T )


1.5
1

0.5 IDEAL 1 Same shape as s(t),


0.5
0
0 just scaled and
-0.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

 Consequence on the Frequency Response:


constant | H (F ) |

 Ae  j 2FT if F is in the passband


F
H (F )  
linear
 H (F )
0 otherwise

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   

 ie 𝐻(𝜔) cannot be zero on an interval, therefore it cannot be ideal.


H ( )

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

 The order of the FIR or IIR filter.

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)

 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 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

 Methods of FIR Filter Design:


 Window Method
 Frequency sampling method.

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 ne
j  j n
hd n 
1

2 
H d e 
j
e jn
d
n  

 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 H d e j

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:

 Thus, the impulse response of the FIR filter becomes :


1 0  n  M
hn  hd nwn where wn  
0 else
hd n 0  n  M
hn  
 0 else

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.

 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
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

0.4 How to reduce the Gibbs phenomenon?


0.2 1) using a window that tapers smoothly
to zero at each end.
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
Normalized Frequency ( rad/sample)
0.8 0.9
2) providing a smooth transition from
the passband to the stopband.
Windowing in Frequency Domain

 Windowed frequency response  
H e j 
1
2  d
H e  
j
W e 
j   
d


 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


17
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

1  e  j  M 1  jM / 2 sin  M  1 / 2


  e
M
j  jn
W e  e
n 0 1 e  j
sin / 2

18
20

Window Parameters 0

-20
attenuation
Two important parameters:
-40

-60
 Main lobe width.
-80

 Relative side lobe level. -100

 The effect of window function on FIR filter -120


0 0.5 1 1.5 2 2.5 3

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

 Large side lobs


 -13 dB
 Large oscillation around discontinuities

 Simplest window possible

1 0  n  M
wn  
0 else

20
Bartlett (Triangular) Window
 Medium main lob
 8/M

 Side lobs
 -25 dB

 Hamming window performs better

 Simple equation
 2n / M 0  n  M/2

wn  2  2n / M M / 2  n  M
 0 else

21
Hanning Window
 Medium main lob
 8/M

 Side lobs
 -31 dB

 Hanning window performs better

 Same complexity as Hamming


1   2n 
 1  cos  0  n  M
wn  2   M 
 0 else

22
Hamming Window
 Medium main lob
 8/M

 Side lobs
 -41 dB

 Simpler than Blackman


  2n 
0.54  0.46 cos  0nM
wn    M 

 0 else

23
Blackman Window
 Large main lob
 12/M

 Very good side lobs


 -57 dB

 Complex equation

  2n   4n 
0.42  0.5 cos   0.08 cos  0nM
wn    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 
 

wn     M / 2  
0nM
 I 0  

 0 else

 I0(.) represents zero-th order modified Bessel


function of first kind.
  represent the shape parameter coefficient.
29
Kaiser Window Filter Design Method
 Parameterized equation forming a set of windows
 Parameter to change main-lob width,
 and side-lob area trade-off.
  2
 I0  1   n  M / 2  

  M / 2  
wn    
 0nM
 I0 

 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  210.4  0.07886 A  21 21  A  50
 A  21
 0

 The filter order M is determined approximately by


A8
M
2.285 32
Example: Kaiser Window Design of a Lowpass Filter
 Example: Determine c ,  , M , when  p  0.4 ,  s  0.6 ,   1   2  0.001
 Solution:
 p
 Cutoff frequency, c  s  0.5
2

 Since, A  20 log10   60 , this means   0.1102 (60  8.7)  5.653

 Since,   s  p  0.2 , and A  20 log10   60


60  8
M  36.22  37
2.285  0.2
 Then the impulse response is given as
  2
  n  18.5 
I 0 5.653 1    

hn   sin0.5 n  18.5   18.5  
. 0nM
  n  18.5 I 0 5.653
 33
 0 else
General Frequency Selective Filters
 A general multiband impulse response can be written as
Nmb
sin k n  M / 2
hmb n   G  G 
n  M / 2
k k 1
k 1

 Window methods can be applied to multiband filters


 Example multiband frequency response
 Special cases of
• Bandpass
• Highpass
• Bandstop

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  zN
H ( z )   H (k ). 2
N k 0 j k
1
1 e N .z

 It has similar problems to the windowing approach

36
37

You might also like