3 FIR Filter Design by YBP 01-09-2013

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

Input

FIR FILTER
DESIGN
Design by
Prof. Yogesh B. Patel
Assistant Professor
Output EC Dept., UVPCE
Digital Filters
Digital filter allow desired band of frequency and attenuate (stop) undesired band
of frequency of digital input signal to produce digital output signal.

The arithmetic computation required by the digital filter for filtering the signal is
performed on a DSP processor or general purpose processor. This is, in general,
called as Digital Signal Processing.

Advantages :
 A digital filter is a computer program and hence it is reprogrammable as per
need.
 Digital filters are easily designed, tested and implemented on computer or
workstation.
 Digital filters are extremely stable with respect both to ambient conditions
and ageing (time).
 Digital filters can handle very low frequency signals accurately.
Classification of Digital Filters
 Time Domain based Classification
 Infinite Impulse Response (IIR)
 Finite Impulse pulse Response (FIR)
 Transfer Function based Classification
Based on magnitude characteristics
 LPF, HPF, BPF and BSF
 All pass
 Based on phase characteristics
 Zero phase
 Linear phase
 Minimum phase & Maximum phase.
Time Domain based Classification:

Digital Filters are classified based on the length of impulse response,


 Infinite Impulse Response (IIR): It contains infinite number of
samples, i.e. length of impulse response is infinite.
Example: h(n) = (O.5)n u(n).
h(n) = {1, .5, .25, .125, ……..}
 Finite Impulse Response (FIR): It contains finite number of
samples, i.e. length of impulse response is finite.
Example: h(n) = {1, 2, 0, -2, 1.5).
Classification Based On Magnitude Characteristics
Low-Pass, High-pass Band-Pass and Band-Stop filter,
 A special type of IIR filter characteristics by unity magnitude
for all frequencies is called as all pass filter.
Why maximum frequency –π ≤ Ω ≤ π ?
 Maximum frequency in DSP system is the folding
frequency fs/2
 Where fs=1/Ts and Ts = Sampling Period
 Maximum Normalized freq.
Ω=ωTs=2π.(fs/2) .Ts
= (2π).(1/2Ts) .Ts
= π radians
 Positive Normalized Frequency range Ω = 0 to π
radians
Mathematical Models of IIR and FIR Filter
Input/output Relation (Time Domain) Form
Infinite Impulse Response (IIR) Filter, Finite Impulse Response (FIR) Filter,
Using convolution Using convolution
∝ M
y ( n) = ∑ h( k ) x ( n − k ) 0≤ n ≤ ∞ y ( n) = ∑ h( k ) x ( n − k ) 0≤ n ≤ N-1
k = −∝ k =0

Using Difference equation, Using Difference equation,


M
y[n] = ∑ bk x[n − k ]
N M
y[n] = −∑ ak y[n − k ] + ∑ bk x[n − k ] n≥ 0 n≥ 0
k =1 k =0 k =0

Transfer function form Transfer function form


M

∑ k
b z −k
M
H (z ) =
Y ( z)
H (z ) =
Y ( z)
= k =0 = ∑ bk z − k
N
X ( z ) k =0
1 + ∑ ak z − k
X ( z)
k =1
Here, ak and bk are the coefficients of the filter which have to be selected
suitably to make the filter to achieve the desired output.
Example:
Find the impulse response of a digital system with following input output relation.
Is it an IIR or FIR filter?
a) y(n) = ½ x(n)+ ½ x(n-l)
b) y(n) = x(n) + y (n -1);
Solution:
a) y(n) = ½ x(n)+ ½ x(n-l)
Taking Z - transform
Y(z) = ½ X(z) + ½ z-1 X(z)
Y(z)/X(z) = H(z) = ½ + ½ z-1
Comparing this with transform function of FIR filter
Here , b0= ½ And b1= ½
Therefore , h(n) = { b0 , b1 }
:. Unit sample response h(n) = { ½, ½ }
This is the unit sample response of the digital FIR filter because it contains only
two samples i.e. finite number of samples.
Moreover , it is observed that output depends only on present and past input and
not on past output. This is import characteristic of FIR filter. Also known as
Nonrecursive Filter.
b) y(n) = y(n-1) + x(n)
Taking Z - transform
Y(z) = z-1 Y(z) + X(z)
System function Y(z)/X(z) = H(z) = 1/(1 - z-1 )
The inverse Z-transform of system function H(z) is called unit sample response or
impulse response denoted by h(n.)
Hence taking inverse Z-transform of above equation,
h(n) = u(n)
We know that,
u(n) = 1 for n ≥ 0
0 for n < 0
u(n) = { 1,1,1,………….}
Unit step function has infinite duration. Therefore the filter we have considered
here is IIR filter.
Moreover, it is observed that output depends only on present and past input as well
as on past output. This is important characteristic of IIR filter. Also known as
Recursive Filter
Advantages of IIR Filters
 IIR filters are useful for high speed designs because they typically
