Why does a violin, a clarinet, and a flute playing the exact same note (like A3 at $220\text{ Hz}$) sound completely different?
The answer is timbre (often called tone color or sound quality). Timbre is produced by harmonics (overtones).
When an acoustic instrument plays a note, the vibrating string or air column doesn't just vibrate in one simple wave. It vibrates in multiple modes simultaneously at integer multiples of its lowest frequency, known as the fundamental frequency $f_0$:
$$f_n = n \cdot f_0 \quad (n = 1, 2, 3, 4, 5, \dots)$$
$n = 1$: Fundamental frequency ($f_0$) — sets the main musical pitch you recognize.
In the early 1800s, French mathematician Joseph Fourier made a profound discovery: any continuous periodic sound wave can be constructed by adding together pure sine waves of harmonic frequencies:
$$y(t) = \sum_{n=1}^{N} A_n \sin(2\pi \cdot n f_0 \cdot t)$$
By choosing different recipes of amplitudes $A_n$, we can synthesize the characteristic sounds of entire families of musical instruments:
Pure Tone (tuning fork): Only the fundamental ($n=1$). Very smooth and plain.
Sawtooth Wave (violin, cello, bright brass): Contains all harmonics ($n = 1, 2, 3, 4, \dots$) with amplitude $A_n = 1/n$. Bright, buzzy, and full.
Square Wave (clarinet, oboe, vintage 8-bit synths): Contains only odd harmonics ($n = 1, 3, 5, 7, \dots$) with amplitude $A_n = 1/n$. Hollow and reedy.
Triangle Wave (flute, recorder): Contains only odd harmonics with rapidly falling amplitudes ($A_n = 1/n^2$). Soft and breathy.
s = {} for n = 1, 10 do amp = 1 / n freq = n * 220 table.insert(s, amp) table.insert(s, freq) end play_sines(s, 3)
Move the mouse over a dotted box for more information.
Acoustic Physics: Instruments open at both ends (like flutes) or strings anchored at both ends (like violins and guitars) form standing waves with nodes at both ends: $L = n \frac{\lambda}{2}$. This produces all integer harmonics ($n = 1, 2, 3, \dots$).
Pipes Closed at One End: Instruments like the clarinet or pan pipes are closed at the mouthpiece and open at the bell. They have a node at one end and an antinode at the other: $L = (2m - 1)\frac{\lambda}{4}$, which naturally produces only odd harmonics ($n = 1, 3, 5, \dots$). This gives them their uniquely hollow acoustic signature!
Now you try. Run the code with $N = 1$, then $N = 3$, and $N = 12$. Notice how each added harmonic introduces more brightness and acoustic warmth!
Type your code here:
See your results here:
The default code synthesizes an acoustic bowed-string instrument (a sawtooth wave) from pure mathematics!
1. Replace ???? with 1 and hit Run. You will hear a single, sterile sine wave (like a hearing test beep).
2. Next, try N = 3: the sound gets warmer as the 2nd and 3rd harmonics join in.
3. Now set N = 12: listen to how rich, bright, and brassy the tone becomes! Adding higher harmonics gives sound its life and presence.
Share your code
Show a friend, family member, or teacher what you've done!