Compute the Fourier coefficients of a square wave, confirm the sine/cosine basis is orthogonal, and watch the reconstruction error and the Gibbs overshoot as you add terms in the sandbox, and predict — before you read it off the screen — that only odd harmonics appear, that the basis functions are mutually perpendicular, that the error falls as N grows, and that the overshoot at the jump refuses to vanish.
A Fourier series treats a period-T function as a vector in an inner-product space with 〈f, g〉 = ∫₀ᵀ f(t) g(t) dt. The basis functions 1, cos(2πkt/T), sin(2πkt/T) are orthogonal, so each coefficient is just the projection of f onto one basis vector, divided by that vector's square-norm: aₖ = (2/T)〈f, cosₖ〉, bₖ = (2/T)〈f, sinₖ〉. The N-term partial sum is the closest point in the subspace spanned by the first N harmonics — Fourier analysis is orthogonal projection.
Open the sandbox. Pick the square waveform, set the number of terms and the period, and read the coefficient bars, the orthogonality table, the RMS-error readout and the Gibbs-overshoot readout. Each step names the values to set, then read the number off the screen.
Waveform = square N (terms) = 12 Period T = 1 (read: b1, b2, b3, a1)
Also read: , , RMS at N=2 and N=20, Gibbs overshoot at N=40
Watch the coefficient bars (only odd bₖ are nonzero), the orthogonality table (zeros off the diagonal, T/2 on it), and the falling RMS error against the stubborn Gibbs overshoot — every number you predict is printed there.
Choose the square waveform with N = 12 terms and period T = 1. The first sine coefficient b₁ is the projection of the square wave onto sin(2πt). Predict b₁, then read the first coefficient bar.
The coefficient is b₁ = 4/π ≈ 1.273 — the exact height of the square wave's fundamental. Every odd harmonic follows the same rule, bₖ = 4/(kπ), so b₃ = 4/(3π) ≈ 0.424.
Keep the square wave, N = 12, T = 1. Look at the second sine coefficient b₂ (the sin(4πt) term). Predict its value, then read the second coefficient bar.
It is b₂ = 0: a square wave has only odd sine harmonics. Its half-wave symmetry — the second half is the negative of the first — kills every even term, so the reconstruction is built from sin(2πt), sin(6πt), sin(10πt), … alone.
In the orthogonality table read the entry for 〈sin₁, sin₂〉 — the inner product of the first two sine basis functions over one period. Predict it, then read the off-diagonal cell.
It is 〈sin₁, sin₂〉 = 0: any two different harmonics are perpendicular. That is exactly why each coefficient can be computed on its own — projecting onto sin₁ picks up nothing from sin₂.
Now read the diagonal entry 〈sin₂, sin₂〉 — a harmonic's inner product with itself, over the period T = 1. Predict it, then read the diagonal cell.
It is 〈sin₂, sin₂〉 = T/2 = 0.5: the square-norm of every sine harmonic is T/2. That is the divisor in the coefficient formula — it is why bₖ = (2/T)〈f, sinₖ〉 carries the 2/T normaliser.
With the square wave, set N = 20 terms and read the RMS reconstruction error. Compare it against the N = 2 case, whose RMS is about 0.435. Predict the N = 20 RMS, then read it.
The RMS error is about 0.142 at N = 20, down from 0.435 at N = 2: adding harmonics steadily shrinks the L² distance to the true wave (Bessel's inequality). The error falls with every term, though a jump discontinuity makes it fall slowly.
Push the square wave to N = 40 terms and read the Gibbs overshoot — how far the partial sum spikes past the true value at the jump, as a fraction of the jump height. Predict it, then read the readout.
The overshoot is about 8.96% of the jump — and it stays there. Adding terms only makes the spike narrower, never shorter: it converges to the Wilbraham-Gibbs constant, about 8.95%. L² convergence does not mean pointwise accuracy at a discontinuity — the classic surprise of Fourier series.
Everything above is waiting in the sandbox. Switch waveforms, drag the number of terms, and watch the coefficient bars, the partial-sum reconstruction, the orthogonality table, the RMS error and the Gibbs overshoot all update together — then push the square wave to high N and watch the overshoot narrow but never shrink.
- Computed the square wave's fundamental, b₁ = 4/π ≈ 1.273
- Saw the even harmonic vanish, b₂ = 0 — only odd harmonics survive
- Confirmed different harmonics are orthogonal, 〈sin₁, sin₂〉 = 0
- Read a harmonic's square-norm, 〈sin₂, sin₂〉 = T/2 = 0.5
- Watched the RMS error fall — 0.435 at N = 2 down to 0.142 at N = 20
- Saw the Gibbs overshoot hold near 8.96% at N = 40 — it narrows, it does not shrink
- Every value you predicted is the demo's own Fourier arithmetic, not a picture