Wednesday, November 18, 2009

Program to design Highpass FIR Filter using Hamming Windows

CODE:
clc
clear all
close all
sn = 0;
f=input('Enter The Sampling Frequency Where f = 0.8 or 0.6 or 0.4 or 0.2 := ');
n=input('Enter The Order Of Filter Where n = 16 or 32 or 64 or 128 or 256 := ');
disp(' For Hamming Window ');
for i=1:256
sn(i) = ((4*sin(2*pi*(f)*i)) + ((4/3)*sin(2*pi*3*(f)*i))+((4/5)*sin(2*pi*5*(f)*i))+((4/7)*sin(2*pi*7*(f)*i)));
end
subplot(3,2,1);
plot(sn);grid;
axis([0 150 -10 10]);

%Create a filter and use sn as input
wn = 0.2 * pi; %Cutoff frequency
win=hanning(n+1);
b = fir1(n,wn,'high',win);

%Creating FIR HP filter with hamming window
hs = filter(b,1,sn);

%Plot the output
subplot(3,2,2);
plot(hs);grid;
axis([0 150 -10 10]);
title('Output of the FIR HP filter');

%Plot the magnitude response of the filter
subplot(3,2,3);
[H,F] = freqz(b,1,256);





% returns the frequency response vector H and the corresponding angular frequency vector F
plot(F,20 * log10(abs(H)));grid;
xlabel('Normalized F (rad/sample)');
ylabel('Magnitude (dB)');
title('Magnitude Response');

%Plot the phase response of the filter
subplot(3,2,4);
plot(F,unwrap(angle(H))*180/pi); grid;
xlabel('Normalized F (rad/sample)');
ylabel('Phase (degrees)');
title('Phase Response');

%Plot the filter
subplot(3,2,5);
plot(b);grid;
xlabel('Filter using hamming window');
fvtool(b);

No comments:

Post a Comment