Waves & Fourier Analysis — Superposition, DFT, FFT Butterfly & Nyquist Theorem

Everything that vibrates — strings, air columns, quantum particles, circuits, signals — is described by the same mathematics. This post builds from simple harmonic motion to the Fast Fourier Transform, showing how any waveform decomposes into a sum of pure sinusoids.

1. Simple Harmonic Motion & Superposition

A mass on a spring satisfies Newton's second law with a restoring force F = −kx. The solution is a sinusoid: x(t) = A cos(ωt + φ) where ω = √(k/m). When two or more waves pass through the same medium simultaneously, their displacements add: constructive interference amplifies, destructive interference cancels.

2. The Discrete Fourier Transform

Given N samples x[n] of a signal, the DFT computes the spectrum X[k] — the amplitude and phase of each frequency component. Formally:

DFT Definition & Inverse

X[k] = Σ_{n=0}^{N-1} x[n] · e^{−j2πkn/N}   (analysis)
x[n] = (1/N) Σ_{k=0}^{N-1} X[k] · e^{+j2πkn/N}  (synthesis)

The twiddle factor W_N = e^{−j2π/N} is a primitive N-th root of unity.
X[k] is complex: X[k] = Re[k] + j·Im[k]
Magnitude |X[k]| gives spectral amplitude; arg(X[k]) gives phase.

Direct computation of all N output values costs O(N²) multiply-add operations — too slow for large N. The Fast Fourier Transform exploits the twiddle-factor symmetry to reduce this to O(N log N).

3. FFT Butterfly — O(N log N) via Divide & Conquer

The Cooley-Tukey radix-2 FFT splits an N-point DFT into two (N/2)-point DFTs — one over the even indices, one over the odd:

Cooley-Tukey Decimation-in-Time

X[k] = E[k] + W_N^k · O[k]   (k = 0 … N/2−1)
X[k + N/2] = E[k] − W_N^k · O[k]

where E[k] = DFT of even-indexed samples {x[0], x[2], …}
      O[k] = DFT of odd-indexed samples  {x[1], x[3], …}

Recurrence depth = log₂ N; work per level = N ops → O(N log₂ N) total.

// Iterative Cooley-Tukey FFT (in-place, N must be power of 2)
function fft(re, im) {          // re[], im[] are real and imaginary parts
  const N = re.length;
  // Bit-reversal permutation
  for (let i = 1, j = 0; i < N; i++) {
    let bit = N >> 1;
    for (; j & bit; bit >>= 1) j ^= bit;
    j ^= bit;
    if (i < j) { [re[i], re[j]] = [re[j], re[i]]; [im[i], im[j]] = [im[j], im[i]]; }
  }
  // Butterfly passes
  for (let len = 2; len <= N; len <<= 1) {
    const ang = -2 * Math.PI / len;
    const wRe = Math.cos(ang), wIm = Math.sin(ang);
    for (let i = 0; i < N; i += len) {
      let uRe = 1, uIm = 0;
      for (let j = 0; j < len / 2; j++) {
        const tRe = uRe * re[i+j+len/2] - uIm * im[i+j+len/2];
        const tIm = uRe * im[i+j+len/2] + uIm * re[i+j+len/2];
        re[i+j+len/2] = re[i+j] - tRe;  im[i+j+len/2] = im[i+j] - tIm;
        re[i+j] += tRe;                   im[i+j] += tIm;
        [uRe, uIm] = [uRe*wRe - uIm*wIm, uRe*wIm + uIm*wRe];
      }
    }
  }
}

4. Nyquist-Shannon Sampling Theorem

A bandlimited signal with maximum frequency f_max can be perfectly reconstructed from equally-spaced samples if and only if the sample rate f_s satisfies:

Nyquist Criterion

f_s ≥ 2 · f_max   (Nyquist rate)

Aliasing occurs when f_s < 2 · f_max — high-frequency content "folds back" and masquerades as a lower frequency in the spectrum.

Shannon reconstruction: x(t) = Σ_n x[n] · sinc(f_s · t − n)
Sinc interpolation is the ideal (brick-wall) low-pass filter.

5. Standing Waves & Resonance

When a travelling wave reflects from a fixed boundary, the incident and reflected waves superpose to form a standing wave — nodes where displacement is always zero, antinodes where it is maximum. For a string of length L fixed at both ends, the allowed resonant frequencies are: f_n = n · v / (2L), where n = 1, 2, 3, … and v is the wave speed. This harmonic series is the physical basis of all string instruments.

Algorithms at a Glance

SHM / Superposition Huygens wavefronts DFT Cooley-Tukey FFT Bit-reversal permutation Nyquist-Shannon Sinc interpolation Fourier series Gibbs phenomenon z-transform Bilinear Tustin Modal analysis

Why O(N log N) matters: For N = 1 048 576 (2²⁰) samples, the DFT requires ~10¹² operations, taking several minutes. The FFT reduces this to ~20 million — completing in milliseconds. This is why real-time audio processing, radar, and OFDM wireless communication (4G/5G) all rely on FFT hardware.