require a lower number of multipliers compared to FIR filters.
 The attenuation characteristic of IIR filter is always superior than
what is required.
 IIR Filter require less resources for implementation as compared
to FIR filters because of Feedback taps.

Disadvantages of IIR Filters


 Stability is not always guaranteed in IIR Filters.
 IIR filters can never be linear phase.
 IIR filters also are very sensitive to filter coefficient quantization
errors that occur due to using a finite number of bits to represent
the filter coefficients.
Advantages of FIR Filters
 FIR filters are easy to implement.
 They are guaranteed bounded input bounded output (BIBO) stable.
 FIR filter (Symmetric and anti-symmetric) can be guaranteed to have linear
phase. This is a desirable property for many applications such as video
processing.
 FIR filters also have a low sensitivity to filter coefficient quantization errors.
This is an important property to have when implementing a filter on a DSP
processor or on an integrated circuits.
Disadvantages of FIR Filter
 Order of an FIR filter, in most cases, is considerably higher than the order of
an equivalent IIR filter for meeting the same specifications. FIR filter has thus,
higher computational complexity.
 The attenuation characteristic of FIR filter is always inferior than what is
required.
Limitations of IIR filter

 We approximate the attenuation characteristic of the filter to


make it as tight as possible with an effort to go as closer to ideal
characteristic as possible. But for this, certain approximations
are done e.g. Butterworth approximation, Chebyshev-I or
Chebyshev-II approximation etc.
 We ignore the phase characteristic in designing IIR filter
because linear phase characteristic can not be achieve in IIR
filter design.
 IIR filters are always non-linear in phase.
 This problem of non-linear phase characteristic in design of
IIR filter can be resolved in FIR filter design.
That means, it contains more than one frequency component (sinusoidal
component) in it.

Therefore for non linear phase filter, the frequency components which
form the input signal will reach the output at different time instances
to form the output signal which is said to be phase distorted output
signal.

The effect of phase distortion on the quality of signal will be very large if
the signal band width is larger e.g. video signal is compared to low
bandwidth signal because small part of non-linear phase characteristics can
be considered as linear for low bandwidth.

The audio signal bandwidth (20 kHz) is very small, therefore , phase
distortion is not occurs in these signal. However, video signal band
width is very large (5MHz). Therefore phase distortion is large.

Thus IIR filter can be used for processing of audio signal but for video
signal linear phase FIR filter are preferred to video signal processing.
Phase distortion can’t be made zero in case of IIR filter design but can be
minimized. This complete problem can be eliminated by use of symmetric
or Antisymmetric FIR filter because symmetric and Antisymmetric FIR
filters are always linear in phase. Therefore, group velocity is constant. i.e.
no phase distortion.

If any impulse response with odd or even number of samples can be made
symmetric or Antisymmetric and any impulse response which is symmetric
or Antisymmetric is always linear in phase.

But, Attenuation characteristic of FIR filter is always inferior is that of IIR


filter (because FIR filter is designed by truncating the IIR to make it FIR).

Hence, FIR filter are designed where linear phase is essential. Typical
example of application of linear phase FIR filter is filtering of video
signals.
Filter Type Choice between : FIR and IIR
FIR IIR
No feedback (only zeros). Feedback (poles & zeros).
Always stable. May be unstable.
Can be linear phase. Non linear phase.
High order (20-2000). Typ. <1/10th order of FIR
(4-20).
If you care about phase If you care about
response, use linear phase computational cost and
FIR. attenuation response, use
low complexity IIR.
Condition of Linear Phase Characteristics
To achieve the linear phase characteristic, impulse response of filter
is essentially needed to be either Symmetric or Antisymmetric.

