Skip to main content

From Convolution to FFT

Slide a convolution, inspect a spectrum, and step through butterflies to understand how FFT speeds up computation.

What you hear now is the sum of past echoes

Compare the pianist view (overlapping echoes), listener view (flipped & shifted response), and continuous slicing.

Convolution controls
Presets
Length of a Length of b
c2=∑i+j=2aibj=a0b2+a1b1+a2b0=2⋅0.3+3⋅0.6+1.5⋅1=3.71c_{2}=\sum_{i+j=2}a_ib_j=a_{0}b_{2}+a_{1}b_{1}+a_{2}b_{0}=2\cdot0.3+3\cdot0.6+1.5\cdot1=3.71
Beat 0 (a₀=2)Echo decay →0.56Beat 1 (a₁=3)Echo decay →1.65Beat 2 (a₂=1.5)Echo decay →1.5Total sound heardSum of all echoes2t=04.1t=13.71t=21.91t=30.78t=40.18t=5Listener at t=2: total 3.71
2a03a11.5a2Input a: strength per beat
1b00.6b10.3b20.1b3Response b: echo per step
Col j: response b10.60.30.1221.10.60.2331.70.80.41.51.50.80.40.2Row i
2c04.1c13.7c21.9c30.8c40.2c5

Bars are colored by source: color i is the echo from input i. The stacked pieces in the selected column match the highlighted diagonal in the table on the left.

A(x)B(x)=(2+3x+1.5x2)(1+0.55x+0.28x2+0.12x3)=2+4.1x+3.71x2+1.91x3+0.78x4+0.18x5A(x)B(x)=(2+3x+1.5x^{2})(1+0.55x+0.28x^{2}+0.12x^{3})=2+4.1x+3.71x^{2}+1.91x^{3}+0.78x^{4}+0.18x^{5}

Linear convolution has length 3+4−1=6. Set N to 6 or larger and cyclic convolution matches it exactly; below 6, tail terms wrap back to the start.

Two views of a polynomial: coefficients vs. point values

A degree < n polynomial is uniquely fixed by n distinct points; switching to roots of unity turns evaluation into DFT.

Point Values controls
nn
3 points fix a degree < 3 polynomial: 3+10x+8x2=C(x)3\text{ points fix a degree < }3\text{ polynomial: }3+10x+8x^{2}=C(x)
−404812−2−1.5−1−0.500.5

A=1+2xB=3+4xC=AB

xjx_jA(xj)A(x_j)B(xj)B(x_j)A(xj)B(xj)A(x_j)B(x_j)
−1.5−2−36
−0.5010
0.52510

In point-value form, multiplication multiplies two values per row (3 mults for 3 points). Since deg(C) = 2, 3 points already suffice; extra points simply confirm the same polynomial.

Interpolation stability: Vandermonde condition number κ2(V)\kappa_2(V)

Points nReal nodes herexj=0,1,…,n−1x_j=0,1,\ldots,n-1Roots of unity
21.62.61
35.613.91
421.91541
64245.77×10⁴1
895395.29×10⁷1
126.00×10⁶2.46×10¹⁴1
164.37×10⁹>10¹⁵1

Recovering coefficients solves Vc=yV\mathbf c=\mathbf y with Vjp=xj pV_{jp}=x_j^{\,p}. Perturbing point values amplifies the 2-norm relative coefficient error by at most κ2(V)\kappa_2(V) in the worst case.

At roots of unity, V is the Fourier matrix F (F∗F=N IF^*F=N\,I), so F/NF/\sqrt N is unitary and κ2(F)=1\kappa_2(F)=1: the linear solve itself adds zero amplification (though floating-point rounding still occurs). For the current 3 real nodes, estimated κ₂ ≈ 5.6.

Multiplying by a complex number rotates and scales the plane

Moduli multiply and angles add: drag z and w or press z ← zw repeatedly.

Complex Mult controls
Set w to
∣z∣ ∣w∣=1.58×1.17=1.84=∣zw∣,arg⁡z+arg⁡w=18.4∘+59∘≡77.5∘|z|\,|w|=1.58\times1.17=1.84=|zw|,\quad \arg z+\arg w=18.4^\circ+59^\circ\equiv77.5^\circ
1izwzw

z=1.5+0.5iz=1.5+0.5i

w=0.6+iw=0.6+i

zw=0.4+1.8izw=0.4+1.8i

The faint unit square and letter F are the originals; the solid outline shows them multiplied by z. The whole plane rotates and scales uniformly without shearing.

Why the exponential series winds into a circle

Each term multiplies the previous by iθ/(n+1), turning 90° while factorials eventually shrink the spiral onto the unit circle.

