Documentation Center

  • Trial Software
  • Product Updates


Fast Fourier transform


Y = fft(x)
Y = fft(X,n)
Y = fft(X,[],dim)
Y = fft(X,n,dim)


The functions Y = fft(x) and y = ifft(X) implement the transform and inverse transform pair given for vectors of length N by:


is an Nth root of unity.


Y = fft(x) returns the discrete Fourier transform (DFT) of vector x, computed with a fast Fourier transform (FFT) algorithm.

If the input X is a matrix, Y = fft(X) returns the Fourier transform of each column of the matrix.

If the input X is a multidimensional array, fft operates on the first nonsingleton dimension.

Y = fft(X,n) returns the n-point DFT. fft(X) is equivalent to fft(X, n) where n is the size of X in the first nonsingleton dimension. 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.




Fs = 1000;                    % Sampling frequency
T = 1/Fs;                     % Sample time
L = 1000;                     % Length of signal
% Sum of a 50 Hz sinusoid and a 120 Hz sinusoid
xlabel('time (milliseconds)')


Y = fft(y,NFFT)/L;

% Plot single-sided amplitude spectrum.
xlabel('Frequency (Hz)')


Data Type Support

fft supports inputs of data types double and single. If you call fft with the syntax y = fft(X, ...), the output y has the same data type as the input X.

More About

expand all


The FFT functions (fft, fft2, fftn, ifft, ifft2, ifftn) are based on a library called FFTW [3],[4]. To compute an N-point DFT when N is composite (that is, when N = N1N2), the FFTW library decomposes the problem using the Cooley-Tukey algorithm [1], which first computes N1 transforms of size N2, and then computes N2 transforms of size N1. The decomposition is applied recursively to both the N1- and N2-point DFTs until the problem can be solved using one of several machine-generated fixed-size "codelets." The codelets in turn use several algorithms in combination, including a variation of Cooley-Tukey [5], a prime factor algorithm [6], and a split-radix algorithm [2]. The particular factorization of N is chosen heuristically.

When N is a prime number, the FFTW library first decomposes an N-point problem into three (N – 1)-point problems using Rader's algorithm [7]. It then uses the Cooley-Tukey decomposition described above to compute the (N – 1)-point DFTs.

For most N, real-input DFTs require roughly half the computation time of complex-input DFTs. However, when N has large prime factors, there is little or no speed difference.


    Note   You might be able to increase the speed of fft using the utility function fftw, which controls the optimization of the algorithm used to compute an FFT of a particular size and dimension.


[1] Cooley, J. W. and J. W. Tukey, "An Algorithm for the Machine Computation of the Complex Fourier Series,"Mathematics of Computation, Vol. 19, April 1965, pp. 297-301.


[3] FFTW (


[5] Oppenheim, A. V. and R. W. Schafer, Discrete-Time Signal Processing, Prentice-Hall, 1989, p. 611.


[7] Rader, C. M., "Discrete Fourier Transforms when the Number of Data Samples Is Prime," Proceedings of the IEEE, Vol. 56, June 1968, pp. 1107-1108.

See Also

| | | | |

Was this topic helpful?