At a glance
Almost any repeating shape can be built by adding sine waves whose frequencies are whole multiples of one base frequency, even a square wave with its sharp jumps. This sim adds the sines one at a time, so you can see how many it takes to match a target and what the sum looks like along the way.
What you'll learn
- How each sine's amplitude is calculated, and why the amplitudes do not depend on one another.
- How the quality of the match depends on the number of terms N and on the shape of the target.
- What these sines are for a particle in a box.
- How the width of a bump relates to the sines it needs.
What's on screen
- Individual Components (top strip): one card per term, with its formula, its amplitude and its curve. Scroll sideways when N is large.
- Dashed target: the shape being matched.
- Partial sum (blue to pink curve): the N terms added together.
- Sweeping line and dot: a marker that moves along the sum. It changes nothing.
- Equation bar: the sum written out. For the square and sawtooth it shows the first six terms, then ⋯.
The controls
Press ⌖ on a row to see where that control sits in the sim.
| Control | What it changes | Range | |
|---|---|---|---|
| Wave Type | The target: Square, Sawtooth, Gaussian, or Two Gaussians. | 4 buttons opens on Square | |
| Gaussian width σ/L | The width of each bump, as a fraction of the box width L. It appears only for the two Gaussian targets. | 0.02–0.25 opens at 0.10; Two Gaussians: 0.02–0.15, opens at 0.05 | |
| Number of terms N | How many sines are added. The − and + buttons step by one. | 1–30 opens at 2 | |
| Individual Components | One card per term, showing its amplitude and curve. | strip | |
| Main plot | The dashed target, the partial sum and the sweeping marker. | plot | |
| Panel divider | Drag it up or down to give the strip or the plot more room. | drag | |
| Reset | Returns to the opening wave type, number of terms and width. | top bar |
Fixed: the box width L = 1. Square and sawtooth have period 2π and are drawn from −2π to 2π. The Gaussian target is exp(−(x − L/2)²/2σ²); Two Gaussians has equal bumps at L/4 and L/2.
Where the sine waves come from
Every term is a sine whose frequency is a whole multiple of one base frequency. Two different ones, multiplied together and integrated over the range, give zero:
So each amplitude can be found on its own: multiply the target by that one sine and integrate. The sim does these sums for you and only adds the results:
The square wave uses odd harmonics only, so N counts terms, not harmonics. Term k carries n = 2k + 1: at N = 3 the terms are n = 1, 3, 5.
What a jump costs
A jump is a vertical edge, and smooth sines can imitate it only by piling up. The square-wave amplitudes fall slowly, A = 4/(nπ), and N terms reach n = 2N − 1.
- The last card is 1/(2N − 1) of the first: 1/11 at N = 6, and still 1/59 (1.7%) at N = 30.
- The slope of the sum at the jump (x = 0) is exactly 4N/π: 3.8 at N = 3, 38 at N = 30. It grows without limit as N does, which is how smooth curves approach a vertical edge.
- The sawtooth has the same 1/n fall, with every n present and alternating signs. Its jump is at x = π.
The spike beside the jump stays
Just beside each jump the sum overshoots the target. More terms squeeze that spike towards the jump but do not lower it.
The peak is 1.1796 at N = 12 and 1.1791 at N = 30. It tends to (2/π)∫₀^π (sin t / t) dt = 1.17898, so the overshoot settles at 8.95% of the jump (the jump is 2, from −1 to +1). The peak sits a distance π/2N from the jump.
Away from the jump the sum does converge to the target, because the spike keeps moving in. Right at the jump it never converges evenly. This is the Gibbs phenomenon. The sawtooth tends to the same limit at its jump, more slowly.
What a smooth target needs
A Gaussian bump has no jump, and its coefficients fall much faster than 1/n:
The exponential factor is itself a Gaussian in n. It falls to 1/e at nₑ = √2 L/(πσ), and beyond about that n the cards are flat.
| σ/L | nₑ | of 30 coefficients, above 1% of the largest |
|---|---|---|
| 0.25 | 1.8 | 2 |
| 0.10 | 4.5 | 5 |
| 0.02 | 22.5 | 15 |
Symmetry decides which n appear. The single bump is symmetric about L/2 and the even sines are antisymmetric about it, so their coefficients are exactly zero. Two bumps at L/4 and L/2 break that symmetry: n = 2, 6, 10 … carry weight, while n = 4, 8, 12 … stay exactly zero.
These sliders move the sim too. σ/L matters only for the Gaussian targets.
The same series in a box
On [0, L] the terms sin(nπx/L) are the stationary states of a particle in an infinite square well, with energy Eₙ = n²π²ħ²/2mL². Read the bump as an unnormalised wavefunction ψ(x) = Σ bₙ sin(nπx/L). Then bₙ² is the weight on level n, and the probability of finding Eₙ is bₙ² divided by the sum of all the bₘ².
Each sine is an equal mix of a right-moving and a left-moving wave. So n fixes the size of the momentum, |p| = nπħ/L, but not its direction, and ⟨p⟩ = 0.
A narrower bump in x needs more levels, so its momentum is spread wider. For a Gaussian with σ ≪ L:
Where it matters
- Sound. An ideal square-wave tone contains odd harmonics only, with amplitudes falling as 1/n: the series of the square wave here.
- Imaging. An MRI scan measures only a finite range of spatial frequencies, which truncates the series. Sharp edges in the image then show ringing beside them, the Gibbs (or truncation) artefact.
- Quantum states. Expanding a state in energy eigenstates is this same calculation, and the trade-off between width in x and spread in p is the uncertainty relation.
Go deeper: what the series captures, and where the sim's formulas stop
- For the square wave, N terms carry (8/π²) Σ 1/(2k+1)² of the mean square: 81.1% at N = 1, 93.3% at N = 3, 99.3% at N = 30. The power converges even though the spike stays.
- The Gaussian formulas assume σ ≪ L. Up to σ/L = 0.15 they agree with the exact box integral to within 0.0003. At σ/L = 0.25 they do not: b₅ is 0.0006 in the sim and 0.0279 exactly.
Summary
Key points
- Each amplitude is found on its own, so N only adds terms.
- At a jump the amplitudes fall as 1/n; the spike narrows but keeps its height.
- For a Gaussian the coefficients fall like a Gaussian in n, reaching 1/e at nₑ = √2 L/(πσ).
- In a box the terms are energy states; a narrower bump needs more of them (ΔxΔp = ħ/2 for σ ≪ L).
Common mix-ups
- "Add enough harmonics and the overshoot goes away." The spike narrows; its height stays at 8.95% of the jump.
- "N is the highest harmonic." For the square wave the highest is n = 2N − 1.
- "A sine in a box has a definite momentum." Only |p| = nπħ/L is definite; the sign is an equal mix.
Things to try on your own
- Raise the square wave from N = 1, noting the n of each new card.
- Choose Two Gaussians at σ/L = 0.05, N = 12, and list the cards that read exactly zero.
- Choose Gaussian at N = 30 and move σ/L from 0.25 to 0.02, noting how far along the strip the amplitudes stay sizeable.