function fid hold off % Define the time domain nmax=10; n=2^nmax; tmax=20; dt=tmax/(n-1); t=[0:dt:tmax]; % Specify frequencies and amplitudes omega=[15 25 35 45]; amp=[1 2 3 4]; nt=length(t); nfreq=length(omega); tau=5; for i=1:nt time=t(i); s=0; for j=1:nfreq s=s+amp(j)*cos(omega(j)*time)*exp(-time/tau); end f(i)=s; end y=real(fft(f)); w=2*pi*[1:length(y)]/20; % Plot the original signal - "free induction decay" subplot(2,1,1) plot(t,f,'-k','linewidth',1) ylabel('$f(t)$','Interpreter','latex','fontsize',30) xlabel('$t$','Interpreter','latex','fontsize',30) axis([0 10 -8 8]) set(gca,'FontSize',26) set(gca,'Ytick',[-8:8:8],'linewidth',1.6) set(gca,'Xtick',[0:5:10],'linewidth',1.6) % Calculate the FFT y=real(fft(f)); % Plot the Fourier transform giving the original frequencies subplot(2,1,2) plot(w,y,'-k','linewidth',1.2) ylabel('$f(\omega)$','Interpreter','latex','fontsize',30) xlabel('$\omega$','Interpreter','latex','fontsize',30) axis([0 60 0 400]) set(gca,'FontSize',26) set(gca,'Ytick',[0:200:400],'linewidth',1.6) set(gca,'Xtick',[5:10:60],'linewidth',1.6) axis([1 60 0 400])