close all clear all clc T = 0.01; t = -2:T:2; x = triang(t); N = length(x); om = (-round((N-1)/2):round(N/2)-1) *2*pi/(N*T); X = fftshift(T*fft(x)).*exp(-1i*om*t(1)); Xref = sinc(om/(2*pi)).^2; figure subplot(2,1,1) plot(t,x) grid xlabel('t') ylabel('x(t)') title('signal') subplot(2,2,3) semilogy(om,abs(X),om,abs(Xref)) axis([0 max(om) ylim]) grid xlabel('\omega') ylabel('X(\omega)') legend('MatLab','analytical') title('Fourier transform') subplot(2,2,4) semilogy(om,abs(X-Xref)) axis([0 max(om) ylim]) grid xlabel('\omega') title('Difference') % printing figure in png format set(gcf,'PaperUnits','inches','PaperPosition',[0 0 6 4.5]) print -dpng homework1.png -r100 function s = triang(t) s = (1-abs(t)).*(abs(t)<1); end