Académique Documents
Professionnel Documents
Culture Documents
clc;
clear all;
close all;
disp('FIR low pass filter using rectangular, triangular, Hanning, hamming and Black mann
window ');
%Inputs
Fc=input('Enter cut-off frequency Fc in Hz ');
F=input('Enter sampling frequency F in samples/sec ');
N=input('Enter the order of filter ');
M=N+1; %Length of filter
% conversion and normalization of frequencies
wc=2*Fc/F; %pi radians/second
%Error message
if F<=Fc
error('Sampling rate > or = 2*Fc');
end
%window coefficients
%Rectangular
wr=rectwin(M);
%Triangular
wt=bartlett(M);
%Hanning
wh=hann(M);
%Hamming
wH=hamming(M);
%Blackman
wb=blackman(M);
%Desired filter coefficients
%Rectangular
br=fir1(N,wc,'bandpass',wr);
%Triangular
bt=fir1(N,wc,wt);
%Hanning
bh=fir1(N,wc,wb);
%Hamming
bH=fir1(N,wc,wH);
%Blackman
bb=fir1(N,wc,wb);
%Frequency response
%Rectangular
[Hr,fr]=freqz(br,1,512,F);
%Triangular
[Ht,ft]=freqz(bt,1,512,F);
%Hanning
[Hh,fh]=freqz(bh,1,512,F);
%Hamming
[HH,fH]=freqz(bH,1,512,F);
%Blackman
[Hb,fb]=freqz(bb,1,512,F);
%Plotting
%Window
n=0:N;
subplot(3,1,1);
stem(n,wr');
xlabel('n');
ylabel('wr');
title('Rectangular window');
%response
subplot(3,1,2);
plot(fr,20*log10(abs(Hr)));
xlabel('f in hz');
ylabel('|H(w)|');
title('Magnitude response of FIR low pass filter using rectangular window');
subplot(3,1,3);
plot(fr,angle(Hr));
xlabel('f in hz');
ylabel('Phase of H(w)');
title('Phase response of FIR low pass filter using rectangular window');
disp('Press any key to continue....');
pause;
close all;
%Window
subplot(3,1,1);
stem(n,wt');
xlabel('n');
ylabel('wt');
title('triangular window');
%response
subplot(3,1,2);
plot(ft,20*log10(abs(Ht)));
xlabel('f in hz');
ylabel('|H(w)|');
title('Magnitude response of FIR low pass filter using triangular window');
subplot(3,1,3);
plot(ft,angle(Ht));
xlabel('f in hz');
ylabel('Phase of H(w)');
title('Phase response of FIR low pass filter using triangular window');
xlabel('n');
ylabel('wb');
title('Blackman window');
subplot(3,1,2);
plot(ft,20*log10(abs(Hb)));
xlabel('f in hz');
ylabel('|H(w)|');
title('Magnitude response of FIR low pass filter using Blackman window');
subplot(3,1,3);
plot(ft,angle(Hb));
xlabel('f in hz');
ylabel('Phase of H(w)');
title('Phase response of FIR low pass filter using Blackman window');
Results:
FIR low pass filter using rectangular, triangular, Hanning, hamming and Black mann window
Enter cut-off frequency Fc in Hz 4000
Enter sampling frequency F in samples/sec 20000
Enter the order of filter 20
R e c t a n g u la r w in d o w
1
wr
0 .5
10
12
14
16
18
n
M a g n i t u d e r e s p o n s e o f F IR l o w p a s s fi l t e r u s i n g r e c t a n g u l a r w i n d o w
20
1000
2000
3000
4000
10000
1000
2000
3000
4000
50
|H (w )|
0
-5 0
-1 0 0
5000
6000
7000
8000
9000
f in h z
P h a s e r e s p o n s e o f F IR lo w p a s s filt e r u s in g r e c t a n g u la r w in d o w
P h a s e o f H (w )
-5
5000
f in h z
6000
7000
8000
9000
10000
Filter coefficients:
br = 0.0000 -0.0352 -0.0244 0.0279 0.0527 -0.0000 -0.0791 -0.0652 0.0978 0.3164
0.4181 0.3164 0.0978 -0.0652 -0.0791 -0.0000 0.0527 0.0279 -0.0244 -0.0352
0.0000
t ria n g u la r w in d o w
wt
0 .5
10
12
14
16
18
n
M a g n it u d e r e s p o n s e o f F IR lo w p a s s fi lt e r u s in g t r ia n g u l a r w in d o w
20
1000
2000
3000
4000
10000
1000
2000
3000
4000
|H ( w ) |
-2 0
-4 0
5000
6000
7000
8000
9000
f in h z
P h a s e r e s p o n s e o f F IR lo w p a s s filt e r u s in g t r ia n g u la r w in d o w
P h a s e o f H (w )
-5
5000
f in h z
6000
7000
8000
9000
10000
Filter coefficients:
bt = 0 -0.0035 -0.0049 0.0084 0.0211 -0.0000 -0.0475 -0.0456 0.0782 0.2848
0.4181 0.2848 0.0782 -0.0456 -0.0475 -0.0000 0.0211 0.0084 -0.0049 -0.0035 0
h a n n in g w in d o w
1
wh
0 .5
10
12
14
16
18
n
M a g n i t u d e r e s p o n s e o f F I R l o w p a s s fi l t e r u s i n g H a n n i n g w i n d o w
20
1000
2000
3000
4000
10000
1000
2000
3000
4000
|H ( w ) |
-1 0 0
-2 0 0
P h a s e o f H (w )
-5
5000
f in h z
6000
7000
8000
9000
10000
Filter coefficients:
bh = 0.0000 -0.0003 -0.0009 0.0027 0.0101 -0.0000 -0.0386 -0.0430 0.0794 0.2906
0.3999 0.2906 0.0794 -0.0430 -0.0386 -0.0000 0.0101 0.0027 -0.0009 -0.0003
0.0000
H a m m in g w in d o w
1
wH
0 .5
10
12
14
16
18
n
M a g n i t u d e r e s p o n s e o f F I R l o w p a s s fi l t e r u s i n g H a m m i n g w i n d o w
20
1000
2000
3000
4000
10000
1000
2000
3000
4000
50
|H ( w ) |
0
-5 0
-1 0 0
-1 5 0
5000
6000
7000
8000
9000
f in h z
P h a s e r e s p o n s e o f F IR l o w p a s s f i l t e r u s i n g H a m m i n g w i n d o w
P h a s e o f H (w )
4
2
0
-2
-4
Filter coefficients:
bH = -0.0000 -0.0035 -0.0039
0.2965 0.4008 0.2965 0.0855
-0.0035 -0.0000
0.0072
-0.0506
5000
f in h z
6000
7000
8000
9000
10000
0.0855
-0.0039
B la c k m a n w in d o w
1
wb
0 .5
10
12
14
16
18
n
M a g n i t u d e r e s p o n s e o f F IR l o w p a s s fi l t e r u s i n g B l a c k m a n w i n d o w
20
1000
2000
3000
4000
10000
1000
2000
3000
4000
|H ( w ) |
-1 0 0
-2 0 0
5000
6000
7000
8000
9000
f in h z
P h a s e r e s p o n s e o f F IR l o w p a s s f i l t e r u s i n g B l a c k m a n w i n d o w
P h a s e o f H (w )
-5
5000
f in h z
6000
7000
8000
9000
10000
Filter coefficients:
bb= 0.0000 -0.0003 -0.0009 0.0027 0.0101 -0.0000 -0.0386 -0.0430 0.0794 0.2906
0.3999 0.2906 0.0794 -0.0430 -0.0386 -0.0000 0.0101 0.0027 -0.0009 -0.0003
0.0000
2. %FIR low pass filter using common windows
clc;
clear all;
close all;
disp('FIR low pass filter using Kaiser window');
%Inputs
K a is e r w in d o w
1
wk
0 .5
1000
1000
10
12
14
16
18
n
M a g n it u d e r e s p o n s e o f F IR lo w p a s s filt e r u s in g K a is e r w in d o w
20
2000
3000
4000
10000
2000
3000
4000
|H (w ) |
-5 0
-1 0 0
5000
6000
7000
8000
9000
f in h z
P h a s e r e s p o n s e o f F IR lo w p a s s filt e r u s in g K a is e r w in d o w
P h a s e o f H (w )
4
2
0
-2
-4
5000
f in h z
6000
7000
8000
9000
10000
Filter coefficients:
bk= -0.0000 -0.0000 -0.0000
0.0000
0.0000 -0.0000 -0.0013 -0.0069
0.2551 0.4319 0.2551 0.0372 -0.0069 -0.0013 -0.0000 0.0000 0.0000
-0.0000 -0.0000
2)
FIR low pass filter using Kaiser window
Enter cut-off frequency Fc in Hz 4000
Enter sampling frequency F in samples/sec 20000
Enter the order of filter 100
0.0372
-0.0000
wk
0 .5
10
20
30
40
50
60
70
80
90
n
M a g n i t u d e r e s p o n s e o f F IR l o w p a s s f i l t e r u s i n g K a i s e r w i n d o w
100
1000
2000
3000
4000
10000
1000
2000
3000
4000
500
|H ( w ) |
0
-5 0 0
-1 0 0 0
5000
6000
7000
8000
9000
f in h z
P h a s e r e s p o n s e o f F IR l o w p a s s fi l t e r u s i n g K a i s e r w i n d o w
P h a s e o f H (w )
-5
5000
f in h z
6000
7000
8000
9000
10000
Filter coefficients:
bk= -0.0000 -0.0000 -0.0000
0.0000
0.0000 -0.0000 -0.0000 -0.0000
0.0000
0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0001 -0.0000 0.0001
0.0001 -0.0000 -0.0003 -0.0002 0.0003 0.0007 -0.0000 -0.0012 -0.0009 0.0012
0.0024 -0.0000 -0.0037 -0.0028 0.0034 0.0068 -0.0000 -0.0099 -0.0074 0.0088
0.0171 -0.0000 -0.0245 -0.0182 0.0221 0.0438 -0.0000 -0.0711 -0.0602 0.0921
0.3016 0.4000 0.3016 0.0921 -0.0602 -0.0711 -0.0000 0.0438 0.0221 -0.0182
-0.0245 -0.0000 0.0171 0.0088 -0.0074 -0.0099 -0.0000 0.0068 0.0034 -0.0028
-0.0037 -0.0000 0.0024 0.0012 -0.0009 -0.0012 -0.0000 0.0007 0.0003 -0.0002
-0.0003 -0.0000 0.0001 0.0001 -0.0000 -0.0001 -0.0000 0.0000 0.0000 -0.0000
-0.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 -0.0000
-0.0000 -0.0000