This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / The Mathematica Book / Advanced Mathematics / Numerical Operations on Data  /

3.8.3 Fourier Transforms

A common operation in analyzing various kinds of data is to find the 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 transforms.

There are several conventions that can be used in defining Fourier transforms. In Mathematica, the Fourier transform of a list of length is taken to be . Notice that the zero frequency term appears at position 1 in the resulting list.
Note that the convention for defining the Fourier transform used in Mathematica is the one common in the physical sciences. In electrical engineering, the sign of the exponent is typically reversed, leading to a list of values which is reversed.
The Fourier transform takes you from a time series of data to the frequency components of the data. You can use the inverse Fourier transform to get back to the time series. The inverse Fourier transform of a list of length is defined to be


  • Here is some data, corresponding to a square pulse.
  • In[1]:= {-1, -1, -1, -1, 1, 1, 1, 1}


  • Here is the Fourier transform of the data. It involves complex numbers.
  • In[2]:= Fourier[%]


  • Here is the inverse Fourier transform.
  • In[3]:= InverseFourier[%]


  • After using Chop, this gives back exactly your original data.
  • In[4]:= Chop[%]


  • Fourier works whether or not your list of data has a length which is a power of two. It is, however, significantly more efficient when the length is a power of two.
  • In[5]:= Fourier[{1, -1, 1}]


  • This generates a length-256 list containing a periodic signal with random noise added.
  • In[6]:= data = Table[ N[Sin[30 2 Pi n/256] + (Random[ ] - 1/2)],
    {n, 256} ] ;

  • The data looks fairly random if you plot it directly.
  • In[7]:= ListPlot[ data, PlotJoined -> True ]

  • The Fourier transform, however, shows a strong peak at , and a symmetric peak at

    , reflecting the frequency 30 component of the original signal.
  • In[8]:= ListPlot[ Abs[Fourier[data]], PlotJoined -> True,
    PlotRange -> All ]

    A common and important application of Fourier transforms is doing convolutions. The basic idea is that integrals of the form can be evaluated simply by multiplying the Fourier transforms of and

    . Convolutions are used extensively, for example, in smoothing data.

  • This generates some "data".
  • In[9]:= data = Table[ N[BesselJ[1, 10 n/256] +
    0.2 (Random[ ] - 1/2)], {n, 256} ] ;

  • Here is a plot of the data.
  • In[10]:= ListPlot[data]

  • This generates a typical convolution kernel suitable for smoothing data.
  • In[11]:= kern = Table[Exp[-n^2/100.], {n, -128, 127}] ;

  • Here is a plot of the convolution kernel.
  • In[12]:= ListPlot[kern, PlotRange -> All]

  • This puts the convolution kernel in a form suitable for use in a discrete Fourier transform.
  • In[13]:= kern = RotateLeft[kern, 128]/Apply[Plus, kern] ;

  • The convolution is done by multiplying the Fourier transform of the data by the Fourier transform of the kernel, then taking the inverse Fourier transform of the result.
  • In[14]:= conv = InverseFourier[
    Sqrt[256] Fourier[data] Fourier[kern] ] ;

  • This plots the result. The Chop removes small imaginary parts that are generated in the Fourier transforms. The final plot is a smoothed version of the original data.
  • In[15]:= ListPlot[ Chop[conv] ]

    Two-dimensional Fourier transform.

    Mathematica can find Fourier transforms for data in any number of dimensions. In dimensions, the data is specified by a list nested

    levels deep. Two-dimensional Fourier transforms are often used in image processing.