Understanding the Fast Fourier Transform (快速傅里叶变换)

An introduction to the Fast Fourier Transform (FFT) — from the DFT definition to the Cooley–Tukey algorithm, with Python code and complexity analysis.

The FFT is the most important numerical algorithm of our lifetime.

— Gilbert Strang [1]

Introduction

The Discrete Fourier Transform (DFT)See Smith [2] for an excellent introduction aimed at engineers. is one of the most important tools in computational mathematics and signal processing. It converts a sequence of 𝑁 complex numbers into another sequence of 𝑁 complex numbers, revealing the frequency content of the original signal.

然而,直接计算 DFT 需要 𝑂(𝑁2) 次运算,对于大规模数据来说效率太低。DFT 的直接算法复杂度很高——对 𝑁=106 的信号需要约 10{12} 次运算。 1965年,Cooley 和 Tukey 发表了快速傅里叶变换(FFT)算法,将复杂度降低到 𝑂(𝑁log𝑁),使得频谱分析在实际工程中变得可行。FFT 是信号处理领域的革命性突破,被誉为“20世纪最重要的算法之一”。

You can also use a numbered note: This note has a superscript number marker in the text and margin.

This article walks through the mathematical foundation of the DFT, derives the radix-2 Cooley–Tukey FFT algorithm, and provides a Python implementation.

The Discrete Fourier Transform

Formally, we write 𝜔𝑁=𝑒−2𝜋𝑖/𝑁 for the primitive 𝑁-th root of unity, so the transform becomes:

𝑋𝑘=∑𝑛=0𝑁−1𝑥𝑛𝜔𝑁𝑘𝑛

(1)

The inverse DFT recovers the original sequence, as shown in Equation 2:

𝑥𝑛=1𝑁∑𝑘=0𝑁−1𝑋𝑘𝜔𝑁−𝑘𝑛

(2)

Key Properties

The DFT satisfies several important properties:

A Visual Intuition

Below is a margin figure showing the magnitude spectrum of a simple signal:

As Figure 1 shows, the FFT clearly separates the two frequency components.

The Cooley–Tukey FFT Algorithm

The key insight of the FFT is to exploit the symmetry and periodicity of 𝜔𝑁. By splitting the DFT into even and odd indices:

𝑋𝑘=∑𝑚=0𝑁/2−1𝑥2𝑚𝜔𝑁/2𝑚𝑘⏟𝐸𝑘+𝜔𝑁𝑘∑𝑚=0𝑁/2−1𝑥2𝑚+1𝜔𝑁/2𝑚𝑘⏟𝑂𝑘

(4)

This gives us the butterfly operation, which is the computational core of the FFT:

𝑋𝑘=𝐸𝑘+𝜔𝑁𝑘𝑂𝑘𝑋𝑘+𝑁/2=𝐸𝑘−𝜔𝑁𝑘𝑂𝑘

(5)

Figure 2 visualizes this butterfly structure — each pair of inputs (𝐸𝑘,𝑂𝑘) produces two outputs via addition and subtraction of the twiddle factor 𝜔𝑁𝑘:

Since 𝐸𝑘 and 𝑂𝑘 are periodic with period 𝑁/2, we only need to compute them for 𝑘=0,1,…,𝑁/2−1.

通过递归地应用这一分解,我们可以将 𝑁 点 DFT 的计算分解为 log2𝑁 层蝶形运算,每层包含 𝑁/2 次蝶形操作。

Complexity Analysis

Table 1: Comparison of DFT and FFT computational complexity.

For a concrete example, consider 𝑁=220≈106:

Python Implementation

Below is a recursive radix-2 FFT implementation. Note the elegant correspondence to the mathematical derivation above.

import numpy as np

def fft(x):
    """Compute the FFT of sequence x (length must be a power of 2)."""
    N = len(x)
    if N == 1:
        return x

    # Split into even and odd indices
    even = fft(x[0::2])
    odd  = fft(x[1::2])

    # Twiddle factors: ω_N^k for k = 0, ..., N/2 - 1
    T = np.exp(-2j * np.pi * np.arange(N // 2) / N)

    # Butterfly: combine E_k and O_k
    return np.concatenate([
        even + T * odd,   # X_k       = E_k + ω^k · O_k
        even - T * odd    # X_{k+N/2} = E_k - ω^k · O_k
    ])

# Verify against NumPy's FFT
if __name__ == "__main__":
    x = np.random.random(1024)
    assert np.allclose(fft(x), np.fft.fft(x))
    print("FFT implementation verified!")

Performance note: this recursive version is clear but not optimal. Production FFT libraries (like FFTW [3]) use iterative approaches with carefully tuned memory access patterns, achieving near-peak hardware performance.

What the FFT Reveals

Figure 3 shows a typical FFT output: a time-domain signal containing two sine waves (50 Hz and 120 Hz) is transformed into a frequency-domain representation with clear peaks at those exact frequencies.

Figure 3: FFT spectrum of a two-tone signal. The peaks at 50 Hz and 120 Hz correspond to the two frequency components in the original signal.

Applications

Signal processing. The most common application — spectral analysis, filtering, and compression (MP3, JPEG, etc.) all rely on the FFT.

The FFT reduced the operation count for an 𝑁-point transform from 𝑁2 to 𝑁log𝑁. For 𝑁=106, that’s a factor of nearly 100,000. This single algorithm change made real-time digital signal processing possible.
— Press et al. [4]

Other important applications include:

  1. Polynomial multiplication: multiplying two degree-𝑛 polynomials in 𝑂(𝑛log𝑛) instead of 𝑂(𝑛2)
  2. Large integer multiplication: the Schönhage–Strassen algorithm uses FFT to multiply 𝑛-digit integers in 𝑂(𝑛log𝑛loglog𝑛)
  3. Partial differential equations: 谱方法利用 FFT 在频域中高效求解偏微分方程,在流体力学和量子力学模拟中广泛使用
  4. Convolution: fast computation of convolutions via the convolution theorem, used in deep learning (CNNs)

FFT in the Real World

A wide figure showing a more detailed visualization:

Figure 4: A time-domain signal containing multiple frequency components. The FFT decomposes this into its constituent frequencies.

As Figure 4 demonstrates, even a visually complex signal is just a sum of simple sinusoids — the FFT tells us exactly which ones.

Conclusion

The FFT is one of the most beautiful and practical algorithms in all of computational mathematics. It reduces the complexity of the DFT from 𝑂(𝑁2) to 𝑂(𝑁log𝑁), making large-scale spectral analysis feasible.

The central idea — divide and conquer via the symmetry of roots of unity — is both mathematically elegant and practically powerful. Understanding the FFT provides deep insight into the interplay between the time domain and the frequency domain, a duality that lies at the heart of much of applied mathematics.

Bibliography

  • [1] G. Strang, Introduction to Applied Mathematics. Wellesley-Cambridge Press, 1994.
  • [2] S. W. Smith, The Scientist and Engineer's Guide to Digital Signal Processing. California Technical Publishing, 1997. [Online]. Available: https://www.dspguide.com/
  • [3] M. Frigo and S. G. Johnson, “The Design and Implementation of FFTW3,” Proceedings of the IEEE, vol. 93, no. 2, pp. 216–231, 2005.
  • [4] W. H. Press, S. A. Teukolsky, W. T. Vetterling, and B. P. Flannery, Numerical Recipes: The Art of Scientific Computing, 3rd ed. Cambridge University Press, 2007.