close all clear all clc T = 0.01; N = 1000; t = (0:N-1)*T; x = ((t>0)+.5*(t==0)).*(2*exp(-t).*cos(2*pi*t)); X = fftshift(T*fft(x)); om = (-round((N-1)/2):round(N/2)-1) *2*pi/(N*T); Xref = 1./(1+1j*(om-2*pi))+1./(1+1j*(om+2*pi)); figure subplot(2,1,1) plot(t,x) grid xlabel('t') ylabel('x(t)') title('signal') subplot(2,1,2) semilogy(om,abs(X),om,abs(Xref)) grid xlabel('\omega') ylabel('X(\omega)') legend('MatLab','analytical') title('Fourier transform') % printing figure in png format set(gcf,'PaperUnits','inches','PaperPosition',[0 0 6 4.5]) print -dpng exercise1.png -r100