Frequency of Musical Notes
Harmonic Series
A tone that we perceive as having a musical pitch is made up of harmonically-related frequency components, that are whole-number multiples of a fundamental frequency. But how do you know what the fundamental frequency of a given pitch is supposed to be?
Well, one way to find out would be to Google “frequency of musical notes”, and you’d be shown a chart that looks something like this.
Pitch-to-Frequency Chart
This chart shows the names of some musical notes, their fundamental frequency in Hertz, and the wavelength of that frequency in centimeters. (We don’t care about the wavelength in this discussion; it just happens to be included in this particular chart.)
So, theoretically, you could implement a pitch-to-frequency chart like this as a lookup table—an associative array—in your program. But instead of doing that, you can just have the computer calculate the frequency as needed, which has various advantages. So, here’s how to do that.
A-440
You’ll notice that this note here, which is the A above middle C, has a frequency of exactly 440 Hertz. That has been a tuning standard in Western music for over a century, and in fact has become an international standard. Not all instruments or orchestras necessarily tune to exactly that frequency, but all synthesizers and tuning devices use 440 Hz as the standard for that note A above middle C.
And because of what we know about octave equivalence, if we multiply or divide that frequency by a power of 2, we’ll get other As in other octaves.
Other As
For example if we multiply by 2, we get the A an octave higher at 880 Hz. If we were to multiply that by 2, we’d get the A another octave higher at 1760 Hz. If we divide 440 Hz by 2, we get the A an octave lower at 220 Hz, and if we were to keep dividing by 2 we’d get successively lower As at 110 Hz, 55 Hz, and 27.5 Hz, which is the fundamental frequency of the lowest key on a piano.
But how did we arrive at the frequencies for all the other notes in between? You’ll recall that in Western music there are 12 different notes per octave—A Bb B C C# D Eb E F F# G G#. (For historical reasons, the interval between each of those pitches is called a semitone, but in this discussion we’ll just call them “steps”.) The predominant tuning system that has been in use in Western music for centuries is called 12-tone equal temperament, which means that the tunings of the 12 pitches in each octave are derived by dividing the octave into 12 equal parts. Here’s the formula for how to do that.
The Formula (for Bb)
Given the standard of A being 440 Hz, we can use this formula to calculate the frequency of the note one step above that, which is B-flat. The formula says:
Base Frequency
We know that the frequency upon which all calculations will be based is 440 Hz.
Octave Factor
And we know that an octave is obtained by multiplying by a factor of 2, and each different A is obtained by multiplying by some integer power of 2. 2 to the 0th power is 1, so that gives us 440, 2 to the 1st power is 2, so that gives us 880, 2 to the 2nd power is 4, so that gives us 1760, and so on. And 2 to the -1st power is ½, so that gives us 220, 2 to the -2nd power is ¼, so that gives us 110, and so on.
Divisions of the Octave
For 12-tone equal temperament we want to divide the octave into 12 equal steps, 12 equal pitch intervals. So instead of taking only integer powers of 2, we’ll take fractional powers, 12ths of an octave.
Steps
We’ll take 2 to the 1/12 power, also known as the twelfth root of 2, to find out the frequency of the step just above A.
Bb
The 1 in this fractional exponent indicates that we’re taking one step up from A, to B-flat.
Twelfth Root of 2
The twelfth root of 2 equals 1.059463, which is to say an increase of about 6%.
Frequency of Bb
So, if we multiply the base frequency of A, 440, by the twelfth root of 2, we learn that the frequency of the B-flat above it is 466.163762 Hz. The difference in frequency between these two notes is about 26 Hz, but we don’t care about that number so much because that difference will vary at different pitch heights; the thing we care about, and that will determine our sense of the pitch interval, is the ratio of the two frequencies.
It’s worth noting that, because of the physical and cognitive fact that octave equivalency occurs with a factor of 2, and because of the cultural standards of A-440 being the recognized base frequency and 12 being the number of steps per octave, most of the numbers in this formula are going to stay constant.
Steps is the Variable
The one element of this equation that we will definitely want to vary is the number of steps, in order to calculate the frequency of all the different pitches.
Frequency of B
For example, if we change that value to 2, we get the frequency of the pitch B-natural, two steps above A-440. (You might notice that the arithmetic difference in frequency between this B and the B-flat below it is nearly 28 Hz, a bigger difference than we saw between B-flat and A; remember that it’s the ratio of frequencies that’s important to our sense of pitch interval.)
Frequency of G#
To get the frequency of pitches below A-440, we just use a negative numerator in the fractional exponent, which means the exponent will be negative, which is equivalent to dividing by the twelfth root of 2 instead of multiplying by it. Here we see the frequency of the G-sharp that’s one step below A-440.
Frequency of A an Octave Up
If we go up 12 steps, we reach the next A, an octave up. 2 to the 12/12 power is 2 to the 1st power, which is just 2, so we get the expected frequency of 880 Hz.
Frequency of A an Octave Down
And if we want the A an octave down, we use 2 to the -12/12 power, which is 2 to the -1st power, which is ½, so we get the expected frequency of 220 Hz.
n steps
So, you can see that to make this formula more generally useful, we just need to consider “steps” to be a variable, so that we can get the frequency of any pitch, just by knowing how many steps it is from A-440.
(For right now, we’ll leave all the other numbers as constants, although you might want to ponder what you could achieve by changing any one of them.)
fn(n) Code
This would be simple to implement as a function in JavaScript, which you could then use to obtain the frequency of any pitch in the 12-tone equal-tempered system.