fft

Fast Fourier Transform.

f = fft(x)

f = fft(x,n)

f = fft(x,n,dim)

Inputs

x
The signal to be transformed into the frequency domain.
Type: double
Dimension: vector | matrix
n
Size of the fft.
Default: [] to use the input vector length.
Type: integer
Dimension: scalar
dim
The dimension on which to operate.
Default: first non-singleton dimension.
Type: integer
Dimension: scalar

Outputs

f
The frequency domain representation of x.

Example

fft of signal with two frequency components.

The example shows how to interpret spectral vector locations. The two-sided spectrum is shown. The DC response is at 0, and 50 is the Nyquist frequency. The positive frequency responses are displayed in the range [5,50], and the negative frequency responses are displayed in the range [55,95] by convention.

f1 = 25;                 % first frequency component
f2 = 40;                 % second frequency component
fs = 100;                % sampling frequency
ts = 1/fs;               % sampling time interval
n = 20;	           % number of samples
time = [0:ts:(n-1)*ts];  % time vector
signal = sin(2*pi*f1*time) + 0.8 * sin(2*pi*f2*time);
fq = freq(n,fs);         % frequency vector
ft = fft(signal) / n;    % normalized fft
plot(fq, abs(ft));

The frequency spacing is 5 Hz, so both components fall exactly on one of the frequency vector values.