Case Study · Math · Analysis
The Wave, Rebuilt from Circles
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 is the height of a point going around a circle 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 it evaluates the real Fourier coefficients
| 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.
folds each pair into a single vector of radius , 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 , a slow decay, which is why those waves need so many terms; for the triangle they fall like , 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 ; a mere kink in the slope costs only .
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, , as 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, , printed at the foot of the panel, because differentiating term by term multiplies the th harmonic by 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 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 with a jump of , and plus 8.95% of 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 over one period (I read from to ), and the same quadrature computes its harmonics and the epicycles, the spectrum and the loop all rebuild around it. Try 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 and are mutually orthogonal over a period the way basis vectors are orthogonal in space; the integral that extracts is a dot product; the partial sum is the projection of 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 , 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 factors into a function of times a function of , 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 , which at is a third of a billion complex multiplies and would visibly hang a browser tab. Done as separate FFTs it is , 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 is a corrugation with cycles across the image horizontally and cycles vertically, so it carries both a fineness and a direction. Its ridges run perpendicular to the vector and its wavelength is 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 , 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.
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.
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 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.