# Parallel Spectral Numerical Methods/One-Dimensional Discrete Fourier Transforms

The discrete Fourier transform (DFT) takes a function sampled at a finite number of points and finds the coefficients for the linear combination of trigonometric polynomials that best approximates the function; the number of trigonometric polynomials used is equal to the number of sample points. Suppose we have a function $f(x)$ which is defined on the interval $a\leq x\leq b$. Due to memory limitations, a computer can only store values at a finite number of sample points, i.e. $a\leq x_{0}<x_{1}<...<x_{n}\leq b$. For our purposes these points will be equally spaced, for example $x_{1}-x_{0}=x_{3}-x_{2}$, and so we can write
$x_{j}=a+jh,\qquad j=0,1,2,...,n$
where $x_{j}$ are the sample points, $n$ is the number of sample points and
$h={\frac {b-a}{n}}.$
It is convenient to use the standard interval, for which $0\leq x\leq 2\pi$. Rewriting $x$ in terms of standard interval yields
$x_{0}=0,x_{1}={\frac {2\pi }{n}},x_{2}={\frac {4\pi }{n}},x_{j}={\frac {2j\pi }{n}},...,x_{n-1}={\frac {2(n-1)\pi }{n}}$
Notice how $x_{n}=2\pi$ is omitted; periodicity implies that the value of the function at $2\pi$ is the same as the value of the function at $0$, so it need not be included. We will introduce the DFT using the language of linear algebra. Much of this formalism carries over to continuous functions that are being approximated. It also makes it easier to understand the computer implementation of the algorithms. Many computer packages and programs are optimized to perform calculations through matrix operations, so the formalism is also useful when actually calculating transforms. We write the approximation to $f(x)$ at the sample points as a finite dimensional vector
${f}=(f_{0},f_{1},...,f_{n-1})^{T}=(f(x_{0}),f(x_{1}),...,f(x_{n-1}))$
where
$f_{j}=f(x_{j})=f\left({\frac {2j\pi }{n}}\right).$
The DFT decomposes the sampled function $f(x)$ into a linear combination of complex exponentials, $\exp(ikx)$ where $k$ is an index. Since
$\exp(ikx)=\cos(kx)+i\sin(kx),$
we also obtain an expansion in trigonometric functions, which may be more familiar from courses in calculus and differential equations. Since the function is sampled at $n$ points, the highest frequency of oscillation that can be resolved will have $n$ oscillations. Any frequencies higher than $n$ in the original function are not adequately resolved and cause an aliasing error (see, for example, Boyd or Uecker for more on this). This error can be reduced by sampling at a greater number of points so that the number of approximating exponentials functions can also be increased. There is a tradeoff between increasing the accuracy of the simulation and the time required for the simulation to complete. For many cases of scientific and practical interest, simulations with up to thousands of grid points can be computed relatively quickly. Below we explain how a function $f(x)$ can be approximated by an interpolating trigonometric polynomial $p(x)$ so that
$f(x)\approx p(x)=c_{0}+c_{1}e^{2ix}+c_{2}e^{2ix}+...+c_{n-1}e^{(n-1)ix}=\sum \limits _{k=0}^{n-1}c_{k}e^{ikx}$
The $\approx$ symbol means that $f(x)$ and $p(x)$ agree on each sample point, i.e. $f(x_{j})=p(x_{j})$ for each $j=0,1,...n-1$, but the interpolated polynomial $p(x)$ is only an approximation of the true solution $f(x)$ away from the sample points.. The $c_{n}$ are called discrete Fourier coefficients and are what we will be looking to solve for. $p(x)$ represents the values of interpolating trigonometric polynomial of degree $\leq n-1$, so if we have the values of these coefficients then we have a function we can use. Since we are working in a finite-dimensional vector space, a useful approach is to rewrite the discrete Fourier series as a vector. We let
$\omega _{k}=(e^{ikx_{0}},e^{ikx_{1}},e^{ikx_{2}},...,e^{ikx_{n}})^{T}$
$=(1,e^{2k\pi i/n},e^{4k\pi i/n},...,e^{2(n-1)k\pi i/n})^{T},$
where $k=0,1,...,n-1$. The interpolation conditions, $f(x_{j})=p(x_{j})$, can also be rewritten in vectorial form
    $f=c_{0}{\omega _{0}}+c_{1}{\omega _{1}}+...+c_{n-1}{\omega _{n-1}}.$         ( 1)
