To plot the FFT of a vector in Matlab, you can follow these steps:
x = sin(2*pi*1000*[0:1/44100:1]);
where 1/44100
is the sampling frequency, and 2*pi*1000
is the frequency of the sine wave.y = fft(x);
. Note that this computes the complex Fourier coefficients of the input vector.ysingle = y(1:length(x)/2+1);
.freq = 0:1/length(x):44100/2;
.plot(freq, abs(ysingle));
. Note that taking the absolute value of the Fourier coefficients gives the amplitude, and not the phase information.Here is the final code:
main.m248 chars15 lines
gistlibby LogSnag