# 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 ${\displaystyle f(x)}$ which is defined on the interval ${\displaystyle a\leq x\leq b}$. Due to memory limitations, a computer can only store values at a finite number of sample points, i.e. ${\displaystyle a\leq x_{0}. For our purposes these points will be equally spaced, for example ${\displaystyle x_{1}-x_{0}=x_{3}-x_{2}}$, and so we can write

${\displaystyle x_{j}=a+jh,\qquad j=0,1,2,...,n}$

where ${\displaystyle x_{j}}$ are the sample points, ${\displaystyle n}$ is the number of sample points and

${\displaystyle h={\frac {b-a}{n}}.}$

It is convenient to use the standard interval, for which ${\displaystyle 0\leq x\leq 2\pi }$. Rewriting ${\displaystyle x}$ in terms of standard interval yields

${\displaystyle 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 ${\displaystyle x_{n}=2\pi }$ is omitted; periodicity implies that the value of the function at ${\displaystyle 2\pi }$ is the same as the value of the function at ${\displaystyle 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 ${\displaystyle f(x)}$ at the sample points as a finite dimensional vector

${\displaystyle {f}=(f_{0},f_{1},...,f_{n-1})^{T}=(f(x_{0}),f(x_{1}),...,f(x_{n-1}))}$

where

${\displaystyle f_{j}=f(x_{j})=f\left({\frac {2j\pi }{n}}\right).}$

The DFT decomposes the sampled function ${\displaystyle f(x)}$ into a linear combination of complex exponentials, ${\displaystyle \exp(ikx)}$ where ${\displaystyle k}$ is an index. Since

${\displaystyle \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 ${\displaystyle n}$ points, the highest frequency of oscillation that can be resolved will have ${\displaystyle n}$ oscillations. Any frequencies higher than ${\displaystyle n}$ in the original function are not adequately resolved and cause an aliasing error (see, for example, Boyd[1] or Uecker[2] 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 ${\displaystyle f(x)}$ can be approximated by an interpolating trigonometric polynomial ${\displaystyle p(x)}$ so that

${\displaystyle 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 ${\displaystyle \approx }$ symbol means that ${\displaystyle f(x)}$ and ${\displaystyle p(x)}$ agree on each sample point, i.e. ${\displaystyle f(x_{j})=p(x_{j})}$ for each ${\displaystyle j=0,1,...n-1}$, but the interpolated polynomial ${\displaystyle p(x)}$ is only an approximation of the true solution ${\displaystyle f(x)}$ away from the sample points.. The ${\displaystyle c_{n}}$ are called discrete Fourier coefficients and are what we will be looking to solve for. ${\displaystyle p(x)}$ represents the values of interpolating trigonometric polynomial of degree ${\displaystyle \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

${\displaystyle \omega _{k}=(e^{ikx_{0}},e^{ikx_{1}},e^{ikx_{2}},...,e^{ikx_{n}})^{T}}$

${\displaystyle =(1,e^{2k\pi i/n},e^{4k\pi i/n},...,e^{2(n-1)k\pi i/n})^{T},}$

where ${\displaystyle k=0,1,...,n-1}$. The interpolation conditions, ${\displaystyle f(x_{j})=p(x_{j})}$, can also be rewritten in vectorial form

${\displaystyle f=c_{0}{\omega _{0}}+c_{1}{\omega _{1}}+...+c_{n-1}{\omega _{n-1}}.}$

( 1)

Here ${\displaystyle f}$ is a vector evaluated at the sample points, which is decomposed into vectors ${\displaystyle {\omega }_{k}}$, much as a vector in three dimensional space can be decomposed into the components in the ${\displaystyle x}$, ${\displaystyle y}$ and ${\displaystyle z}$ directions. The discrete Fourier transform allows us to compute the coefficients ${\displaystyle 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, ${\displaystyle {\omega _{0}},...,{\omega _{n-1}}}$, than it is to work with the original function. In order to solve for ${\displaystyle c_{k}}$, we use the orthonormality of the basis elements ${\displaystyle {\omega _{0}},...,{\omega _{n-1}}}$. We now explain how this is done (For a more detailed explanation see Olver and Shakiban[3].).

Define ${\displaystyle \xi _{n}=e^{2\pi i/n}}$. We observe that

${\displaystyle \left(\xi _{n}\right)^{n}=\exp \left({\frac {2\pi in}{n}}\right)=\cos(2\pi )+i\sin(2\pi )=1}$

For this reason ${\displaystyle \xi _{n}}$ is known as the primitive ${\displaystyle n^{\text{th}}}$ root of unity. Note also that for ${\displaystyle 0\leq k, we have that ${\displaystyle (\xi _{n}^{k})^{n}=1}$, so all other roots of unity when taken to the power ${\displaystyle n}$ can be obtained from the primitive ${\displaystyle n^{\text{th}}}$ root of unity. We will use this to perform the DFT algorithm to calculate the coefficients ${\displaystyle c_{0},...,c_{k-1}}$ in eq. 1 . The main idea behind the DFT algorithm is to use orthogonality of the vectors ${\displaystyle \omega _{k}}$. To show the orthogonality between the vectors ${\displaystyle \omega _{k}}$ and ${\displaystyle \omega _{l}}$, we let ${\displaystyle \omega _{l}^{*}}$ denote the complex conjugate of ${\displaystyle \omega _{l}}$, and then take the inner product of ${\displaystyle \omega _{k}}$ and ${\displaystyle \omega _{l}}$ and find that

${\displaystyle <\omega _{k},\omega _{l}>}$

${\displaystyle ={\frac {1}{n}}\sum _{m=0}^{n-1}\exp \left({\frac {2\pi ikm}{n}}\right)\left[\exp({\frac {2\pi ilm}{n}})\right]^{*}}$

${\displaystyle ={\frac {1}{n}}\sum _{m=0}^{n-1}\exp \left({\frac {2\pi i(k-l)m}{n}}\right)}$

${\displaystyle ={\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)}$

${\displaystyle =1}$ if ${\displaystyle k=l}$ and ${\displaystyle 0}$ otherwise.

To deduce the last part, if ${\displaystyle k=l}$ then ${\displaystyle \exp(0)=1}$, and if ${\displaystyle 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

${\displaystyle 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, ${\displaystyle c_{0},...,c_{n-1}}$ using the DFT from the definition can be very slow for large values of ${\displaystyle n}$. Computing the Fourier coefficients ${\displaystyle c_{0},...c_{n-1}}$ requires ${\displaystyle n^{2}-n}$ complex multiplications and ${\displaystyle n^{2}-n}$ complex additions. In 1960, Cooley and Tukey[4] 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 ${\displaystyle O(n\log n)}$. For large values of ${\displaystyle 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[5] 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.

## 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.

http://en.wikipedia.org/wiki/Fast_Fourier_transform