You are on page 1of 4

DESIGN OF FIR FILTER:

LOW PASS FILTER:


clc;
clear all;
wc=input('enter the value of cut off frequency');
N=input('enter the value of filter');
alpha=(N-1)/2;
eps=0.001;
%Rectangular Window
n=0:1:N-1;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
hn=hd
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on
%Hamming Window
n=0:1:N-1;
wh=0.54-0.46*cos((2*pi*n)/(N-1));
hn=hd.*wh
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'ms');
hold off;
hold on
%Hanning Window
n=0:1:N-1;
wh=0.5-0.5*cos((2*pi*n)/(N-1));
hn=hd.*wh
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'blue');
hold off;
hold on
%Blackman Window
n=0:1:N-1;
wh=0.42-0.5*cos((2*pi*n)/(N-1))+0.08*cos((4*pi*n)/(N-1));
hn=hd.*wh
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'green');
hold off;

OUTPUT FOR LOW PASS FILTER:


enter the value of cut off frequency1.6
enter the value of filter11
hn =
Columns 1 through 8
0.0630 0.0092 -0.1057 -0.0090 0.3185 0.5093 0.3178 -0.0095
Columns 9 through 11
-0.1056 0.0094 0.0630
hn =
Columns 1 through 8
0.0050 0.0015 -0.0421 -0.0062 0.2905 0.5093 0.2899 -0.0065
Columns 9 through 11
-0.0420 0.0016 0.0050
hn =
Columns 1 through 8
0 0.0009 -0.0365 -0.0059 0.2881 0.5093 0.2875 -0.0062
Columns 9 through 11
-0.0365 0.0009 0
hn =
Columns 1 through 8
-0.0000 0.0004 -0.0212 -0.0046 0.2705 0.5093 0.2699 -0.0049
Columns 9 through 11
-0.0212 0.0004 -0.0000

GRAPH FOR LPF:


DESIGN FOR HIGH PASS FILTER:
clc;
clear all;
wc=input('enter the value of cut off frequency');
N=input('enter the value of filter');
alpha=(N-1)/2;
eps=0.001;
%Rectangular Window
n=0:1:N-1;
hd=(sin(pi*(n-alpha+eps))-sin((n-alpha+eps)*wc))./(pi*(n-alpha+eps));
hn=hd
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on
%Hamming Window
n=0:1:N-1;
wh=0.54-0.46*cos((2*pi*n)/(N-1));
hn=hd.*wh
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'ms');
hold off;
hold on
%Hanning Window
n=0:1:N-1;
wh=0.5-0.5*cos((2*pi*n)/(N-1));
hn=hd.*wh
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'blue');
hold off;
hold on
%Blackman Window
n=0:1:N-1;
wh=0.42-0.5*cos((2*pi*n)/(N-1))-0.08*cos((4*pi*n)/(N-1));
hn=hd.*wh
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'green');
hold off;

OUTPUT FOR HIGH PASS FILTER:


enter the value of cut off frequency1.6
enter the value of filter11
hn =
Columns 1 through 8
-0.0628 -0.0094 0.1061 0.0085 -0.3175 0.4907 -0.3188 0.0100
Columns 9 through 11
0.1053 -0.0091 -0.0632
hn =
Columns 1 through 8
-0.0050 -0.0016 0.0422 0.0058 -0.2896 0.4907 -0.2908 0.0068
Columns 9 through 11
0.0419 -0.0015 -0.0051
hn =
Columns 1 through 8
0 -0.0009 0.0366 0.0056 -0.2872 0.4907 -0.2884 0.0066
Columns 9 through 11
0.0364 -0.0009 0
hn =
Columns 1 through 8
0.0100 0.0001 0.0350 0.0055 -0.2539 0.4122 -0.2550 0.0064
Columns 9 through 11
0.0348 0.0001 0.0101

GRAPH FOR HPF:

You might also like