## May 23rd, 2008

### Musical tuning: visuals from the lecture.

The lecture went well! I had a good, engaged audience — a little over a dozen people, i think — and they put up with the multiple glitches in my presentation software. I wrote the software to do these animations using Pyglet, a multimedia library for Python.

Here's a condensed version of the first part of the lecture. It isn't quite the same without the audio — we could play the notes depicted on these slides, to hear the intervals we were talking about. But i'll try to explain the ideas in text.

* * *

Musical notes are oscillations, and the pitch of a musical note is determined by the frequency of the oscillation. (There are often many different frequencies embedded in the sound of a particular instrument, but the pitch we hear is usually the loudest and lowest of the frequencies.)

Two notes played together sound harmonious if their frequencies are in a ratio of small integers. That's because when the ratio is simple, the combination of waves makes a simple repeating pattern like the pair of waves on the bottom of this picture. The pair on top are not in a simple ratio, so the pattern doesn't repeat exactly. The ratio between 300 Hz and 600 Hz is 1 to 2, the simplest possible ratio of two different notes. We hear that as an octave — such a basic interval that the two sound like the "same note". Here are the four octaves starting from 100 Hz — they go up to 200, 400, 800, and 1600 Hz. Plotted on a logarithmic scale, all ratios of 1 to 2 appear as equal distances. I'll mark this distance with a red bar. Let's zoom in on one of these octaves and see what other ratios look like. I'll drop the "Hz" for now and mark the starting frequency just as 1. The next simplest ratio is from 2 to 3; i'll mark that with a blue bar. The ratio from 3 to 4 gets a green bar. And the ratio from 4 to 5 gets a yellow bar. The ratio from 2 to 4 is also an octave. And the blue interval and green interval fit neatly inside — so they add up to exactly an octave. The blue interval is known as a "perfect fifth" and the green interval is called a "perfect fourth" — the reason for these names will become clear in a moment when we've put together the major scale.

If you go a perfect fifth up from 1, you get to 3/2, or 1.5. And if you go a perfect fourth up from 1, you get to 4/3 (about 1.333). These fit symmetrically between 1 and 2 — you can imagine a line right down the middle, and the two notes on one side are a mirror image of the two notes on the other. The yellow interval — the ratio 5/4 — is called a "major third". If you go up this much from 1, you get to 1.25. And the three notes 1, 1.25, 1.5 make a nice-sounding chord — this is the major chord. Let's construct a major chord starting at each of the three notes shown above: starting from 1, from 1.333, and from 1.5. Each major chord is a yellow-blue pair in the picture below. The top note of the chord starting at 1.5 overshoots the top of the octave — it goes to 2.25, which is the ratio 9/4. The equivalent note within the octave is exactly half of that, at 9/8. These seven notes we've identified form the major scale — if we label them in increasing order starting from C, these are (approximately) the white keys on a piano. So this explains why there are seven white keys in each octave on a piano.

You can see now why C–E is called a "third" — E is the third note counting from the left, and C–F is called a "fourth" — F is the fourth note, and C–G is called a "fifth" — G is the fifth note. The frequencies you see above are the "just intonation" for the major scale.

Notice that the spaces between the notes are uneven — E and F are closer together than the rest, and so are B and C at the top of the scale. In each of the five bigger gaps, there's space for another note. These are the black keys on a piano — that's why there are five black keys in each octave.

But piano keys are not tuned exactly like the notes in the picture above. That's because the spaces that look about the same are not exactly equal. For example, although D looks about halfway between C and E, it isn't. The ratio of D to C is 9/8 = 1.125, but the ratio of E to D is 10/9 or about 1.111. That means that if you tune your notes according to these ideal ratios, the scale will only sound right when you start on C. The other intervals will be off. For example, the fifth note starting from D is A. But the interval D–A is not a perfect fifth; it's 40/27, or about 1.48, which sounds really off.

To make it possible to play in any key, pianos (and most modern instruments) are tuned so that all twelve notes are equally spaced within the octave. This picture compares the justly-tuned major scale (on top) with 12 equal divisions of the octave (on the bottom). By an amazing coincidence, when you divide the octave (a multiplicative factor of 2) into 12 equal parts (each a multiplicative factor of 21/12), you get notes that closely correspond to every note of the major scale. For example, 7 of these 12 parts almost exactly make a perfect fifth: 27/12 is very nearly equal to 1.5. Where the lines match up, you have a white key on the piano; and where there is a missing line on top, that's where you have a black key.

When you tune the piano to this system, which is called "12-tone equal temperament", the scale starting from any key sounds exactly the same. This means you can write music that shifts from key to key freely, without fear of ending up in a bad-sounding scale — all the scales sound equally good. The scales are a little off from what they should be, though. The fifth on an equal-tempered keyboard sounds pretty much indistinguishable from a real perfect fifth; but you see how the E doesn't quite match up? The major third is off by an amount that you can hear if you listen closely. The A is off by even more.

One of the big surprises for me when i learned about this stuff is that the 12-semitone system is rather arbitrary. It's not mathematically fundamental; it's a compromise: an approximation we invented. All of Western music is based on it, which, in a way, makes all of Western music a kludge. And it is impossible to tune the notes both in simple ratios and allowing modulation freely between all keys. The frequencies can never match up, because the just tunings are rational numbers, and any equal division of the octave will produce irrational numbers (nth roots of 2).

(I then wandered off into talking about the scales in other cultures, and we listened to samples of music from these other cultures and from modern experiments in 19-tone and 13-tone equal temperament.)

)