Euler's Formula controls
θ=π,∑n=05(iθ)nn!=0.124+0.524i,∣error∣=1.2401\theta=\pi,\quad \sum_{n=0}^{5}\frac{(i\theta)^n}{n!}=0.124+0.524i,\quad |\text{error}|=1.2401
eiθ
  1. (iθ)00!\frac{(i\theta)^{0}}{0!}Real axis +1, len 1
  2. (iθ)11!\frac{(i\theta)^{1}}{1!}Imag axis +i, len 3.142
  3. (iθ)22!\frac{(i\theta)^{2}}{2!}Real axis −1, len 4.935
  4. (iθ)33!\frac{(i\theta)^{3}}{3!}Imag axis −i, len 5.168
  5. (iθ)44!\frac{(i\theta)^{4}}{4!}Real axis +1, len 4.059
  6. (iθ)55!\frac{(i\theta)^{5}}{5!}Imag axis +i, len 2.55

Each term multiplies the previous by iθn+1\tfrac{i\theta}{n+1}: rotate 90° left and scale by θn+1\tfrac{\theta}{n+1}. With enough terms, the spiral converges to the point at angle θ on the unit circle; even terms sum to cos θ and odd terms to sin θ.

10⁻⁶10⁻⁵10⁻⁴10⁻³10⁻²10⁻¹110¹0510152025n

Bar height is term magnitude θn/n!\theta^n/n! (log scale, clipped below 10−610^{-6}); blue bars are included terms. Consecutive ratios are θ/(n+1)\theta/(n+1): terms grow while the ratio exceeds 1 and shrink afterward. Orange highlights a peak term (n=3, magnitude 5.17); the 30-term spiral reaches distance 5.04 from the origin.

The error above compares the partial sum against cos/sin, combining truncation and floating-point rounding. Cancellation of large intermediate terms raises rounding risk, while large θ still leaves truncation error within 30 terms.

Full turns close the polygon back to zero

Summing ω^(jr) over j = 0..N-1 yields N when N | r and 0 otherwise.

Roots of Unity controls
8∤1: ∑j=07ωj=1−ω81−ω=1−11−ω=08\nmid 1\text{: }\sum_{j=0}^{7}\omega^{j}=\frac{1-\omega^{8}}{1-\omega}=\frac{1-1}{1-\omega}=0
ω⁰ω¹ω²ω³ω⁴ω⁵ω⁶ω⁷Multiply by ω^1 (step 1)
StartSum ω^(1j) tip-to-tail, j = 0…7

ω1=0.71−0.71i\omega^{1}=0.71-0.71i. ω^1 rotates by 1/8 turn. Returning to start in 8 steps traces a regular 8-gon; a closed polygon sums to 0. The dashed diameter links ω⁰ and ω^4: ω4=−1\omega^{4}=-1, so opposite roots negate each other — the symmetry FFT uses to halve the work.

The same sum as a matrix: F F∗=N IF\,F^{*}=N\,I

00800000001108000000220080000033000800004400008000550000080066000000807700000008

The Fourier matrix has Fjm=ωjmF_{jm}=\omega^{jm}. Entry (j,k)(j,k) of FF∗F F^{*} is ∑mω(j−k)m\sum_{m}\omega^{(j-k)m}, the exact sum above for r=j−kr=j-k: 8 on the diagonal and 0 off it. Highlighted diagonal: j−k≡1(mod8)j-k\equiv1\pmod{8} (click any cell to switch r). Thus F−1=1NF∗F^{-1}=\tfrac{1}{N}F^{*}: swap ω with ω−1\omega^{-1} and divide by N.

Canceling a frequency with a counter-rotating probe

Matching the signal frequency freezes the vectors along one direction; mismatched frequencies average to zero.

Frequency Probe controls
X2=∑j=015xj ω162j=0X_{2}=\sum_{j=0}^{15}x_j\,\omega_{16}^{2j}=0
Signal x_j
0123456789101112131415Spectrum |X_k| (click to select k)Orange: mirror X₁₄
Rotate each sample by jk steps & sum tip-to-tail

Vectors close into a polygon back at the origin: this probe frequency cancels out.

Pairs of roots share the same half-size computation

Splitting even and odd terms pairs ω^k with −ω^k into (u + v, u − v) butterflies across log₂N stages.

FFT Butterfly controls
Inputs reordered by 3-bit reversal: 0,4,2,6,1,5,3,70,4,2,6,1,5,3,7
10302040Input (bit-reversed)········Size-2 DFT········Size-4 DFT········Size-8 DFTa₀a₄a₂a₆a₁a₅a₃a₇X₀X₁X₂X₃X₄X₅X₆X₇

Click "Next stage" to start merging. Click any node in the active column to inspect its butterfly.

2 roots collapse to 1 when squared
Direct DFT
64 complex mults
FFT used
0 / 12 butterflies

