Skip to main content

MATLAB Code for Fourier Transform of a Signal

 

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)))


 
Fig 1: FFT Plot of sin(2*pi*5*t) 
 

--------------------------------------------------------------------

z = freqz(x);

Shows the frequency components available in the signal

 

 
Fig 2: Frequency Components of a Signal sin(2*pi*5*t)

 

 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

[1] How to Plot FFT Plot of a Signal in MATLAB

People are good at skipping over material they already know!

View Related Topics to







Contact Us

Name

Email *

Message *