Calculating Logarithmic Semitone Cents

While writing a blog post about phone keypad sounds, I realised I'd never done the maths to work out how semitone cents would be split up logarithmically. So here's a run-down of how it might work!

Each octave, a note on the keyboard doubles in frequency: where one A (A4) is 440Hz, the A above it (A5) is 880Hz, and A6 above that is 1760Hz. This means we can't describe the interval between pitches on the keyboard in linear steps, because the difference between 440Hz and 880Hz is much less than the difference between 880Hz and 1760Hz – even though to our human ears, they sound "an octave apart"!

So instead of using linear steps, we use a logarithmic scale. Given that an octave is split into twelve notes, we split our logarithmic scale into twelve sections. This means to get from one note to the note above it, instead of adding on a constant frequency, we multiply the note by 2^(1/12).

If this doesn't seem intuitive, remember the laws of exponents. For any frequency, if we apply some operation to the number twelve times, it needs to become twice the original value. We know that a^b * a^c is equal to a^(b + c). It follows that if we multiply a number by 2 ^ (1/12) twelve times, the number will effectively be multiplied by 2 ^ (1/12 + 1/12 + 1/12 +...), or 2^1 – it'll be doubled.

This gives us the property that the "logarithmic difference" between two pitches is 2^(1/12). But we don't want to stop at just dividing the octave into chromatic notes, we want to subdivide the semitones into 100 cents.

Again, each semitone gap is different, but the property that must hold is that by moving up 100 cents from any semitone, you must reach the next semitone up. So cents should also use a logarithmic scale!

Unfortunately, this does lead to a nasty bit of maths. The logarithmic difference between one cent and the next can be expressed as (2^(1/12))^(1/100) – if you multiply any frequency by this value 100 times, you'll get to the same frequency multiplied by 2^(1/12), i.e. the next semitone above it.

Thankfully, this can be simplified slightly using power laws: (2^(1/12))^(1/100) is equivalent to 2^(1/1200), or the 1200th root of 2. So the logarithmic distance between two cents is 2^(1/1200)!

Put another way, an octave must be split into 1200 cents. An octave occurs when you double a frequency. To double a frequency over 1200 steps, we multiply it by 2^(1/1200) at each step. After 1200 steps, the frequency will have been multiplied by 2.


Here's a practical use case for this. Given A4=440Hz, A♯4=466Hz, and a pitch of 452Hz, give a value for 0<n<100 such that the pitch may be represented as A4 + n cents.

Take 440Hz. How many times do you have to multiply it by 2^(1/1200) before it becomes 452Hz?

In other words, 452 = 440 * (2^(1/1200))^n.

Using power laws, the right hand side can be simplified to 440 * 2 ^ (n/1200).

Dividing both sides by 440, we get 452/440 = 2 ^ (n/1200).

Taking the log base 2 of both sides, we get log(2, 452/440) = n/1200.

And finally multiplying both sides by 100, we get n = 1200 * log(2, 452/440). If we plug that into Wolfram Alpha, we get a reasonable-sounding value of 47 (rounded to the nearest cent).

So our answer: to the nearest cent, 452Hz is equal to A4 + 47 cents!