Zero-pad, transform, multiply pointwise, and invert step by step

Compare floating-point complex FFT against exact finite-field NTT modulo a prime p.

FFT vs. NTT controls
a=1+2x, b=3+4xa=1+2x,\ b=3+4x: degree-2 product needs 3 coefficients, zero-padded to N=4N=4
  1. Zero-pad
  2. Transform a
  3. Transform b
  4. Pointwise ×
  5. Inverse
  6. Read output
kkaka_kbkb_ka^k\hat a_kb^k\hat b_kc^k=a^kb^k\hat c_k=\hat a_k\hat b_kRe(IFFT)\text{Re(IFFT)}Rounded\text{Rounded}
013·····
124·····
200·····
300·····

Each step reveals the next column; muted columns have not been computed yet.

This panel runs the same radix-2 FFT as the butterfly lab (conjugate, forward FFT, divide by N for the inverse). Numbers reflect this implementation rather than a universal bound.

What the Fourier transform diagonalizes

Every circulant matrix is a polynomial in the shift matrix P, so the Fourier basis diagonalizes all of them.

Circulant Matrix controls
FCbF−1=diag⁡(b^)=diag⁡(15, −2−5i, 5, −2+5i)FC_bF^{-1}=\operatorname{diag}(\hat b)=\operatorname{diag}(15,\,-2-5i,\,5,\,-2+5i)
Circulant matrix C_b4065540665400654
In Fourier basis150000−2−5i000050000−2+5i

Each column shifts the previous one cyclically down by one, so C_b = b₀I + b₁P + b₂P² + b₃P³. Fourier vectors are eigenvectors of P and hence of C_b: the diagonal is the DFT of b and off-diagonals are 0.

Three multiplications instead of four

Compute (a₀+a₁)(b₀+b₁) and subtract a₀b₀ and a₁b₁ to recover the cross term.

Karatsuba controls
a=a=
b=b=
3 mults: 8+10x+3x2; at x=10: 12×34=408\text{3 mults: }8+10x+3x^{2}\text{; at }x=10\text{: }12\times34=408

Direct expansion: 4 cells, 4 mults

b0=4b_0=4
b1=3b_1=3
a0=2a_0=2
a₀b₀ = p₀8
a₀b₁6
a1=1a_1=1
a₁b₀4
a₁b₁ = p₁3

The two diagonal cells are p0p_0 and p1p_1. We only need the sum of the off-diagonal cells: p2p_2 computes all four together, then subtracts the diagonal.

Karatsuba: 3 multiplications

  1. p0=a0b0=8p_0=a_0b_0=8
  2. p1=a1b1=3p_1=a_1b_1=3
  3. p2=(a0+a1)(b0+b1)=3⋅7=21p_2=(a_0+a_1)(b_0+b_1)=3\cdot7=21

a0b1+a1b0=p2−p0−p1=10a_0b_1+a_1b_0=p_2-p_0-p_1=10

(a0+a1x)(b0+b1x)=8+10x+3x2(a_0+a_1x)(b_0+b_1x)=8+10x+3x^{2}

Same idea: evaluate at 0, 1, ∞ & interpolate

C(0)=a0b0=p0,C(1)=(a0+a1)(b0+b1)=p2,C(∞)=a1b1=p1C(0)=a_0b_0=p_0,\quad C(1)=(a_0+a_1)(b_0+b_1)=p_2,\quad C(\infty)=a_1b_1=p_1

c1=C(1)−C(0)−C(∞)=21−8−3=10c_1=C(1)-C(0)-C(\infty)=21-8-3=10

C(∞)C(\infty) denotes the leading coefficient. A degree-2 product is fixed by 3 point values (3 mults) — the exact Point Values idea at three cheap points.

Replacing coefficients with half-length polynomials, 4 levels (n = 16)

Multiplications alone: 44=2564^{4}=256 vs. 34=813^{4}=81 (31.6%), lowering the exponent from 2 to log⁡23≈1.585\log_2 3\approx 1.585. Each level adds 4n−44n-4 additions; the table counts both mults and adds (direct: n2+(n−1)2n^2+(n-1)^2):

nDirectFull recursionRatioBest cutoffRatio
255771.40No recursion1.00
4252533331.32No recursion1.00
81131131271271.1240.91
164814814414410.9240.77
321,9851{,}9851,4471{,}4470.7340.62
648,0658{,}0654,5934{,}5930.5740.49
12832,51332{,}51314,28714{,}2870.4440.38
256130,561130{,}56143,88143{,}8810.3440.29
512523,265523{,}265133,687133{,}6870.2640.22
10242.10×1062.10\times10^{6}405,153405{,}1530.1940.17

