50 lines
816 B
Matlab
50 lines
816 B
Matlab
% value of a
|
|
a=0.9;
|
|
|
|
% signal x(n)
|
|
for n=0:200
|
|
x(n+1) = a^n;
|
|
end
|
|
figure(1)
|
|
n=0:1:200;
|
|
stem(n,x)
|
|
xlabel('n');
|
|
ylabel('x(n)');
|
|
|
|
% question part (e)
|
|
n=1;
|
|
d=[1 -a];
|
|
[h1,w]=freqz(n,d,256);
|
|
h1mag=abs(h1);
|
|
figure(2)
|
|
plot(w,h1mag,'b','linewidth',2)
|
|
xlabel('Frequency');
|
|
ylabel('Magnitude Response');
|
|
|
|
% partial dtft for k =3
|
|
[h2,w]=freqz(x(1:4),1,256);
|
|
h2mag=abs(h2);
|
|
hold
|
|
plot(w,h2mag,'r','linewidth',2)
|
|
|
|
% partial dtft for k =10
|
|
[h3,w]=freqz(x(1:11),1,256);
|
|
h3mag=abs(h3);
|
|
plot(w,h3mag,'m','linewidth',2)
|
|
|
|
% partial dtft for k =20
|
|
[h4,w]=freqz(x(1:21),1,256);
|
|
h4mag=abs(h4);
|
|
plot(w,h4mag,'k','linewidth',2)
|
|
|
|
% supremum coefficients of the error
|
|
for k=1:200
|
|
[hk,w]=freqz(x(1:k+1),1,256);
|
|
ek=abs(h1-hk);
|
|
coeff(k)=max(ek);
|
|
end
|
|
figure(3)
|
|
k=1:1:200;
|
|
stem(k,coeff)
|
|
|