Subroutine Logo
Subroutine
← Back to Playground Physics & Math Intermediate

Interactive Fast Fourier Transform (FFT) & Signal Processing

An interactive mathematical exploration of 1D signal frequency decomposition, Cooley-Tukey O(N log N) FFT, and spectrum analysis.

Published: 2026-07-26
#Physics & Math#Fourier Transform#FFT#Signal Processing#Mathematics

The Fast Fourier Transform (FFT) is widely regarded as one of the most important algorithms of the 20th century. It decomposes time-domain wave signals (such as audio, radio frequencies, or image textures) into their constituent frequency spectrum components.

While naive Discrete Fourier Transform (DFT) requires O(N2)O(N^2) complex multiplications, the Cooley-Tukey FFT algorithm uses divide-and-conquer to compute the exact spectrum in O(NlogN)O(N \log N) time.


1. Summary & Key Takeaways

  • Continuous Fourier Transform: Translates continuous time-domain function f(t)f(t) to frequency spectrum f^(ξ)\hat{f}(\xi): f^(ξ)=f(t)e2πiξtdt\hat{f}(\xi) = \int_{-\infty}^{\infty} f(t) \, e^{-2\pi i \xi t} \, dt
  • Cooley-Tukey Radix-2 FFT: Splits a size-NN DFT into two sub-problems of size N/2N/2 (even and odd indexed samples): Xk=Ek+e2πiNkOkX_k = E_k + e^{-\frac{2\pi i}{N} k} O_k
  • Time Complexity Speedup: Reduces computational steps from O(N2)O(N^2) down to O(NlogN)O(N \log N), enabling real-time audio processing and digital communications (5G, Wi-Fi, MP3/JPEG compression).

2. Interactive FFT Signal Decomposition

Use the interactive spectrum analyzer below to adjust the frequencies of two combined sine waves, then view the resulting Time-Domain Waveform and Frequency-Domain FFT Spectrum!

Frequency Decomposition

Adjust the Sine Wave 1 and Sine Wave 2 sliders. Watch the lower FFT spectrum graph isolate the two distinct frequency magnitude peaks!

Fast Fourier Transform (FFT) SpectrumSignal Processing

Decompose composite time-domain wave signals into their exact frequency spectrum components!

Sine Wave 1 Frequency:440 Hz
Sine Wave 2 Frequency:880 Hz
Fast Fourier Transform Implementation Code
fft_analysis.py
Python (SciPy / NumPy)
# Fast Fourier Transform (FFT) in Python using NumPy & SciPy
import numpy as np
from scipy.fft import fft, fftfreq

# 1. Generate Composite Signal (440 Hz + 880 Hz Sine Waves)
sampling_rate = 8000 # 8 kHz
t = np.linspace(0, 1.0, sampling_rate, endpoint=False)
signal = np.sin(2 * np.pi * 440 * t) + 0.5 * np.sin(2 * np.pi * 880 * t)

# 2. Compute Fast Fourier Transform (Cooley-Tukey O(N log N))
fft_spectrum = fft(signal)
frequencies = fftfreq(len(signal), 1.0 / sampling_rate)

# 3. Extract Magnitude Spectrum Peaks
magnitudes = np.abs(fft_spectrum)[:len(signal)//2]

3. Mathematical Foundations: Cooley-Tukey Divide-and-Conquer

For discrete sequence x0,x1,,xN1x_0, x_1, \dots, x_{N-1}, the Discrete Fourier Transform is:

Xk=n=0N1xne2πiNnkX_k = \sum_{n=0}^{N-1} x_n \cdot e^{-\frac{2\pi i}{N} n k}

By separating into even (n=2mn = 2m) and odd (n=2m+1n = 2m + 1) terms:

Xk=m=0N/21x2me2πiN/2mk+e2πiNkm=0N/21x2m+1e2πiN/2mkX_k = \sum_{m=0}^{N/2-1} x_{2m} \cdot e^{-\frac{2\pi i}{N/2} m k} + e^{-\frac{2\pi i}{N} k} \sum_{m=0}^{N/2-1} x_{2m+1} \cdot e^{-\frac{2\pi i}{N/2} m k}

Xk=DFTN/2[xeven]k+WNkDFTN/2[xodd]kX_k = \text{DFT}_{N/2}[x_{\text{even}}]_k + W_N^k \cdot \text{DFT}_{N/2}[x_{\text{odd}}]_k

where WNk=e2πiNkW_N^k = e^{-\frac{2\pi i}{N} k} is the twiddle factor!


4. DFT vs. FFT Performance Comparison

PropertyNaive DFTCooley-Tukey FFT
Time ComplexityO(N2)O(N^2)O(NlogN)O(N \log N)
Steps for N=1,048,576N = 1,048,576 (2202^{20})1.1×1012\sim 1.1 \times 10^{12} operations2.0×107\sim 2.0 \times 10^{7} operations (50,000×50,000\times faster!)
Real-Time Feasibility❌ Too slow for live audio/telecom✅ Real-time 4K audio, 5G, & JPEG