EXPERIMENT NO:8
Aim of the Experiment:
To Design FIR filter (Low pass, High pass, Band pass and Band stop) using windowing
technique (Hanning , Hamming & Rectangular ).
Software Required:
System software: Window XP
Application Software: MATLAB 7.1 software.
Theory:
A discreete –time filter produces a discrete -time output sequence y(n) for the discrete-time
input sequence x(n). Digital filters are classified either as finite duration unit pulse response
(FIR) filters or infinite duration unit pulse response (IIR) filters, depending on the form of
the unit pulse responseof the system. In the FIR system,the impulse response sequence is of
finite duration,i.e it has a finite number of non-zero terms.FIR filters are usually
implemented using structures with no feedback (non- recursive structures –all zeros).
An FIR filter of length M is described by the difference equation
y ( n )=b0 x ( n )+ b1 x ( n−1 )+ b2 x ( n−2 )+ b3 x ( n−3 ) +…+ bm−1 x ( n− M +1 )
M −1
¿ ∑ bk x(n−k)
k=0
Where {b k } is the set of filter coefficients. The response of the FIR filter depends only on the
present and past input samples, whereas for the IIR filter, the present response is a function
of the present and
past N values of the excitation as well as past values of the response.
Frequency Response of Linear phase fir Filters
If the filter length M is odd,
M −3
( M2−1 ) T +¿
( M −1
2 )
−jω
2 − jωnT + h e M −1
H ( e )= ∑ h(n)e ∑
jω − jωnT
h(n)e ¿
n =0 M +1
N=
2
h(n)=h(M-1-n)
Putting k= (M-1)/2-n,
{∑ ( )}[ e
M −1
( M2−1 )T
( M2−1 )
2
− jω
M −1
H ( e jω )=e h −k jωnT
+e− jωnT ] +h
k=1 2
{∑ }
M −1
− jω ( M −1
)T 2
H ( e jω )=e 2
a (k )cosωkT
k=1
− jω ( M2−1 )T
¿e =M (ω)
The equation defines the frequency response of a casual FIR with linear phase shift. The
cosine function is real and represents the frequency response.
Window Techniques:
The desired frequency response of any digital filter is periodic in frequency and can be
expanded in a Fourier series, i.e.
∞
H d ( e ) = ∑ hd ( n ) e− jωn
jω
n=−∞
Where
2π
1
h ( n )= ∫ H ❑ ( e ) dω
jωn
2π 0
ω (n), referred to as window functions
The sequence h^ (n)=h(n).ω (n) is obtained to get an FIR approximation of H(e jω ). The
sequence h^ (n) is exactly zero outside the interval –N≤n≤N. The sequence h^ (n) and its
Fourier transform ^ H (e ). are shown in the third row. ^
jω
H (e jω ) is nothing but the circular
convolution of H(e jω ) and W(e jω)
Program:
Program for FIR filter:
i=input('enter 1-lp,2-hp,3-bp,4-bs')
N=23;
a=1;
if i==1
wn=0.5;
w1=rectwin(N+1);
b=fir1(N,wn,'low',w1);
[H,W]=freqz(b,a);
end
if i==2
wn=0.5;
w1=hamming(N+2);
b=fir1(N,wn,'high',w1);
[H,W]=freqz(b,a);
end
if i==3
wn=[0.2,0.8];
w1=hann(N+1);
b=fir1(N,wn,'bandpass',w1);
[H,W]=freqz(b,a);end
if i==4
wn=[0.2,0.8];
w1=kaiser(N+2);
b=fir1(N,wn,'stop',w1);
[H,W]=freqz(b,a);
end
m=abs(H);
p=angle(H);
gd=grpdelay(H);
g=20*log10(m);
subplot(221)
plot(W/pi,m)
title('magnitude');xlabel('frequency');ylabel('amplitude')
subplot(222)
plot(W/pi,p)
title('phase');xlabel('frequency');ylabel('phase')
subplot(223)
plot(W/pi,gd)
title('group delay');xlabel('frequency');ylabel('group delay')
subplot(224)
plot(W/pi,g); xlabel('frequency');ylabel('gain')
title('gain');
Observation:
Lowpass using rectangular window:
magnitude phase
1.5 4
amplitude
phase
2
1
0
0.5
-2
0 -4
0 0.5 1 0 0.5 1
frequency frequency
group delay gain
group delay
50 50
0
gain
0
-50
-50
-100
-100 -150
0 0.5 1 0 0.5 1
frequency frequency
Highpass using Hamming window:
magnitude phase
1.5 4
amplitude
phase
2
1
0
0.5
-2
0 -4
0 0.5 1 0 0.5 1
frequency frequency
group delay gain
group delay
525 50
520
gain
0
515
-50
510
505 -100
0 0.5 1 0 0.5 1
frequency frequency
Bandpass using Hanning window
magnitude phase
1.5 4
amplitude
2
1
phase
0
0.5
-2
0 -4
0 0.5 1 0 0.5 1
frequency frequency
group delay gain
4000 50
group delay
2000
0
gain
0
-50
-2000
-4000 -100
0 0.5 1 0 0.5 1
frequency frequency
Bandstop using Kaiser window:
magnitude phase
1.5 4
2
1
amplitude
phase
0
0.5
-2
0 -4
0 0.5 1 0 0.5 1
frequency frequency
18
x 10 group delay gain
6 50
4
group delay
0
gain
2
-50
0
-2 -100
0 0.5 1 0 0.5 1
frequency frequency
Conclusion: