Let's say I have the note A 440Hz and the frequency 450Hz. How do I calculate the distance in cents between that note and that frequency?
c = 1200 × log2(f1/f0)
The frequency f of a note n semitones away from A4 is (Wikipedia):
f = 2n/12 × 440 Hz
More generally, to calculate one frequency from another based on their distance in semitones:
f1 = 2n/12 × f0
To answer your question, solve for n to get semitones:
n = 12 × log2(f1/f0)
And multiply by 100 for cents:
c = 1200 × log2(f1/f0)
Given your example, the distance in cents between 440 Hz and 450 Hz:
c = 1200 × log2(440/450)
c = –38.9
so 440 Hz is about 39 cents below 450 Hz.
For more information, see the mathematics of musical scales. There’s also some information about the logarithmic scale in the linked entry for musical cents.
The first formula shown on you wiki link is the one you want:
From wiki:
""If one knows the frequencies a and b of two notes, the number of cents measuring the interval from a to b may be calculated by the following formula (similar to the definition of decibel):
Likewise, if one knows a note a and the number n of cents in the interval from a to b, then b may be calculated by:
E.G. for your given two frequencies, 440Hz and 450Hz
3986*log(450/440)= 38.9 cents
and in the other direction:
3986*log(440/450)= -38.9 cents
And checking our answer with the second formula:
440*2^(38.9/1200) = 450.0 Hz
-
1+1 for putting it in functions you can actually find on a calculator. However it might be worth pointing out that log2(b/a) = log10(b/a)/log10(2) = ln(b/a)/ln(2). Thus the correct value of the constant 3986 is 1200/log10(2)=3986.31371 etc. The fundamental maths is easier to remember than a mysterious constant. – Level River St May 17 '14 at 3:41