y = fft(X)
y = fft(X,n)
y = fft(X)
is the discrete Fourier transform of vector X
, computed with a fast Fourier transform (FFT) algorithm. If X
is a matrix, fft(X)
is the FFT of each column of the matrix.
y = fft(X,n)
is the n
-point FFT. If the length of X
is less than n
, X
is padded with trailing zeros to length n
. If the length of X
is greater than n
, the sequence X
is truncated. When X
is a matrix, the length of the columns are adjusted in the same manner.
The fft
function employs a radix-2 fast Fourier transform algorithm if the length of the sequence is a power of two, and a slower mixed-radix algorithm if it is not.
X = fft(x)
and x = ifft(X)
implement the transform and inverse transform pair given for vectors of length N
by
where
is an n
-th root of unity.
It is difficult to identify the frequency components from looking at the original signal. Converting to the frequency domain, the discrete Fourier transform of the noisy signalt = 0:0.001:0.6;
x = sin(2*pi*50*t)+sin(2*pi*120*t);
y = x + 2*randn(size(t));
plot(y(1:50))
y
is found by taking the 512-point fast Fourier transform (FFT):
Y = fft(y,512);
The power spectral density, a measurement of the energy at various frequencies, is
Pyy = Y.* conj(Y) / 512;
The first 256 points (the other 256 points are symmetric) can be graphed on a meaningful frequency axis with
f = 1000*(0:255)/512;
plot(f,Pyy(1:256))
When the sequence length is not an exact power of two, an alternate algorithm finds the prime factors of the sequence length and computes the mixed-radix discrete Fourier transforms of the shorter sequences.
The time it takes to compute an FFT varies greatly depending upon the sequence length. The FFT of sequences whose lengths have many prime factors is computed quickly; the FFT of those that have few is not. Sequences whose lengths are prime numbers are reduced to the raw (and slow) discrete Fourier transform (DFT) algorithm. For this reason it is generally better to stay with power-of-two FFTs unless other circumstances dictate that this cannot be done. For example, on one machine a 4096-point real FFT takes 2.1 seconds and a complex FFT of the same length takes 3.7 seconds. The FFTs of neighboring sequences of length 4095 and 4097, however, take 7 seconds and 58 seconds, respectively.
fft2
, fftshift
, ifft
dftmtx
, filter
, freqz
, specplot
, and spectrum
in the Signal Processing Toolbox
(c) Copyright 1994 by The MathWorks, Inc.