The Cooley–Tukey algorithm, named after J. W. Cooley and John Tukey, is the most common fast Fourier transform (FFT) algorithm. It re-expresses the discrete Fourier transform (DFT) of an arbitrary composite size
N=N1N2
Because the Cooley–Tukey algorithm breaks the DFT into smaller DFTs, it can be combined arbitrarily with any other algorithm for the DFT. For example, Rader's or Bluestein's algorithm can be used to handle large prime factors that cannot be decomposed by Cooley–Tukey, or the prime-factor algorithm can be exploited for greater efficiency in separating out relatively prime factors.
The algorithm, along with its recursive application, was invented by Carl Friedrich Gauss. Cooley and Tukey independently rediscovered and popularized it 160 years later.
This algorithm, including its recursive application, was invented around 1805 by Carl Friedrich Gauss, who used it to interpolate the trajectories of the asteroids Pallas and Juno, but his work was not widely recognized (being published only posthumously and in Neo-Latin).[1] [2] Gauss did not analyze the asymptotic computational time, however. Various limited forms were also rediscovered several times throughout the 19th and early 20th centuries.[2] FFTs became popular after James Cooley of IBM and John Tukey of Princeton published a paper in 1965 reinventing[2] the algorithm and describing how to perform it conveniently on a computer.[3]
Tukey reportedly came up with the idea during a meeting of President Kennedy's Science Advisory Committee discussing ways to detect nuclear-weapon tests in the Soviet Union by employing seismometers located outside the country. These sensors would generate seismological time series. However, analysis of this data would require fast algorithms for computing DFTs due to the number of sensors and length of time. This task was critical for the ratification of the proposed nuclear test ban so that any violations could be detected without need to visit Soviet facilities.[4] [5] Another participant at that meeting, Richard Garwin of IBM, recognized the potential of the method and put Tukey in touch with Cooley. However, Garwin made sure that Cooley did not know the original purpose. Instead, Cooley was told that this was needed to determine periodicities of the spin orientations in a 3-D crystal of helium-3. Cooley and Tukey subsequently published their joint paper, and wide adoption quickly followed due to the simultaneous development of Analog-to-digital converters capable of sampling at rates up to 300 kHz.
The fact that Gauss had described the same algorithm (albeit without analyzing its asymptotic cost) was not realized until several years after Cooley and Tukey's 1965 paper.[2] Their paper cited as inspiration only the work by I. J. Good on what is now called the prime-factor FFT algorithm (PFA);[3] although Good's algorithm was initially thought to be equivalent to the Cooley–Tukey algorithm, it was quickly realized that PFA is a quite different algorithm (working only for sizes that have relatively prime factors and relying on the Chinese remainder theorem, unlike the support for any composite size in Cooley–Tukey).[6]
A radix-2 decimation-in-time (DIT) FFT is the simplest and most common form of the Cooley–Tukey algorithm, although highly optimized Cooley–Tukey implementations typically use other forms of the algorithm as described below. Radix-2 DIT divides a DFT of size N into two interleaved DFTs (hence the name "radix-2") of size N/2 with each recursive stage.
The discrete Fourier transform (DFT) is defined by the formula:
Xk=
N-1 | |
\sum | |
n=0 |
xn
| |||||
e |
,
k
N-1
Radix-2 DIT first computes the DFTs of the even-indexed inputs
(x2m=x0,x2,\ldots,xN-2)
(x2m+1=x1,x3,\ldots,xN-1)
The radix-2 DIT algorithm rearranges the DFT of the function
xn
n={2m}
n={2m+1}
\begin{matrix}Xk&= &\sum
N/2-1 | |
\limits | |
m=0 |
x2m
| |||||
e |
+\sum
N/2-1 | |
\limits | |
m=0 |
x2m+1
| |||||
e |
\end{matrix}
One can factor a common multiplier
| |||||
e |
x2m
x2m+1
xn
x2m
Ek
x2m
Ok
\begin{matrix}Xk=\underbrace{\sum
N/2-1 | |
\limits | |
m=0 |
x2m
| |||||
e |
Note that the equalities hold for
k=0,...,N-1
Ek
Ok
k=0,..., | N2-1 |
X | ||||
|
Ek
Ok
\begin{align}
X | ||||||
|
&=\sum
N/2-1 | |
\limits | |
m=0 |
x2m
| ||||||||
e |
+
| ||||||||
e |
\sum
N/2-1 | |
\limits | |
m=0 |
x2m+1
| ||||||||
e |
\\ &=\sum
N/2-1 | |
\limits | |
m=0 |
x2m
| |||||
e |
e-2\pi+
| |||||
e |
e-\pi\sum
N/2-1 | |
\limits | |
m=0 |
x2m+1
| |||||
e |
e-2\pi\\ &=\sum
N/2-1 | |
\limits | |
m=0 |
x2m
| |||||
e |
-
| |||||
e |
\sum
N/2-1 | |
\limits | |
m=0 |
x2m+1
| |||||
e |
\\ &=Ek-
| |||||
e |
Ok \end{align}
We can rewrite
Xk
X | ||||
|
\begin{matrix} Xk&= &Ek+
| |||||
e |
This result, expressing the DFT of length N recursively in terms of two DFTs of size N/2, is the core of the radix-2 DIT fast Fourier transform. The algorithm gains its speed by re-using the results of intermediate computations to compute multiple DFT outputs. Note that final outputs are obtained by a +/− combination of
Ek
Ok\exp(-2\piik/N)
This process is an example of the general technique of divide and conquer algorithms; in many conventional implementations, however, the explicit recursion is avoided, and instead one traverses the computational tree in breadth-first fashion.
The above re-expression of a size-N DFT as two size-N/2 DFTs is sometimes called the Danielson–Lanczos lemma, since the identity was noted by those two authors in 1942[7] (influenced by Runge's 1903 work[2]). They applied their lemma in a "backwards" recursive fashion, repeatedly doubling the DFT size until the transform spectrum converged (although they apparently didn't realize the linearithmic [i.e., order ''N'' log ''N''] asymptotic complexity they had achieved). The Danielson–Lanczos work predated widespread availability of mechanical or electronic computers and required manual calculation (possibly with mechanical aids such as adding machines); they reported a computation time of 140 minutes for a size-64 DFT operating on real inputs to 3–5 significant digits. Cooley and Tukey's 1965 paper reported a running time of 0.02 minutes for a size-2048 complex DFT on an IBM 7094 (probably in 36-bit single precision, ~8 digits).[3] Rescaling the time by the number of operations, this corresponds roughly to a speedup factor of around 800,000. (To put the time for the hand calculation in perspective, 140 minutes for size 64 corresponds to an average of at most 16 seconds per floating-point operation, around 20% of which are multiplications.)
In pseudocode, the below procedure could be written:
X0,...,N−1 ← ditfft2(x, N, s): DFT of (x0, xs, x2s, ..., x(N-1)s): if N = 1 then X0 ← x0 trivial size-1 DFT base case else X0,...,N/2−1 ← ditfft2(x, N/2, 2s) DFT of (x0, x2s, x4s, ..., x(N-2)s) XN/2,...,N−1 ← ditfft2(x+s, N/2, 2s) DFT of (xs, xs+2s, xs+4s, ..., x(N-1)s) for k = 0 to N/2−1 do combine DFTs of two halves into full DFT: p ← Xk q ← exp(−2πi/N k) Xk+N/2 Xk ← p + q Xk+N/2 ← p − q end for end if
Here, '''ditfft2'''
(x,N,1), computes X=DFT(x) out-of-place by a radix-2 DIT FFT, where N is an integer power of 2 and s=1 is the stride of the input x array. x+s denotes the array starting with xs.
(The results are in the correct order in X and no further bit-reversal permutation is required; the often-mentioned necessity of a separate bit-reversal stage only arises for certain in-place algorithms, as described below.)
High-performance FFT implementations make many modifications to the implementation of such an algorithm compared to this simple pseudocode. For example, one can use a larger base case than N=1 to amortize the overhead of recursion, the twiddle factors
\exp[-2\piik/N]
More generally, Cooley–Tukey algorithms recursively re-express a DFT of a composite size N = N1N2 as:[9]
Typically, either N1 or N2 is a small factor (not necessarily prime), called the radix (which can differ between stages of the recursion). If N1 is the radix, it is called a decimation in time (DIT) algorithm, whereas if N2 is the radix, it is decimation in frequency (DIF, also called the Sande–Tukey algorithm). The version presented above was a radix-2 DIT algorithm; in the final expression, the phase multiplying the odd transform is the twiddle factor, and the +/- combination (butterfly) of the even and odd transforms is a size-2 DFT. (The radix's small DFT is sometimes known as a butterfly, so-called because of the shape of the dataflow diagram for the radix-2 case.)
There are many other variations on the Cooley–Tukey algorithm. Mixed-radix implementations handle composite sizes with a variety of (typically small) factors in addition to two, usually (but not always) employing the O(N2) algorithm for the prime base cases of the recursion (it is also possible to employ an N log N algorithm for the prime base cases, such as Rader's or Bluestein's algorithm). Split radix merges radices 2 and 4, exploiting the fact that the first transform of radix 2 requires no twiddle factor, in order to achieve what was long the lowest known arithmetic operation count for power-of-two sizes,[9] although recent variations achieve an even lower count.[10] [11] (On present-day computers, performance is determined more by cache and CPU pipeline considerations than by strict operation counts; well-optimized FFT implementations often employ larger radices and/or hard-coded base-case transforms of significant size.).
Another way of looking at the Cooley–Tukey algorithm is that it re-expresses a size N one-dimensional DFT as an N1 by N2 two-dimensional DFT (plus twiddles), where the output matrix is transposed. The net result of all of these transpositions, for a radix-2 algorithm, corresponds to a bit reversal of the input (DIF) or output (DIT) indices. If, instead of using a small radix, one employs a radix of roughly and explicit input/output matrix transpositions, it is called a four-step FFT algorithm (or six-step, depending on the number of transpositions), initially proposed to improve memory locality,[12] [13] e.g. for cache optimization or out-of-core operation, and was later shown to be an optimal cache-oblivious algorithm.[14]
The general Cooley–Tukey factorization rewrites the indices k and n as
k=N2k1+k2
n=N1n2+n1
N1n2N2k1
X | |
N2k1+k2 |
=
N1-1 | |
\sum | |
n1=0 |
N2-1 | |
\sum | |
n2=0 |
x | |
N1n2+n1 |
| |||||
e |
=
N1-1 | |
\sum | |
n1=0 |
\left[
| |||||
e |
\right] \left(
N2-1 | |
\sum | |
n2=0 |
x | |
N1n2+n1 |
| |||||
e |
\right)
| |||||
e |
=
N1-1 | |
\sum | |
n1=0 |
\left(
N2-1 | |
\sum | |
n2=0 |
x | |
N1n2+n1 |
| |||||
e |
\right)
| |||||
e |
where each inner sum is a DFT of size N2, each outer sum is a DFT of size N1, and the [...] bracketed term is the twiddle factor.
An arbitrary radix r (as well as mixed radices) can be employed, as was shown by both Cooley and Tukey[3] as well as Gauss (who gave examples of radix-3 and radix-6 steps).[2] Cooley and Tukey originally assumed that the radix butterfly required O(r2) work and hence reckoned the complexity for a radix r to be O(r2 N/r logrN) = O(N log2(N) r/log2r); from calculation of values of r/log2r for integer values of r from 2 to 12 the optimal radix is found to be 3 (the closest integer to e, which minimizes r/log2r).[3] [15] This analysis was erroneous, however: the radix-butterfly is also a DFT and can be performed via an FFT algorithm in O(r log r) operations, hence the radix r actually cancels in the complexity O(r log(r) N/r logrN), and the optimal r is determined by more complicated considerations. In practice, quite large r (32 or 64) are important in order to effectively exploit e.g. the large number of processor registers on modern processors, and even an unbounded radix r= also achieves O(N log N) complexity and has theoretical and practical advantages for large N as mentioned above.[12] [13] [14]
Although the abstract Cooley–Tukey factorization of the DFT, above, applies in some form to all implementations of the algorithm, much greater diversity exists in the techniques for ordering and accessing the data at each stage of the FFT. Of special interest is the problem of devising an in-place algorithm that overwrites its input with its output data using only O(1) auxiliary storage.
The best-known reordering technique involves explicit bit reversal for in-place radix-2 algorithms. Bit reversal is the permutation where the data at an index n, written in binary with digits b4b3b2b1b0 (e.g. 5 digits for N=32 inputs), is transferred to the index with reversed digits b0b1b2b3b4 . Consider the last stage of a radix-2 DIT algorithm like the one presented above, where the output is written in-place over the input: when
Ek
Ok
Ek
Ok
The logarithm (log) used in this algorithm is a base 2 logarithm.
The following is pseudocode for iterative radix-2 FFT algorithm implemented using bit-reversal permutation.[16] algorithm iterative-fft is input: Array a of n complex values where n is a power of 2. output: Array A the DFT of a. bit-reverse-copy(a, A) n ← a.length for s = 1 to log(n) do m ← 2s ωm ← exp(−2πi/m) for k = 0 to n-1 by m do ω ← 1 for j = 0 to m/2 – 1 do t ← ω A[''k'' + ''j'' + ''m''/2] u ← A[''k'' + ''j''] A[''k'' + ''j''] ← u + t A[''k'' + ''j'' + ''m''/2] ← u – t ω ← ω ωm return A
The bit-reverse-copy procedure can be implemented as follows. algorithm bit-reverse-copy(a,A) is input: Array a of n complex values where n is a power of 2. output: Array A of size n. n ← a.length for k = 0 to n – 1 do A[rev(k)] := a[k]
Alternatively, some applications (such as convolution) work equally well on bit-reversed data, so one can perform forward transforms, processing, and then inverse transforms all without bit reversal to produce final results in the natural order.
Many FFT users, however, prefer natural-order outputs, and a separate, explicit bit-reversal stage can have a non-negligible impact on the computation time, even though bit reversal can be done in O(N) time and has been the subject of much research.[17] [18] [19] Also, while the permutation is a bit reversal in the radix-2 case, it is more generally an arbitrary (mixed-base) digit reversal for the mixed-radix case, and the permutation algorithms become more complicated to implement. Moreover, it is desirable on many hardware architectures to re-order intermediate stages of the FFT algorithm so that they operate on consecutive (or at least more localized) data elements. To these ends, a number of alternative implementation schemes have been devised for the Cooley–Tukey algorithm that do not require separate bit reversal and/or involve additional permutations at intermediate stages.
The problem is greatly simplified if it is out-of-place: the output array is distinct from the input array or, equivalently, an equal-size auxiliary array is available. The algorithm[20] performs every stage of the FFT out-of-place, typically writing back and forth between two arrays, transposing one "digit" of the indices with each stage, and has been especially popular on SIMD architectures.[21] [22] Even greater potential SIMD advantages (more consecutive accesses) have been proposed for the Pease algorithm,[23] which also reorders out-of-place with each stage, but this method requires separate bit/digit reversal and O(N log N) storage. One can also directly apply the Cooley–Tukey factorization definition with explicit (depth-first) recursion and small radices, which produces natural-order out-of-place output with no separate permutation step (as in the pseudocode above) and can be argued to have cache-oblivious locality benefits on systems with hierarchical memory.[24] [25] [26]
A typical strategy for in-place algorithms without auxiliary storage and without separate digit-reversal passes involves small matrix transpositions (which swap individual pairs of digits) at intermediate stages, which can be combined with the radix butterflies to reduce the number of passes over the data.[25] [27] [28] [29] [30]