From the handbook: Series, trigonometric and Fourier series, §411–418, pages 608–624
Any repeating shape, even one with sharp corners, is a sum of smooth sine waves of different sizes and speeds.
A sine wave is the smoothest possible repeating shape. In the 1800s Joseph Fourier claimed that every repeating shape, however jagged, can be built by stacking sine waves: one that repeats once per cycle, one that repeats twice, three times, and so on, each with its own size. Even a square wave, which jumps straight up and down, is a sum of perfectly smooth curves.
The slowest wave sets the overall swing. Faster waves add detail: they sharpen corners and flatten tops. The list of sizes, one per speed, is the shape's recipe, called its spectrum.
For a shape f(x) that repeats every 2π (one full turn of a circle), the book (§415) writes
f(x) = a₀/2 + a₁ cos x + b₁ sin x + a₂ cos 2x + b₂ sin 2x + …
Read it as “f of x equals a constant, plus some amount of the wave that repeats once, plus some amount of the wave that repeats twice, and so on”. sin kx and cos kx are waves that repeat k times per cycle; cosine is the same wave as sine, just shifted a quarter turn. The numbers ak and bk say how much of each to use.
How much of each? The Euler-Fourier formulas (§414) answer it: multiply the shape by the wave you're asking about and find the average (an integral, idea 6):
bk = (1/π) ∫ f(x) sin kx dx, from −π to π
Read it as “b-sub-k is one over pi times the integral of the shape times the kth sine wave”. Where the shape and the wave rise and fall together, the product is mostly positive and the amount is large; where they have nothing in common, it averages out to zero. The ak come the same way using cosine.
A square wave that sits at +1 for half a cycle and −1 for the other half turns out to need only the odd-numbered sine waves, in sizes 4/π, 4/(3π), 4/(5π), …:
f(x) = (4/π) (sin x + sin 3x / 3 + sin 5x / 5 + …)
Check it at the middle of the flat top, x = π/2, where the true value is 1. The first wave gives 4/π ≈ 1.273, too high. Adding the second (sin 3x/3 is at its lowest there) takes away 0.424, giving 0.849. The third adds back 0.255: 1.103. The fourth takes 0.182: 0.921. The sum swings above and below 1, closer each time. The page opens with two waves added.
Near the jump the sum always overshoots by about 9% however many waves you add (the Gibbs effect), though the overshoot gets squeezed into a thinner and thinner spike. At the jump itself the sum lands halfway, at 0, just as the book's theorem for shapes with jumps says (§418).
This is how sound is analysed and music compressed, how a JPEG image throws away detail you won't miss (it keeps the slow waves and drops the fast ones), and how MRI and CT scanners build an image: the scanner measures the spectrum and a computer adds the waves back up. Procedural terrain and clouds are made the other way round, by stacking noise at many speeds and sizes. Any looping animation cycle is a repeating shape and can be smoothed by dropping its fastest waves.
Vygodsky, Mathematical Handbook: Higher Mathematics, chapter “Series”.
Sine and cosine together are a point going round a circle. That link, through imaginary numbers, is Euler's formula, idea 11.