This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Discrete Fourier Transforms

A common operation in analyzing various kinds of data is to find the discrete Fourier transform (or spectrum) of a list of values. The idea is typically to pick out components of the data with particular frequencies or ranges of frequencies.
Fourier[{u1,u2,...,un}]discrete Fourier transform
InverseFourier[{v1,v2,...,vn}]inverse discrete Fourier transform

Discrete Fourier transforms.

Here is some data, corresponding to a square pulse.
Click for copyable input
Here is the discrete Fourier transform of the data. It involves complex numbers.
Click for copyable input
Here is the inverse discrete Fourier transform.
Click for copyable input
Fourier works whether or not your list of data has a length which is a power of two.
Click for copyable input
This generates a list of 200 elements containing a periodic signal with random noise added.
Click for copyable input
The data looks fairly random if you plot it directly.
Click for copyable input
The discrete Fourier transform, however, shows a strong peak at 30+1, and a symmetric peak at 201-30, reflecting the frequency component of the original signal near 30/200.
Click for copyable input
In Mathematica, the discrete Fourier transform vs of a list ur of length n is by default defined to be . Notice that the zero frequency term appears at position 1 in the resulting list.
The inverse discrete Fourier transform ur of a list vs of length n is by default defined to be .
In different scientific and technical fields different conventions are often used for defining discrete Fourier transforms. The option FourierParameters allows you to choose any of these conventions you want.
common convention
discrete Fourier transform
inverse discrete Fourier transform
Mathematica default{0,1}ure2i(r-1)(s-1)/nvse-2i(r-1)(s-1)/n
data analysis{-1,1}ure2i(r-1)(s-1)/nvse-2i(r-1)(s-1)/n
signal processing{1,-1}ure-2i(r-1)(s-1)/nvse2i(r-1)(s-1)/n
general case{a,b}1/n(1-a)/2ure2ib(r-1)(s-1)/nvse-2ib(r-1)(s-1)/n

Typical settings for FourierParameters with various conventions.

two-dimensional discrete Fourier transform

Two-dimensional discrete Fourier transform.

Mathematica can find discrete Fourier transforms for data in any number of dimensions. In n dimensions, the data is specified by a list nested n levels deep. Two-dimensional discrete Fourier transforms are often used in image processing.
One issue with the usual discrete Fourier transform for real data is that the result is complex-valued. There are variants of real discrete Fourier transforms that have real results. Mathematica has commands for computing the discrete cosine transform and the discrete sine transform.
FourierDCT[list]Fourier discrete cosine transform of a list of real numbers
FourierDST[list]Fourier discrete sine transform of a list of real numbers

Discrete real Fourier transforms.

Here is some data, corresponding to a square pulse.
Click for copyable input
Here is the Fourier discrete cosine transform of the data.
Click for copyable input
Here is the Fourier discrete sine transform of the data.
Click for copyable input
There are four types each of Fourier discrete sine and cosine transforms typically in use, denoted by number or sometimes roman numeral as in "DCTII" for the discrete cosine transform of type 2.
FourierDCT[list,m]Fourier discrete cosine transform of type m
FourierDST[list,m]Fourier discrete sine transform of type m

Discrete real Fourier transforms of different types.

The default is type 2 for both FourierDCT and FourierDST.
Mathematica does not have InverseFourierDCT or InverseFourierDST functions because FourierDCT and FourierDST are their own inverses when used with the appropriate type. The inverse transforms for types 1, 2, 3, 4 are types 1, 3, 2, 4, respectively.
Check that the type 3 transform is the inverse of the type 2 transform.
Click for copyable input
The discrete real transforms are convenient to use for data or image compression.
Here is data that might be like a front or an edge.
Click for copyable input
The discrete cosine transform has most of the information in the first few modes.
Click for copyable input
Reconstruct the front from only the first 20 modes (1/10 of the original data size). The oscillations are a consequence of the truncation and are known to show up in image processing applications as well.
Click for copyable input