Gregory Friedman The Greg Wide Web on the name →

Case Study · Math · Analysis

The Wave, Rebuilt from Circles

2026

The idea

Here is a claim that should sound impossible the first time you meet it: every reasonable periodic function, however jagged, is a sum of smooth sines and cosines. A square wave, all right angles and sudden jumps, is secretly nothing but circular motion added up. Fourier made this claim in 1807 about heat, and a generation of mathematicians refused to believe him, because the pieces are so much smoother than the whole. How can you build a corner out of things that have no corners?

The way to see it is to stop treating the sines as formulas and start treating them as motion. A term like sin⁡(nx)\sin(nx) is the height of a point going around a circle nn times as fast as the base rate. Stack those circles tip to tail, each spinning at its own integer frequency with its own radius, and the end of the chain traces a curve. Choose the radii and starting angles correctly and that curve is your target waveform. This is a Fourier series drawn instead of written: an epicycle chain, the same device medieval astronomers used to fit planetary motion, turned loose on any signal you like.

The approach

The plate below computes the radii and phases directly, by integration. For a chosen waveform ff it evaluates the real Fourier coefficients

Peak of the square-wave partial sum for three harmonic counts, showing the Gibbs overshoot holding near 8.9% as terms are added.
harmonics partial-sum peak overshoot
5 1.18836 9.42%
15 1.18028 9.01%
45 1.17914 8.96%

With JavaScript enabled this plate rebuilds a chosen waveform from rotating vectors, one per harmonic, and lets you dial the number of terms, with two further panels below the stage that redraw the same wave as its spectrum and as its phase portrait. The table is the figure's surprise in numbers: adding harmonics to a square wave narrows the ringing at the jump but never lowers it. The overshoot holds near 8.9% forever. That is the Gibbs phenomenon.

Plate I The reconstruction, harmonic by harmonic. Left: one rotating vector per harmonic, radius and phase read straight off the Fourier coefficients, summed tip to tail. Right: the running sum drawn over the dashed target, with the Gibbs horn measured live where a target jumps; the ochre tick marks how far the sum overshoots the step, holding near 8.95% however many terms you add. Below, the same wave twice more: the amplitude spectrum, one bar per harmonic, which is the wave drawn as frequencies instead of time, and beside it the phase portrait, the partial sum plotted against its own slope, which closes into a loop because both coordinates are periodic. Choose among six ready-made targets, from a square to a rectified sine, or type your own function of one variable, and raise the harmonic count: continuous targets close in everywhere, while every target with a jump keeps the stubborn overshoot and drives the height of the loop, max⁡∣fN′∣\max|f_N'|, up without limit. Press Play to let the chain turn; one marker rides all three panels at once, because they are one state of the wave seen three ways.
an=1π∫−ππf(x)cos⁡(nx) dx,bn=1π∫−ππf(x)sin⁡(nx) dx,a_n = \frac{1}{\pi}\int_{-\pi}^{\pi} f(x)\cos(nx)\,dx, \qquad b_n = \frac{1}{\pi}\int_{-\pi}^{\pi} f(x)\sin(nx)\,dx,

folds each pair into a single vector of radius an2+bn2\sqrt{a_n^2 + b_n^2}, and hands the list to the canvas. Nothing is hand-derived, so the demo is exact for any target function I care to write down, corners and all. The vertical height of the chain’s tip is the partial sum at that instant; a horizontal tie-line carries it to a marker sliding along the reconstruction, which is why the two panels always agree.

Four things are worth doing by hand. First, drag the harmonic count up from one and watch the coefficients you are adding: for the square and sawtooth they fall like 1/n1/n, a slow decay, which is why those waves need so many terms; for the triangle they fall like 1/n21/n^2, and three terms are already almost the whole picture. The rate of decay is a direct readout of how smooth the target is. A jump costs you 1/n1/n; a mere kink in the slope costs only 1/n21/n^2.

Second, watch the reconstruction near a jump. It does not simply approach the step. It overshoots, throwing up a little horn of ringing on each side, and here is the surprise the static table records before the animation even starts: adding harmonics does not shrink that horn. It only makes it narrower. The overshoot holds near 8.95% of the jump no matter how many terms you take, a constant Josiah Gibbs pinned down in 1899 (Henry Wilbraham had found it in 1848, and been forgotten). The plate measures it live off the partial sum, and you can watch the number refuse to fall.

Third, switch to the triangle. Same machinery, continuous target, and the overshoot vanishes: the ringing was never about the method, it was about the jump. Gibbs is the price of asking smooth things to render a discontinuity, and the price is fixed.

