Fast Fourier Transform (FFT)
March 21, 2026 · View on GitHub
Overview & Motivation
Many problems in signal processing, communications, and control require knowing the frequency content of a signal. The Discrete Fourier Transform (DFT) answers this question exactly, but its direct computation costs multiplications — prohibitive for real-time embedded systems processing thousands of samples.
The Fast Fourier Transform is a family of algorithms that compute the DFT in operations by exploiting symmetry and periodicity of the complex exponential. This library implements the Radix-2 Cooley-Tukey variant, which recursively splits an -point DFT into two -point DFTs, requiring to be a power of two.
The core insight is that the DFT matrix has a recursive block structure: half of its entries are shared between the even-indexed and odd-indexed sub-problems, so most of the work can be reused rather than recomputed.
Mathematical Theory
Prerequisites
The Discrete Fourier Transform of a length- sequence is defined as:
The inverse DFT recovers the original sequence:
We define the twiddle factor , so .
Cooley-Tukey Decomposition
Split the sum into even-indexed and odd-indexed terms:
Because and are periodic with period :
This pair of equations is the butterfly operation: two outputs from two inputs and one twiddle-factor multiplication.
Bit-Reversal Permutation
The recursive decomposition reorders input by bit-reversing the sample indices. For in-place computation the input array is pre-permuted so that butterfly stages proceed sequentially from the smallest sub-problems to the full -point result.
Complexity Analysis
| Case | Time | Space | Notes |
|---|---|---|---|
| All | must be a power of 2 |
Why : There are butterfly stages, each performing butterfly operations (one complex multiply + two complex adds). Total: complex multiplications.
Twiddle factors are pre-computed and stored in a lookup table of size , so no trigonometric evaluations occur at runtime.
Step-by-Step Walkthrough
Input: ,
Step 1 — Bit-reversal permutation
| Index (binary) | Reversed | Value |
|---|---|---|
| 0 (00) | 0 (00) | 1 |
| 1 (01) | 2 (10) | 3 |
| 2 (10) | 1 (01) | 2 |
| 3 (11) | 3 (11) | 4 |
Reordered:
Step 2 — Stage 1 (size-2 butterflies), twiddle W_2^{0}
- Butterfly: outputs
- Butterfly: outputs
Result:
Step 3 — Stage 2 (size-4 butterfly), twiddles W_4^{0}, W_4^{1}
Output:
Verification: ✓
Pitfalls & Edge Cases
- Power-of-2 constraint. Non-power-of-2 inputs require zero-padding, which introduces interpolation artifacts in the frequency domain.
- Fixed-point overflow. Each butterfly stage can double the magnitude. For Q15/Q31 types, scale the input by $1/N$ before the transform or apply per-stage scaling.
- Spectral leakage. A finite-length DFT implicitly applies a rectangular window. Use a window function before the transform to reduce sidelobes.
- Aliasing. The Nyquist-Shannon theorem requires . Violating this folds high frequencies onto low frequencies irreversibly.
- Frequency resolution is . Increasing improves resolution at the cost of more memory and computation.
Variants & Generalizations
| Variant | Key Difference |
|---|---|
| Mixed-radix FFT | Supports arbitrary composite using radix-2, -3, -5, etc. stages |
| Split-radix FFT | Reduces multiplications by ~33 % compared to standard radix-2 |
| Real-valued FFT | Exploits conjugate symmetry of real inputs to halve work and memory |
| Bluestein's algorithm | Handles arbitrary by converting DFT to a circular convolution |
| Inverse FFT | Same structure; negate twiddle exponents and scale by $1/N$ |
Applications
- Spectral analysis — Identifying frequency components, harmonics, and noise floors in sensor data.
- Convolution and filtering — Multiplication in the frequency domain is equivalent to time-domain convolution; enables efficient FIR filtering.
- Power Spectral Density — Used internally by Welch's method for spectral estimation.
- Communication systems — OFDM modulation/demodulation is built directly on the FFT/IFFT pair.
- Vibration and fault diagnosis — Examining spectral peaks to detect mechanical anomalies.
- Data compression — Foundation for transforms (DCT, MDCT) used in JPEG, MP3, etc.
Connections to Other Algorithms
graph LR
FFT --> PSD["Power Spectral Density"]
FFT --> DCT["Discrete Cosine Transform"]
WIN["Window Functions"] --> FFT
FFT -.-> DK["Durand-Kerner (polynomial eval)"]
| Algorithm | Relationship |
|---|---|
| Power Spectral Density | Calls FFT internally on each windowed segment |
| Discrete Cosine Transform | Computed via FFT with input rearrangement and twiddle-factor post-processing |
| Window Functions | Applied before FFT to reduce spectral leakage |
References & Further Reading
- Cooley, J.W. and Tukey, J.W., "An algorithm for the machine calculation of complex Fourier series", Mathematics of Computation, 19(90), 1965.
- Oppenheim, A.V. and Schafer, R.W., Discrete-Time Signal Processing, 3rd ed., Pearson, 2009 — Chapters 8–9.
- Smith, S.W., The Scientist and Engineer's Guide to Digital Signal Processing, California Technical Publishing, 1997 — Chapters 8, 12.