% % fft_code.m % % This code computes the FFT of a signal comprised of 50 Hz % and 120 Hz components sampled at a rate of 1000 Hz (hence % dt = 1/1000). The vector Pyy contains the power spectrum % which provides a measure of the energy at the various frequencies. % dt = 1/1000; t = 0:dt:0.6; x = sin(2*pi*50*t) + sin(2*pi*120*t); y = x + 1*randn(size(t)); f = 1000*(0:255)/512; Y = fft(y,512); Pyy = Y.*conj(Y)/512; figure(1) plot(t,y) xlabel('Time (s)') ylabel('Amplitude (m)') figure(2) plot(f,Pyy(1:256)) xlabel('Frequency (Hz)') ylabel('Power spectrum') % % End of fft_code.m %