Only FIR systems can be symmetric or anti-symmetric because it’s


impulse response contains finite number of samples.

Thus, IIR systems can never be linear phase. Therefore, it suffers


with the problem of phase distortion, especially filtering application
of large bandwidth signals like video signals.

To overcome the problem of phase distortions, Symmetric or


Antisymmetric FIR Filters are used.
Impulse Response of Ideal Lowpass filter
(Why Ideal frequency selective filters are practically not realizable?)

Frequency response of ideal low pass filter

Impulse response of Ideal low pass filter

Noncausal impulse response of


ideal lowpass filter, due to that
Ideal frequency selective filter
is practically not realizable.
Impulse Response of Ideal Lowpass filter

Here ωc=Cut off frequency and |H(ω)|=Magnitude of filter

When n=0

When n≠0

Sketch h(n) by taking

Note: for derivation of above equation refer class note


Impulse Response of Ideal Highpass filter

Here ωc=Cut off frequency and |H(ω)|=Magnitude of filter

When n=0

When n≠0

Sketch h(n) by taking

Note: for derivation of above equation refer class note


Impulse Response of Ideal Bandpass filter

Here ωc=Cut off frequency and |H(ω)|=Magnitude of filter

When n=0

When n≠0

Sketch h(n) of eq. (4) and (5) by taking

Note: for derivation of above equation refer class note


Impulse Response of Ideal Bandstop filter

Here ωc=Cut off frequency and|H(ω)|=Magnitude of filter

When n=0

When n≠0

Sketch h(n) of eq. (4) and (5) by taking

Note: for derivation of above equation refer class note


FIR Filter
Design
Techniques
FIR filter design techniques
There are several method for FIR filter design which are
listed below:

 Fourier transform method


 Window method
 Frequency sampling method
 Optimal design method
However, first three methods are more popular.
Gibb’s phenomenon
Oscillatory behavior in the magnitude responses of causal FIR filters obtained by
truncating the impulse response coefficients of ideal filters.

 Tight window function produces more ripples but less transition band.
 Smooth window function produces less ripples but wide transition band.
 Thus, selection of window function is a compromise between ripples tolerated and
transition band required in FIR filter design.
Ideal low-pass filter approximation
FIR Filter Design using Fourier transform method

Refer Your Class note


Window Method

Bright Side:
Design procedure is simple and it is same for LP ,HP,
BP,BS.

Dark Side:
Truncation in the time-domain results in ‘Gibbs effect’ in
the frequency domain, i.e. large ripple in pass-band and
stop-band, which cannot be reduced by increasing the filter
order N-1.
FIR Filter Design using ‘Windows’

 In, multiplication in Time-domain corresponds to


convolution in frequency domain :
h(n) = Hd (n). w (n)
H(ω) = Hd(ω) * W(ω)

 Window functions: Rectangular, Hann, Hamming,


Blackman, Kaiser, etc.
 Window choice is trade-off between side-lobe levels
(peak pass-band or stop-band ripples) and main-lobe
width (transition bandwidth).
Filter Design by Windowing
• Simplest way of designing FIR filters
• Method is all discrete-time no continuous-time involved
• Start with ideal frequency response
( )
∞ π
1
Hd e = ∑ hd [n]e

n = −∞
− jωn
hd [n] =
2π −∫π
Hd e( )

e jω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

hd [n] 0 ≤ n ≤ M
h[n] = 
 0 else

• More generally
1 0 ≤ n ≤ M
h[n] = hd [n]w[n] where w[n] = 
0 else
Windowing in Frequency Domain
• Windowed frequency response
π
1
( )
H e jω = ∫
2π − π
Hd ( ) (
e jω
W e )
j(ω − θ )

• 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


Fixed Window function

Using a tapered window causes the height of the sidelobes


to diminish, with a corresponding increase in the main lobe
width resulting in a wider transition at discontinuity.
Comparison of different window functions
Rectangular Window
Wrec[n] = 1, −M ≤ n ≤ M