Here $f$ is a vector evaluated at the sample points, which is decomposed into vectors ${\omega }_{k}$, much as a vector in three dimensional space can be decomposed into the components in the $x$, $y$ and $z$ directions. The discrete Fourier transform allows us to compute the coefficients $c_{i}$ given the value of the function at the sample points. This may at first seem unmotivated, but in many applications, such as solving differential equations, it is easier to manipulate a linear combination of trigonometric polynomials, ${\omega _{0}},...,{\omega _{n-1}}$, than it is to work with the original function. In order to solve for $c_{k}$, we use the orthonormality of the basis elements ${\omega _{0}},...,{\omega _{n-1}}$. We now explain how this is done (For a more detailed explanation see Olver and Shakiban.).
Define $\xi _{n}=e^{2\pi i/n}$. We observe that
$\left(\xi _{n}\right)^{n}=\exp \left({\frac {2\pi in}{n}}\right)=\cos(2\pi )+i\sin(2\pi )=1$
For this reason $\xi _{n}$ is known as the primitive $n^{\text{th}}$ root of unity. Note also that for $0\leq k<n$, we have that $(\xi _{n}^{k})^{n}=1$, so all other roots of unity when taken to the power $n$ can be obtained from the primitive $n^{\text{th}}$ root of unity. We will use this to perform the DFT algorithm to calculate the coefficients $c_{0},...,c_{k-1}$ in eq. 1 . The main idea behind the DFT algorithm is to use orthogonality of the vectors $\omega _{k}$. To show the orthogonality between the vectors $\omega _{k}$ and $\omega _{l}$, we let $\omega _{l}^{*}$ denote the complex conjugate of $\omega _{l}$, and then take the inner product of $\omega _{k}$ and $\omega _{l}$ and find that
$<\omega _{k},\omega _{l}>$
$={\frac {1}{n}}\sum _{m=0}^{n-1}\exp \left({\frac {2\pi ikm}{n}}\right)\left[\exp({\frac {2\pi ilm}{n}})\right]^{*}$
$={\frac {1}{n}}\sum _{m=0}^{n-1}\exp \left({\frac {2\pi i(k-l)m}{n}}\right)$
$={\frac {1}{n}}\sum _{m=0}^{n-1}\cos \left({\frac {\pi (k-l)m}{n}}\right)+i\sin \left({\frac {\pi (k-l)m}{n}}\right)$
$=1$ if $k=l$ and $0$ otherwise.
To deduce the last part, if $k=l$ then $\exp(0)=1$, and if $k\neq l$, then we are sampling the sine and cosine functions at equally spaced points on over an integral number of wavelengths. Since these functions have equal magnitude positive and negative parts, they sum to zero, much as the integral of a sine or cosine over an integral number of wavelengths is zero. This implies that we can compute the Fourier coefficients in the discrete Fourier sum by taking inner products
$c_{k}=<{f},{\omega _{k}}>={\frac {1}{n}}\sum \limits _{m=0}^{n-1}\xi _{n}^{-mk}f_{j}.$
We note the close connection between the continuous and discrete settings, where an integral is replaced by a sum.

## Fast Fourier Transform

Computing the Fourier coefficients, $c_{0},...,c_{n-1}$ using the DFT from the definition can be very slow for large values of $n$. Computing the Fourier coefficients $c_{0},...c_{n-1}$ requires $n^{2}-n$ complex multiplications and $n^{2}-n$ complex additions. In 1960, Cooley and Tukey rediscovered a much more efficient way of computing DFT by developing an algorithm known as the Fast Fourier Transforms (FFT). The FFT cuts the number of arithmetic operations down to $O(n\log n)$. For large values of $n$, this can make a huge difference in computation time compared to the standard DFT. The reason why the FFT is so important is that it is heavily used spectral methods. The basic FFT algorithm used by Cooley and Tukey is well documented in many places, however, there are other implementations of the algorithm and the best version of the algorithm to use depends heavily on computer architecture. We therefore do not give further descriptions here.

## Notes

* ↑ Boyd (2001)
* ↑ Uecker (2009)
* ↑ Olver and Shakiban (2006)
* ↑ Cooley and Tukey (1965)
* ↑ Cooley and Tukey (1965)

## References

Boyd, J.P. (2001). Chebyshev and Fourier Spectral Methods. Dover.
Cooley, J.W.; Tukey, J.W. (1965). "An algorithm for the machine calculation of complex Fourier series". Mathematics of Computation. 19: 297–301.
Shakiban, C. (2006). Applied Linear Algebra. Prentice Hall.
Uecker, H. (2009). A short ad hoc introduction to spectral for parabolic PDE and the Navier-Stokes equations.
http://en.wikipedia.org/wiki/Fast_Fourier_transform