-
Notifications
You must be signed in to change notification settings - Fork 0
/
FIR.m
58 lines (58 loc) · 933 Bytes
/
FIR.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
N=7;
wc=1;
alpha=(N-1)/2;
n=0:1:N-1;
%Desired impulse response
for i=0:1:(N-1)
if(i~=alpha)
hd(i+1)=(sin(wc*(i-3))/(pi*(i-3)));
else
hd(i+1)=wc/pi;
end
end
subplot(5,1,1);
stem(n,hd);
xlabel('n');
ylabel('hd(n)');
title('Desired impulse response');
wHm = zeros(1,7);
%Hamming window
for j=0: 6
wHm(j+1)=0.54-(0.46*cos(2*pi*j/(N-1)));
end
subplot(5,1,2);
stem(n,wHm);
xlabel('n');
ylabel('whm(n)');
title('Hamming window');
%Impulse response
hn=hd.*wHm;
subplot(5,1,3);
stem(n,hn);
xlabel('n');
ylabel('h(n)');
title('Impulse response');
hw=[];
for w=0:(1/pi):pi
t=0;
temp=0;
const=hn(alpha+1);
for m=0:1:((N-3)/2)
temp=temp+(2.*hn(m+1).*cos(w.*(alpha-m)));
end
temp=temp+const;
hw=[hw, temp];
end
w=0:1/pi:pi;
%Magnitude response
subplot(5,1,4);
stem(w,hw);
xlabel('w');
ylabel('|H(w)|');
title('Magnitude response');
phase=-w*alpha;
subplot(5,1,5);
stem(w,phase);
xlabel('w');
ylabel('Phase');
title('Phase response');