• Narrowest main lob


– 4π/N
– Sharpest transitions at
discontinuities in
frequency

• Large side lobs


– -13 dB
– Large oscillation
around discontinuities

• Simplest window
possible

• As M increases, the main lobe becomes narrower, the area under the
side lobes remains the same irrespective of the changes in value of M.
Bartlett (Triangular) Window
n
Wtri[n] = 1 − , −M ≤ n ≤ M
M

• Medium main lob


– 8π/N

• Side lobs
– -26 dB

• Hamming window
performs better

• Simple equation

• Side lobe decreases and touches to higher negative value


Hanning Window
 nπ 
Whan[n] = 0.5 + 0.5 cos , − M ≤ n ≤ M
M 
• Medium main lob
– 8π/N

• Side lobs
– -31 dB

• Hamming window
performs better
• Same complexity as
Hamming

• It is like triangle but first and last sample is zero.


• Main lobe width is increase compare to rectangular window.
• Used in speech processing and music analysis.
• Vast difference in spectrum. Main lobe is narrow and significant sidelobe and narrow
sidelobes decreasing very fast.
Hamming Window
 nπ 
Wham[n] = 0.54 + 0.46 cos , − M ≤ n ≤ M
M 

• Medium main lob


– 8π/N

• Good side lobs


– -41 dB

• Simpler than Blackman

• This window is mostly used in speech processing.


• First and Last sample are not zero.
• It has reduced side lobe but slightly increase in
main lobes.
• Width of main lobe is same as the hann window (larger than rectangular window).
• Magnitude of side lobe (-41 dB) slightly lower than hann window.
• But magnitude of all side lobes is approximately same unlike hann window.
Blackman Window
 nπ   2nπ 
Wblack [n] = 0.42 + 0.5 cos  + 0.08 cos , −M ≤ n ≤ M
M   M 
• Large main lob
– 12π/N

• Very good side lobs


– -51 dB

• Complex equation

• The First and Last sample is zero.


• It is decreasing very fast.
• Main lobe is very wide and side
lobe decreases gradually
• The width of main lobe is maximum among all
other window.
• The magnitude of second side lobe is minimum
among all window.
%MATLAB Program:
%Hamming Window
M=50;
n=0:M; Whm=0.54-0.46*cos(2*pi*n/M);
subplot(514);
%Rectangular Window stem(n,Whm);
Wr=ones(1,M+1); title('Hamming Window');
subplot(511);
stem(n,Wr);
title('Rectangular Window');
%Hanning Window

%Triangular Window Whn=0.5*(1-cos(2*pi*n/M));


n1=0:M/2; subplot(515);
Wt1=(2.*n1)/M; stem(n,Whn);
title('Hanning Window');
n2=M/2+1:M;
Wt2=2-(2.*n2)/M;
figure();
Wt=[Wt1 Wt2]; plot(n,Wt,'-b*');
subplot(512); hold on
stem(n,Wt); plot(n,Wb,'-g*');
title('Triangular Window'); hold on
plot(n,Whm,'-g+');
%Blackman Window hold on
Wb=0.42-0.5.*cos(2*pi*n/M)+0.08.*cos(4*pi*n/M);
plot(n,Whn,'-bo');
subplot(513) legend('Triangular Window','Blackman
stem(n,Wb); Window','Hamming Window','Hanning Window');
title('Blackman Window');
Frequency response of fixed window functions
Frequency response plots of various fixed window
function’s for M =25 are shown below:
Frequency response of fixed window functions

 The width of main lobe is minimum in rectangular


window and maximum in Blackman.
 Magnitude of second slide lobe is maximum in
rectangular window and minimum in Blackman window.
 For hanning and hamming window the main lobe width
and magnitude of second slide lobe is optimum.
For Length of filter =N and order of filter =N-1

Main Minimum
Peak of first
Window lobe stopband
side lobe(dB)
width attenuation (dB)

Rectangular 4π/N -13 -21


Bartlett 8π/N -26 -26
Hanning 8π/N -31 -44
Hamming 8π/N -41 -53
Blackman 12π/N -51 -74
Kaiser a=5.4414 8π/N -41 -53

You might also like