You are on page 1of 1

m=input('enter the order of filter');

t=(m-1)/2;
logi=[];
wc=input('enter the cutoff freq');
for i=1:1:m
if i==(t+1)
h(i)=1-(wc/pi);
continue;
end
n1=sin(pi*((i-1)-t));
n2=sin(wc*((i-1)-t));
h(i)=(n1-n2)/((pi*((i-1)-t)));
end
for e=1:1:m
d(e)=0.5-(0.5*cos(2*pi*(e-i)/(m-1)));
end
g=d.*h;
w=0:2:180;
lo=w*pi/180;
w1=length(w);
k=(g(t+1));
for j=1:1:w1
sum1=0;
for i=1:1:((m-1)/2);
sum1=sum1+(2*g(i)*cos((t-i+1)*lo(j)));
end
res(j)=k+sum1;
logi(j)=20*log(abs(res(j)));
end
lo=lo/pi;
plot(lo,logi,'k');
title('HPF using Hanning window')
xlabel('Frequency (rad/sec)');
ylabel('Gain (dB)');

You might also like