Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

function nn05(k)

clc;
clf;
close all;

% designing of LPF using Hamming window


% take cut off frequency wp as input
% h(n)= sin[wp(n-t)]/pi*(n-t) when n != t
% h(n)= wp/pi when n=t
f=input('Give cutoff frequency in hertz between 0 to 4kHz');
wp=pi*f/4000;
N = 1025;
t=(N-1)/2;
n=0:N-1;
h1=sin(wp*(n-t));
h2=(pi*(n-t));
h1((n-t)==0)=wp;
h2((n-t)==0)=pi;
h=h1./h2;
stem(n,h);
title('impulse response of filter');
xlabel('sampel number');
ylabel('Amplitude');

if k==1
w=ones(1,N);
figure(2);
stem(n,w);
xlabel('sampel number');
ylabel('Amplitude');
title('Rectangular Window');
elseif k==2
w=0.5-0.5*cos(2*pi*n/(N-1));
figure(2);
stem(n,w);
xlabel('sampel number');
ylabel('Amplitude');
title('Hanning Window');
elseif k==3
w = 0.54-0.46*(cos(2*pi*n/(N-1)));
figure(2);
stem(n,w);
xlabel('sampel number');
ylabel('Amplitude');
title('Hamming Window');
elseif k==4
w=0.42-0.5*cos(2*pi*n/(N-1))+0.08*cos(4*pi*n/(N-1));
figure(2);
stem(n,w);
xlabel('sampel number');
ylabel('Amplitude');
title('Blackman Window');
else disp('the number you have entered in not in the range');
end
y=h.*w;
figure(3);
stem(n,y);
title('impulse response of filter h(n)*w(n)');
xlabel('sampel number');
ylabel('Amplitude');
z=fftshift(abs(fft(y)));
f=-4000:(8000/1024):4000;
figure(4)
plot(f,z);
xlabel('frequency in hertz');
ylabel('Amplitude Spectrum');
title('Amplitude spectrum of FIR LPF');
end

You might also like