FFT (Matlab)
FFT (Matlab)
There are many ways to define FFT in MATLAB in this tutorial is one of them:
Third step is to define the frequency vector and time vector (why?)
We define the time vector to represent our signal in the time domain and the
frequency vector because we will draw the signal’s frequency components
In the freq domain.
1
f=(1:N)*df; %begin the vector from 1 or 0 not important but make
%sure it the same size as time vector. We multiply by df as
%we multiply time vector by TS .This issue to be clear lets
%give example if FM=16Khz,df=FM/4=4khz,N=256,so if
%we don’t multiply by df vector frequency will be [1 2 3
% ….255] represent nothing of the freq. components of
%the signal. But if we multiply by df so frequency vector
%will be [1,2……..255]*4khz ,so the first point at 4khz
%the second point at 8khz etc….
Fourth step is to represent our Xt signal using time vector for example our signal
is sine wave with frequency FM.
Xt=sin(2*pi*FM*t);
The last step is to define FFT the function is fft(my signal)/no.of samples
We divide by N to be normalized fft.
Xf=fft(Xt)/N;
2
Example:
Code:
Results:
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6
-4
x 10
0.6
0.5
0.4
0.3
0.2
0.1
0
0 1000 2000 3000 4000 5000 6000