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.
In[1]:=
Click for copyable input
Out[1]=
Here is the discrete Fourier transform of the data. It involves complex numbers.
In[2]:=
Click for copyable input
Out[2]=
Here is the inverse discrete Fourier transform.
In[3]:=
Click for copyable input
Out[3]=
Fourier works whether or not your list of data has a length which is a power of two.
In[4]:=
Click for copyable input
Out[4]=
This generates a list of 200 elements containing a periodic signal with random noise added.
In[5]:=
Click for copyable input
The data looks fairly random if you plot it directly.
In[6]:=
Click for copyable input
Out[6]=
The discrete Fourier transform, however, shows a strong peak at , and a symmetric peak at , reflecting the frequency component of the original signal near .
In[7]:=
Click for copyable input
Out[7]=

In Mathematica, the discrete Fourier transform of a list of length 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 of a list of length 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
setting
discrete Fourier transform
inverse discrete Fourier transform
Mathematica default{0,1}
data analysis{-1,1}
signal processing{1,-1}
general case{a,b}

Typical settings for FourierParameters with various conventions.

Fourier[{{u11,u12,...},{u21,u22,...},...}]
two-dimensional discrete Fourier transform

Two-dimensional discrete Fourier transform.

Mathematica can find discrete Fourier transforms for data in any number of dimensions. In dimensions, the data is specified by a list nested 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.
In[8]:=
Click for copyable input
Out[8]=
Here is the Fourier discrete cosine transform of the data.
In[9]:=
Click for copyable input
Out[9]=
Here is the Fourier discrete sine transform of the data.
In[10]:=
Click for copyable input
Out[10]=

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 need or 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.
In[11]:=
Click for copyable input
Out[11]=

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.
In[12]:=
Click for copyable input
Out[12]=
The discrete cosine transform has most of the information in the first few modes.
In[13]:=
Click for copyable input
Out[13]=
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.
In[14]:=
Click for copyable input
Out[14]=
New to Mathematica? Find your learning path »
Have a question? Ask support »