You are on page 1of 12

Aim of the Experiment:

Design of 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 ) +b 1 x ( n−1 ) +b 2 x ( n−2 ) +b 3 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 +¿
( M2−1 )e
−jω
2 − jωnT +h M −1
H ( e jω )= ∑ h(n) e ∑ h(n)e− jωnT ¿
n=0 M +1
N=
2

h(n)=h(M-1-n)

Putting k= (M-1)/2-n,

{∑ ( )} [ e
M−1

( M −1
)
( M2−1 )
2
− jω T
M −1
H ( e )=e
jω 2
h −k
jωnT
+e
− jωnT
]+ h
k=1 2
{∑ }
M −1
− jω ( M−1
2 )
T 2
H ( e jω )=e 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ω − jωn

n=−∞

Where

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 jω). are shown in the third row. ^
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

2
am plitude

phas e
0
0.5
-2

0 -4
0 0.5 1 0 0.5 1
frequency frequency
group delay gain
50 50
group delay

0
0
gain

-50
-50
-100

-100 -150
0 0.5 1 0 0.5 1
frequency frequency

Highpass using Hamming window:

magnitude phase
1.5 4

2
am plitude

1
phas e

0
0.5
-2

0 -4
0 0.5 1 0 0.5 1
frequency frequency
group delay gain
525 50
group delay

520
0
gain

515
-50
510

505 -100
0 0.5 1 0 0.5 1
frequency frequency

Bandpass using Hanning window


magnitude phase
1.5 4

2
am plitude

phas e
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
0
group delay

gain

2
-50
0

-2 -100
0 0.5 1 0 0.5 1
frequency frequency

Conclusion:
Aim of the Experiment:

Design of IIR (Butterworth Filter) (Low pass, High pass, Band pass &Band stop filter).

Software Required:

System software: Window XP

Application Software: MATLAB 7.1 software.

Theory:

A discrete –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 of
the system.

The system function describing an analog filter may be written as


M

∑ bk sk
H a ( s )= k=0
N (1)
∑ ak s k

k=0
Where {a k } and {b k} are the filter coefficients. The impulse response of these filter
coefficients is related to H a (s) by the Laplace transform.

H a ( s )= ∫ h(t )e
− st
dt (2)
−∞

The analog filter having the rational system function H(s) given in eq.1 can also be described
by the linear constant –coefficient differential equation
N
d k y (t ) M d k x (t)
∑ ak dt k =∑ bk dt
k=0 k=0

Where x(t) is the input signal and y(t) is the output of the filter. The above three
equivalent characterization of an analog filter leads to three alternative methods of
transforming the filter into the digital domain.

Butterworth Filters:

The Butterworth low-pass filter has a magnitude response given by

A
|H ( JΩ)|= ¿ ¿ ¿

Where A is the filter gain and Ωc is the 3dB cut-off frequency and N is the order of the filter.
The magnitude response of the Butterworth filter is shown in the figure. The magnitude
response has a

Maximally flat pass band and stop band. It can be seen that by increasing the filter order N,
the Butterworth response approximates the ideal response. However, the phase response of
the

Butterworth filter becomes more non-linear with increasing N.

Figure
Program:

Program for IIR filter:

i=input('enter 1.for low pass 2.for high pass 3.for bandpass 4.for band stop')
rp=1
rs=15
if i==1
wp=0.1
ws=0.2
[n,wn]=buttord(wp,ws,rp,rs)
[b,a]=butter(n,wn,'low')
end
if i==2
wp=0.2
ws=0.1
[n,wn]=buttord(wp,ws,rp,rs)
[b,a]=butter(n,wn,'high')
end
if i==3
wp=[0.2,0.8]
ws=[0.1,0.9]
[n,wn]=buttord(wp,ws,rp,rs)
[b,a]=butter(n,wn,'bandpass')
end
if i==4
wp=[0.1,0.8]
ws=[0.2,0.7]
[n,wn]=buttord(wp,ws,rp,rs)
[b,a]=butter(n,wn,'stop')
end
[h,w]=freqz(b,a)
m=abs(h)
p=angle(h)
gain=20*log10(m)
gd=grpdelay(h)

subplot(221)
plot(m)
title('magnitude')
xlabel('frequency')
ylabel('amplitude')
subplot(222)
plot(p)
title('phase')
xlabel('frequency')
ylabel('phase')
subplot(223)
plot(gain)
title('gain')
xlabel('frequency')
ylabel('gain')
subplot(224)
plot(gd);title('group delay')
xlabel('frequency');ylabel('group delay')

Observation:

Lowpass butterworth filter:

magnitude phase
1.5 4

2
am plitude

1
phas e

0
0.5
-2

0 -4
0 200 400 600 0 200 400 600
frequency frequency
gain group delay
100 10
group delay

0
5
gain

-100
0
-200

-300 -5
0 200 400 600 0 200 400 600
frequency frequency

Highpass butterworth filter:


magnitude phase
1.5 4
a m p litu d e 2
1

phas e
0
0.5
-2

0 -4
0 200 400 600 0 200 400 600
frequency frequency
gain group delay
100 600

g ro u p d e la y
0 500
g a in

-100 400

-200 300
0 200 400 600 0 200 400 600
frequency frequency

Bandpass butterworth filter:

magnitude phase
1 4

2
am plitude

phase

0.5 0

-2

0 -4
0 200 400 600 0 200 400 600
frequency frequency
16
gain x 10 group delay
0 15
group delay

10
-50
gain

5
-100
0

-150 -5
0 200 400 600 0 200 400 600
frequency frequency

Bandstop butterworth filter:


magnitude phase
1.5 4

2
amplitude
1

phase
0
0.5
-2

0 -4
0 200 400 600 0 200 400 600
frequency frequency
4
gain x 10 group delay
100 4

group delay
2
gain

-100
0
-200

-300 -2
0 200 400 600 0 200 400 600
frequency frequency

Conclusion:

You might also like