Fourth, look at the panel beside the spectrum, which is the same wave a third way. The phase portrait plots the partial sum against its own slope, (fN(x),fN′(x))(f_N(x), f_N'(x)), as xx runs once around the period. Both coordinates are periodic, so the trace closes into a loop, and the loop is a fingerprint of the harmonic content: one harmonic alone gives an ellipse, a sine against its own cosine, and every further harmonic winds another lobe into the curve. What the panel is really for is its vertical extent, max⁡∣fN′∣\max|f_N'|, printed at the foot of the panel, because differentiating term by term multiplies the nnth harmonic by nn and so weights the list by frequency rather than by size. Raise the count on the square wave and watch that number: 2.5 at a count of four, 12.7 at twenty, 25.5 at forty, growing without bound. It has to. At the jump every cosine in the derivative equals one at the same instant, so the steepest slope is just 4/π4/\pi times however many odd harmonics the sum has reached, and each new one adds another fixed step. Meanwhile the values themselves are settling to within a fixed 8.95% of the jump and staying there. That is the precise sense in which the series of a discontinuous function converges: in value, and not in slope. Then switch to the triangle and the number stops. It holds at 0.75 from about a dozen terms onward, and 0.75 is not a round number by accident: the triangle’s derivative is a square wave of height 2/π2/\pi with a jump of 4/π4/\pi, and 2/π2/\pi plus 8.95% of 4/π4/\pi is 0.7506. The overshoot did not disappear when the target became continuous. It moved one derivative down, which is where the phase panel was always going to find it.

Because the coefficients are found by integration and nothing is hand-derived, the plate does not actually care which target you hand it, so I added a Custom option: pick it and type your own f(x)f(x) over one period (I read xx from −π-\pi to π\pi), and the same quadrature computes its harmonics and the epicycles, the spectrum and the loop all rebuild around it. Try sin⁡(x)+0.3sin⁡(3x)\sin(x) + 0.3\sin(3x) to hear a third harmonic ride a fundamental, or something with a corner of your own invention and watch how fast the bars fall off. If what you type does not parse the figure just keeps the last waveform that did and tells you what tripped it, so you can edit toward something in real time.

The coefficients are dot products

Fourier’s coefficients are the same move that runs through the linear-algebra plates on this site, worn in a different coat. The functions sin⁡(nx)\sin(nx) and cos⁡(nx)\cos(nx) are mutually orthogonal over a period the way basis vectors are orthogonal in space; the integral that extracts ana_n is a dot product; the partial sum is the projection of ff onto the span of the first few harmonics, the closest fit in the least-squares sense that also governs the regression plate. Choosing more harmonics is enlarging the subspace you project onto, and the leftover ringing is the part of a jump that no finite-dimensional smooth subspace can reach.

And the spectrum, the list of radii, is a genuine second map of the same function: the waveform tells you what happens at each moment, the spectrum tells you what frequencies it is made of, and Fourier’s theorem is the promise that the two maps carry exactly the same information. That is the atlas idea in its purest form, a territory drawn two ways, and the phase portrait beside the spectrum is a third sheet of it: same wave, same information, plotted against its own derivative instead of against xx, and legible for a fact about slopes that neither of the other two sheets will show you. It is also, not by coincidence, how a vowel differs from another vowel and how the phonetic distance in the etymology work could in principle be grounded: timbre is spectrum.

The same transform, one dimension up

Nothing above used the fact that the domain was time. Swap the line for a plane and the machinery survives intact, which is the claim worth testing, because a two-dimensional transform sounds like it ought to cost two dimensions’ worth of work and does not. The saving is a one-line identity. The 2D basis function e−2πi(ux/N+vy/N)e^{-2\pi i(ux/N + vy/N)} factors into a function of xx times a function of yy, so the double sum that defines the transform separates: take the ordinary 1D transform of every row, then take the ordinary 1D transform of every column of that result, and you have the 2D transform exactly. Done naively from the definition it is O(N4)O(N^4), which at 128×128128 \times 128 is a third of a billion complex multiplies and would visibly hang a browser tab. Done as 2N2N separate FFTs it is O(N2log⁡N)O(N^2 \log N), about a hundred thousand, and it finishes between two frames. The plate below runs the same radix-2 Cooley-Tukey routine for rows and for columns; the only difference between the two passes is the stride it walks the array with.

The second thing to get straight is what a single point in the picture on the right actually is. Every bin of a 2D spectrum is one plane wave: the bin at (u,v)(u, v) is a corrugation with uu cycles across the image horizontally and vv cycles vertically, so it carries both a fineness and a direction. Its ridges run perpendicular to the vector (u,v)(u, v) and its wavelength is N/u2+v2N/\sqrt{u^2+v^2} pixels. That gives the spectrum a geometry you can read off by eye once you know the rule: distance from the centre is how fine the detail is, and angle from the centre is which way it lies. The exact middle is u=v=0u = v = 0, a wave with no oscillation at all, which is just the average brightness of the picture. Near the middle live the slow gradients that carry the coarse structure, the shapes you would still recognise squinting. Far out live the edges and the textures, because a sharp boundary is the one thing a smooth wave is bad at and it takes a great many of them, at every scale, to build one. Two display conventions make this legible and both are mandatory: the spectrum is shifted so DC sits in the centre rather than smeared into the four corners, and it is shown on a logarithmic scale, because DC typically sits four or five orders of magnitude above everything else and a linear map would render the whole panel black with one bright pixel in the middle.

Transform
Filter
Mask edge

Source · 128 × 128

Spectrum · log magnitude, DC centred

Filtered · inverse transform

Energy kept
93.8%
Overshoot past range
26.4%
RMS difference
0.142
Cutoff
ρ 0.18 · period 11 px

A brick wall in frequency is a sinc in space, so every edge comes back with a train of ripples beside it. That is the Gibbs overshoot of Plate I, in two dimensions, and the overshoot readout measures it.

Plate II The transform in two dimensions, with a filter in the middle of it. Left: a synthetic test chart, generated from formulas rather than photographed, so nothing has to be licensed and the frequency content is known before you look; the four quadrants are a smooth blob, a hard-edged square, a diagonal sinusoid and a fine checkerboard. Centre: its magnitude spectrum, log-scaled and shifted so DC is the middle pixel, with everything outside the pass band dimmed rather than blanked so you can see what is being discarded. Distance from the centre is fineness, direction from the centre is orientation, and the single diagonal sinusoid in the source is the one pair of bright dots off the axes. Right: the picture that comes back once the mask has been multiplied in and the transform run backwards. The thing worth doing by hand is switching the mask edge at a fixed cutoff. An ideal cutoff is a brick wall in frequency and a sinc in space, so it rings, and the ripples beside every edge are the Gibbs overshoot of Plate I with a second dimension bolted on; the overshoot readout says how far the result escapes the source's own range. A Gaussian mask blurs by the same amount and does not ring at all. The Transform control swaps the whole-image FFT for the 8 × 8 block DCT that JPEG actually uses, whose failure mode is blocking rather than ringing.

Filtering, in this picture, is a single multiplication: multiply the spectrum by a mask and transform back. Keep the middle and you have a blur; keep the outside and you have an edge detector; keep a ring and you have picked out one band of scales. What the figure is really for is the shape of the mask, because the first choice is the wrong one. A brick wall, gain 1 inside a radius and 0 outside, is the mask you would write first, and it rings: multiplying in frequency is convolution in space, an abrupt disc in frequency is a sinc in space, and a sinc has side lobes that go on forever. So every edge in the filtered picture comes back with a train of ripples beside it, and the readout puts a number on it, ten to twenty-five percent of the picture’s range depending on the source. This is not a bug in the figure and it is not a bug in the FFT. It is Plate I’s Gibbs overshoot, arrived at from the other direction: there we truncated a series and got ringing at a jump, here we truncate a spectrum and get ringing at an edge, and it is the same truncation both times. Switch the edge to Gaussian and the overshoot goes to zero, for the tidiest reason in the subject: the Fourier transform of a Gaussian is a Gaussian, so there are no side lobes to ring with. You pay for it with a cutoff that is a long fade instead of a boundary. Butterworth sits between the two, and so, in practice, does almost every filter anyone ships.

The last control is the one that connects all of this to a file on your disk. JPEG does not transform the whole image. It cuts the picture into 8×88 \times 8 tiles, takes a discrete cosine transform of each (a near relative of the DFT, real-valued and better behaved at the boundaries), and then quantizes: it divides each of the 64 coefficients by a number from a table tuned to human vision, rounds, and stores the result, which sends most of the high-frequency coefficients to zero and makes the rest cheap to encode. Set the plate to blocks and low-pass and you are doing a stripped-down version of exactly that, and the energy readout explains why the trick works at all. Keeping eight of the sixty-four coefficients in each tile still retains better than ninety-nine percent of the picture’s energy, because natural and near-natural images put almost everything they have into the low frequencies. The failure mode changes with the geometry, though, and that is the point of offering both. A whole-image filter rings, because its basis functions span the whole image. A block filter cannot ring across a tile boundary, because none of its basis functions reach that far; instead neighbouring tiles stop agreeing with each other, and the picture breaks into the visible squares that every over-compressed photograph on the internet wears as a badge.

What lies just past the edge

This plate does Fourier synthesis: it draws a waveform I supply, harmonic by harmonic. The mirror-image question, taking a recorded signal in and recovering its spectrum, is analysis, and the spectrum panel below the stage is the first step toward it; Plate II takes the rest of that step, in the plane rather than on the line, with the fast transform that makes the direction affordable. The coefficient integrals are computed by numerical quadrature rather than in closed form, a deliberate trade: it keeps the demo exact to the eye at this resolution and exact for any target I can write down, corners and all, with no hand-derived formulas to get wrong. I chose the real sine-cosine form over the tidier complex exponential on purpose. The exponential spins more cleanly, but the real form keeps the projection intuition visible, and that intuition is the whole point of the figure. The convergence on display is pointwise and in the mean, the right kind for these functions; the deeper theory of where and how Fourier series converge is a century of beautiful analysis that this figure is content to point toward.

Keys on this page

A figure's keys are its own: they answer once the figure has focus, so tab to it or click it first. Esc closes this sheet.