Sid's Site


You have been given a keyboard. Inconveniently, this keyboard has not been tuned. You'd like to play it, and therefore decide to tune it yourself. Luckily, the mechanics of tuning this keyboard are easy... you just need to work out which frequency to assign to each note...

The octave doubling rule

You try to recollect any relevant info you might have picked up over the years.. and remember the following:

    The note an octave above, has double the frequency.

In other words, if note C5 has frequency f, then note C6 will have frequency 2*f. As far as you remember, this should apply to all the notes on the keyboard.

It follows from this that the note an octave below must have half the frequency. So C4 would have a frequency of f/2.

Great! But where to go from here?..

The first frequency

You allow your eyes to wander up and down the 88 key keyboard...

You realise that you could pick a relatively middling key on the keyboard, and assign to this a relatively middling frequency.

You choose A4 to be your middling key. You then play around with a tone generator, and decide that you perceive ~440Hz to be a fairly middling frequency.

You turn on your piano, and program in freq(A4) = 440Hz.

Great! You have now tuned one note!

All the As

Now that you have decided on a frequency for A4, you realise that you can work out the frequencies of all the other As, using the octave doubling rule:

And:

So you program these in...

Great! Now you have tuned all of your As!

Join the dots

You have all the As tuned, but you're not sure what to do about the other notes.

You wonder if a graph might help, so you painstakingly draw out the following:

Graph of the A key frequency, vs the key number on the keyboard.

Looking at this graph, you realise that drawing a curve through the points would assign a frequency to each key on the keyboard. However, drawing the curve looks somewhat difficult..

On a whim, you decide to plot the points again, but this time using logarithmic graph paper:

Graph of the A key frequency, vs the key number on the keyboard, with log y axis.

Aha! Now you can use a ruler to draw a straight line through the points:

Graph of the A key frequency, vs the key number on the keyboard, with log y axis, and line through it.

If you want to find the frequency of a certain key, you can read it off the graph!

You wonder if the octave doubling rule still applies to any note, or just to the As. You read a few values from the graph, and it seems like it does apply to all notes! "Hurrah!" you shout.

Great! By reading from the graph, you can now tune all the notes on your piano!

Finding the expression

Unfortunately, you don't enjoy reading values from the graph. It's repetitive, inaccurate, and slow.

"If only I had a mathematical expression for this curve", you think to yourself, "then I could accurately compute the frequencies for this keyboard!"...

You write out the frequencies of the A keys on your keyboard, and re-number them:

k 1 2 3 4 5 6 7 8
freq 27.5 55 110 220 440 880 1760 3520

You notice that 880 is 440 * 21, and that 1760 is 440 *22, and that 3520 is 440 *23... And realise that you can write the exponent in terms of k...

freq = 440 * 2k-5

You double check that this works for k=4, k=3 and k=1... and it does!

Now you write a table, showing how the 'k' number maps to the keyboard number (e.g. A4 is note number 49 on the keyboard, A5 is 61, etc.):

k 1 2 3 4 5 6
n 1 13 25 37 49 61

You play around, and discover that n = (k-1)*12 + 1.

You realise you need it the other way around, and re-arrange to: k = (n-1)/12 + 1.

You realise you can sub this into your expression for freq!

freq = 440 * 2(n-1)/12 + 1 - 5

Using this expression, you compute the frequency for all 88 keys on your keyboard accurately and conveniently!

Great! You have now tuned your keyboard satisfactorily! After 10 years of lessons, and daily practice, you will one day also be able to play your keyboard satisfactorily!

You started with the octave doubling rule as an axiom.

You selected a key on the keyboard, and assigned it a frequency, fairly arbitrarily, but also fairly sensibly (a middling frequency for middling key).

These two steps allowed you to fit a curve, which gave a sensible tuning for the whole keyboard.

This tuning is called twelve-tone equal temperament. It's "the most common tuning system since the 18th century" (wikipedia), but not the only tuning option available.

https://en.wikipedia.org/wiki/Equal_temperament

https://en.wikipedia.org/wiki/Piano_key_frequencies