MATLAB Code to Find Fast Fourier Transform (FFT) of a Signal
y = fft(x, N);
where x is the input signal; y is the fourier transform of x and N is the number of FFT points
Example
>> x = [1, 2, 3, 4, 5, 6];
>> y = fft(x)
y =
21.0000 + 0.0000i -3.0000 + 5.1962i -3.0000 + 1.7321i -3.0000 + 0.0000i -3.0000 - 1.7321i -3.0000 - 5.1962i
-----------------------------------------------------------------------
>> fs = 10000;
>> t = 0:1/fs:(1-1/fs);
>> x = sin(2*pi*5*t);
>> y = fft(x);
>> freq = (-fs/2:fs/2-1);
>> figure()
>> plot(freq, abs(fftshift(y)))
--------------------------------------------------------------------
z = freqz(x);
Shows the frequency components available in the signal
The above code shows the frequency components and their corresponding phases in the signal. The above shows that the frequency components range from 0 to fs/2 Hz. Suppose you find a frequency peak at x = 0.4; the corresponding frequency will be 0.4*fs/2.
Read also about