Ratio < 1 means fewer total ops. "Best cutoff" switches to direct multiplication at that block size to minimize total ops. Full recursion starts saving at n=16; cutting off at length 4 saves ~9% at n=8 and 50% at n=64.

Seven products instead of eight for 2×2 blocks

Seven bilinear products cancel unwanted cross terms without using commutativity.

Strassen controls
A=A=
B=B=
7 mults give AB=(19224350), matching direct product\text{7 mults give }AB=\begin{pmatrix}19&22\\43&50\end{pmatrix}\text{, matching direct product}

Where M₁ lands when expanded

C₁₁
Entry of Aefgh
a+1+1
b
c
d+1+1
C₁₂
Entry of Aefgh
a
b
c
d
C₂₁
Entry of Aefgh
a
b
c
d
C₂₂
Entry of Aefgh
a+1+1
b
c
d+1+1

Cell (ii, jj) is the coefficient of monomial xiyjx_iy_j (e.g. aeae) in that output; outlined cells are the two needed terms. +1 and −1 are contributed by this product; entries outside the boxes must be canceled by others.

Inspect a product

  • C₁₁ (coeff +1): supplies ae; +ah canceled by −M₅; +de canceled by −M₄; +dh canceled by −M₇
  • C₂₂ (coeff +1): supplies dh; +ae canceled by −M₆; +ah canceled by −M₃; +de canceled by −M₂

Replacing scalars with blocks, 4 recursion levels (n = 16)

Multiplications alone: 84=4,0968^{4}=4{,}096 vs. 74=2,4017^{4}=2{,}401 (58.6%), dropping the exponent from 3 to log⁡27≈2.807\log_2 7\approx 2.807. Each level also adds 18 block additions; the table below counts both mults and adds (direct: 2n3−n22n^3-n^2):

nDirectFull recursionRatioBest cutoffRatio
2121225252.08No recursion1.00
41121122472472.21No recursion1.00
89609602,0172{,}0172.10No recursion1.00
167,9367{,}93615,27115{,}2711.9280.99
3264,51264{,}512111,505111{,}5051.7380.93
64520,192520{,}192798,967798{,}9671.5480.84
1284.18×1064.18\times10^{6}5.67×1065.67\times10^{6}1.3680.75
2563.35×1073.35\times10^{7}4.00×1074.00\times10^{7}1.1980.66
5122.68×1082.68\times10^{8}2.81×1082.81\times10^{8}1.0580.58
10242.15×1092.15\times10^{9}1.97×1091.97\times10^{9}0.9280.51

Ratio < 1 means fewer total ops. "Best cutoff" switches to direct multiplication at that block size to minimize total ops. Full recursion beats direct only at n=1024; cutting off at 8×8 already saves 16% at n=64.

Packing matrix multiplication into one polynomial product

Place matrix entries at chosen exponents so C_ij lands in distinct slots at the cost of Θ(n³) degree.

Matrix Encoding controls
A=A=
B=B=
[x1] PQ=a11b11+a12b21=1⋅5+2⋅7=19=C11[x^{1}]\,PQ=a_{11}b_{11}+a_{12}b_{21}=1\cdot5+2\cdot7=19=C_{11}

All 16 products of P(x) Q(x)P(x)\,Q(x) with their degrees

Q(x)=b21+b11x1+b22x4+b12x5Q(x)=b_{21}+b_{11}x^{1}+b_{22}x^{4}+b_{12}x^{5}

b₂₁·x⁰b₁₁·x¹b₂₂·x⁴b₁₂·x⁵
a₁₁·x⁰x⁰7x¹5x⁴8x⁵6
a₁₂·x¹x¹14x²10x⁵16x⁶12
a₂₁·x²x²21x³15x⁶24x⁷18
a₂₂·x³x³28x⁴20x⁷32x⁸24

Collect by degree and read the 4 target slots

AB=(19224350)AB=\begin{pmatrix}19&22\\43&50\end{pmatrix}, matching direct product.

Both terms of each CijC_{ij} land cleanly on their own degree with no collisions. Try a smaller gap above to see terms collide. Click any degree slot to highlight its contributing cells on the left; red borders mark needed AB terms that failed to land cleanly.

Useful entries are only a small fraction

In general, this encoding requires n3+n−1n^3+n-1 slots of which only n2n^2 belong to ABAB. Even with O(Nlog⁡N)O(N\log N) polynomial multiplication, N=Θ(n3)N=\Theta(n^3), so it is no faster than naive multiplication.

Reading notes & further questions

Companion interactive experiments for FFT:

  • Sliding convolution, point-value interpolation, complex rotation, Euler series, roots of unity, and DFT frequency probing.
  • Radix-2 FFT butterflies, full complex FFT vs. zero-error NTT pipeline, circulant diagonalization, Karatsuba, Strassen, and matrix encoding.