Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
1
Indexable
Never
clc
clear all
close all
 
check = input('Enter 1 for Hamming, 2 for Hanning & 3 for Rectangular: ');
passbnad_frequency = 1.5;
transition_width = 0.5;
stop_band = 8;
sampling_frequency = (passbnad_frequency + (transition_width/2))/stop_band;

wn = zeros(27,1);
H = zeros(27, 1);
Hd = zeros(27,1);
Hamming = zeros(54,1);
Hunning = zeros(45,1);
Rectangle = zeros(22,1); 

N1 = 3.3/(transition_width/stop_band);
N2 = 3.1/(transition_width/stop_band);

%Hamming start 
if check == 1
for n = 1:26
    Hd(n+1) = (sin(2*n*pi*sampling_frequency))/(pi*(n));
    wn(n+1) = 0.54 + 0.46*cos((2*pi*(n))/N1); 
    H(n+1) = Hd(n+1)*wn(n+1);
end

Hamming = flip(H);
for k = 27:53
   Hamming(k)=H(k-26);
end
for f=1:53
    fprintf('h(%d): %4e\n', f-1, Hamming(f));
end
end 
%Hamming end 

%Hunning start 
if check == 2
for n = 1:26
    Hd(n+1) = (sin(2*n*pi*sampling_frequency))/(pi*(n));
    wn(n+1) = 0.5 + 0.5*cos((2*pi*(n))/N2); 
    H(n+1) = Hd(n+1)*wn(n+1);
end

Hunning = flip(H);
for k = 27:44
   Hunning(k)=H(k-26);
end
for f=1:44
    fprintf('h(%d): %4e\n', f-1, Hunning(f));
end
end 

%Hunning end 

%Rectangle start 
if check == 3
for n = 1:10
    Hd(n+1) = (sin(2*n*pi*sampling_frequency))/(pi*(n));
    wn(n+1) = 1; 
    H(n+1) = Hd(n+1)*wn(n+1);
end

Rectangle = flip(H);
for k = 11:21
   Rectangle(k)=H(k-10);
end
for f=1:21
    fprintf('h(%d): %4e\n', f-1, Rectangle(f));
end
end
%Rectangel end