About Music Maths
Why do some pairs of notes sound sweet together and others clash? Because a note is a wave, and two waves whose frequencies make a simple ratio, like 3 : 2, line up again after only a few wiggles. This page shows that four ways. Everything is drawn as well as played, so it works with the sound off (or blocked, as it often is on work computers).
- KEYBOARD: two octaves from middle C. Click or tap the keys, or use the computer keys A W S E D F T G Y H U J K O L P ; ' (Z and X move them down or up an octave). Each key shows its name and frequency; the page writes the notes on a stave, draws their wave and says how the frequency is worked out. Hold several keys for a chord.
- INTERVALS: pick an interval and click a key for its bottom note. You see the two waves and what they add up to, how soon the pattern repeats, the Lissajous figure the pair draws (the shape the Lissajous Shapes app draws with two slides), and the beats. Detune pushes the top note slightly off to make the beats grow.
- STRING: the harmonics of a vibrating string, 1 to 8, the still points between them, the notes they make on a stave and how far each is from the nearest piano key. PLUCK shows the string pulled into a point, which is all its harmonics at once. The two sliders are Mersenne's laws: a shorter or tighter string sounds higher.
- TUNINGS: Pythagorean, just and equal temperament side by side: how far each note is from equal temperament, the beats in a chord in each, and the Pythagorean comma. Tuning at the top sets how the keys themselves are tuned, and Key the note that Pythagorean and just tuning are built on.
COPY LINK copies the tab, notes and tuning you have set up.
THE STORY
The idea that musical intervals are whole-number ratios goes back to the followers of Pythagoras in ancient Greece: a string stopped at half its length sounds an octave higher (2 : 1), at two thirds a fifth (3 : 2), at three quarters a fourth (4 : 3). The famous tale that Pythagoras heard it in the ringing hammers of a blacksmith's forge is a legend: hammers don't ring that way, and the story first appears centuries after him. The single-string monochord, with a sliding bridge, was the instrument for showing it.
In 1636 Marin Mersenne, a French friar and mathematician, set out in his Harmonie universelle the laws of a vibrating string: its pitch goes up as it gets shorter, as the square root of its tension and down as the square root of its weight. He also wrote of hearing higher notes, the harmonics, sounding inside the note of a single string.
Stacking pure 3 : 2 fifths never quite comes back to an octave: twelve of them overshoot seven octaves by the Pythagorean comma, 531441 : 524288, about a quarter of a semitone. Tuners spent centuries hiding that gap. Just intonation uses the simplest ratios (5 : 4 for a major third) but only works in one key. Equal temperament splits the octave into twelve exactly equal steps of the twelfth root of 2; it was worked out precisely by the Chinese prince Zhu Zaiyu in 1584 and by the Flemish mathematician Simon Stevin in about 1585, apparently independently. It became the usual tuning for pianos in the 19th century.
This app grew from the Python script Piano.py, which played a short tune on a tablet's built-in piano sounds, one named note at a time (C3, D3#, F3…) with a pause after each. Its note names are the ones on these keys.
HOW IT WORKS
Frequencies: A4 = 440 Hz, and in equal temperament each key is 21/12 ≈ 1.05946 times the one below, so twelve keys double it. In just and Pythagorean tuning the key note sits where equal temperament puts it and the other notes are its simple ratios (just) or a chain of pure fifths (Pythagorean). A cent is a hundredth of an equal-tempered semitone; 1,200 to the octave.
Two waves of frequencies in the ratio p : q repeat together every q waves of the lower note. When the ratio is slightly off, the lower note's p-th harmonic and the upper note's q-th are close but not equal, and the sound swells and fades as they drift in and out of step: beats, at the difference of the two frequencies. The pictures draw pure waves; the sound adds a few harmonics, like a real instrument, so the beats can be heard.
A string fixed at both ends can only vibrate in whole numbers of half-waves: 1, 2, 3… loops, at 1, 2, 3… times the lowest frequency. A string plucked at a point is a triangle, which is the sum of these harmonics with sizes 2 sin(nπp) ÷ (n²π² p(1 − p)), p being where it was plucked: plucked at a fifth of the way, the 5th harmonic is missing.
Sound uses your browser's Web Audio and only starts when you press something. Nothing is recorded or sent anywhere.
FURTHER WATCHING AND READING