Studio 01 · Synthesis
Fourier series,
one harmonic at a time.
A periodic waveform is a sum of sines. Pick a starting shape, then move the amplitude and phase of harmonics 1 to 12 and watch the same coefficients redraw the trace, the spectrum and the sound. Nothing is normalised behind the scenes, so the overshoot of a truncated square wave stays visible — and audible.
- Sine · square · sawtooth · triangle
- 12 harmonics with phase
- RMS · peak · crest · THD
- WebAudio periodic wave
- y(t)
- fundamental
- harmonic amplitude
Drag on the trace to scrub; the readouts always describe the settings on the right.
Method
How the trace and the sound are built
The synthesiser keeps twelve complex coefficients and evaluates the real sum on screen. For each x position it takes the time t = 3 periods × x, and adds aₙ sin(2π n f₀ t + φₙ) for n = 1…12. The plot is sampled at 1 800 points, which is far more than the twelve harmonics need, so what looks like a vertical edge is really the overshoot of a finite series.
The presets are the textbook partial sums: a square is 1/n on odd harmonics, a sawtooth is 1/n on every harmonic, and a triangle is 1/(n²) on odd harmonics with every second sign reversed — that reversal is exactly the 180° phase you see on harmonics 3, 7 and 11. Because the amplitudes are shown in volts and never rescaled, a square with its first harmonic at 1 V stands only 4/π ≈ 0.785 V tall, and its peak sits at 0.93 V rather than 1 V. The triangle goes the other way: its series starts at 8/π², so normalising the first harmonic to 1 V makes the waveform 1.19 V tall.
Sound uses the same twelve coefficients in a WebAudio periodic wave, so the timbre cannot drift away from the picture. The gain is limited to 0.30 and passes a compressor with a −18 dB threshold.
Formulas
The four numbers to watch
| Quantity | Relation | Note |
|---|---|---|
| RMS of a sum | √(Σ aₙ²/2) | Orthogonal harmonics add in power |
| Peak | max |y(t)| over a period | Sampled at 4 096 points |
| Crest factor | peak / RMS | 1.414 for a pure sine |
| THD | √(Σₙ≥₂ aₙ²)/a₁ × 100 % | 48.3 % for an ideal square |
With harmonics only up to 11 the square preset shows 43.8 % THD, not 48.3 %: the remaining 4.5 points sit in harmonics 13 and above, which the twelve-slider bench does not reach.
Guides