% solution of first midterm spring 2000
% bonus problem 7
%
% (a)
fs=1000;
T=1/fs;
N=5*10;%5 samples/period, 10 period
n=0:N-1;
t=n*T;
xa=cos(200*pi*t).*cos(1000*pi*t);
subplot(4,1,1);plot(t,xa);
title('signal sampled at fs=1000 Hz');
%
% (b)
%
Xa=fft(xa);
f=n*fs/N;
subplot(4,1,2);stem(f,abs(Xa)/N);
title('spectrum of the aliased signal');
%
% (c)
%
fs=1400;
T=1/fs;
N=7*10;%7 samples/period, 10 period
n=0:N-1;
t=n*T;
xc=cos(200*pi*t).*cos(1000*pi*t);
subplot(4,1,3);plot(t,xc);
title('signal sampled at fs=1400 Hz');
%
% (d)
%
Xc=fft(xc);
f=n*fs/N;
subplot(4,1,4);stem(f,abs(Xc)/N);
title('spectrum of the signal without aliasing error');
%
% If I like to see the signal plot in better resolution
%
XXa=[Xa(1:25)zeros(1,350) Xa(26:50)];
xxa=real(ifft(XXa));
figure;subplot(2,1,1);plot(xxa);
title('High resolution plot of the aliased signal (fs=1000Hz)');
XXc=[Xc(1:35)zeros(1,350) Xc(36:70)];
xxc=real(ifft(XXc));
subplot(2,1,2);plot(xxc);
title('High resolution plot of the signal without aliasing error (fs=1400Hz)');


