# 2. 1. 1. | ../robertwalker/cents_to_from_ratios | Show tree |
When you add cents, you multiply ratios.
Let c stand for one cent.
Since 1200 cents make one octave, we have:
c1200 = 2.
Let's try to find 5/4 in cents.
Then we want x such that
cx = 5/4.
So taking logs
1200 log c =log 2
and
x log c = log (5/4)
so
x /1200 = log (5/4)/log 2
and so x = 1200 log (5/4)/log 2.
General formula is
value in cents = 1200 log(ratio)/log 2.
Now for the easy way to do it - use a bit of programming.
Lets try to find a close ratio to 350 cents.
As before, let
c1200 = 2.
I.e. c = 21/1200
We want to find c350
I.e. 2350/1200
To do this on a calculator, use the formula
ab = exp(b log(a)).
2cents/1200 = exp((cents/1200)*log 2).
to get
2350/1200
= 1.2240535433
Here the base of the exp and log have to match - either use use exp and ln (natural log) - i.e. the exp and ln buttons on your calculator, or use 10x with log(x).
Both work equally well: e((cents/1200)*ln 2) = 10((cents/1200)*log 2) .
So far so good. But now we are faced with the task of converting this into a near ratio.
Sometimes one can spot a good value fairly easily. This time, we can see immediately that it is close to 1.224, which is roughly half way between 6/5 at 1.2 and 5/4 at 1.25.
So, it's going to be somewhere near 1224/1000 = 153/125, and for some simpler ratios, it is near (6/5+5/4)/2 = (24/20 + 25/20)/2 = 49/40,, and it will also be near the mediant (6+5)/(5+4) = 11/9 as the mediant is also close to the mid-point.
But, are those the best small ratios, and what about closer values? We are going to need a lot of trial and error, and it won't always be this easy to spot nice values!
The solution is to use continued fractions.
To introduce the idea, one way of finding the golden ratio is as [1,1,1,1,1....], which is a continued fraction. It is a short way of writing 1+1/(1+1/(1+....))
The best approximations to the golden ratio are 1, 2, 3/2, 5/3, 8/5,... which you get by calculating successive terms. For instance, 5/3 is 1+1/(1+1/1+1))
It works because of a nice theorem (see Hardy and Wright). Any ratio obtained using the continued fraction algorithm will be closer to the desired value than any other ratio with the same size quotient or smaller.
It's easy to find the continued fraction for any number.
Taking 1.2240535433 as an example, the method is:
Find a = integer part of 1.2240535433 = 1
Find zeta = remainder = 0.2240535433
Continued fraction so far is [1]
Now find
1/zeta = 4.46321885953
a2 = 4
zeta2 = 0.46321885953
Continued fraction now is [1, 4] = 1+1/4
i.e. 5/4
Then repeat the process.
1/zeta2 = 2.15880674853, a3 = 2, zeta3 = 0.15880674853
Continued fraction now is [1, 4, 2] = 1+1/(4+1/2), i.e. 1+2/9 = 11/9.
Lets do one more step
1/zeta3 = 6.29696161691, a4 = 6, zeta4 = 0.29696161691
Continued fraction now is [1, 4, 2, 6] = 1+1/(4+1/(2+1/6))
i.e. 1+1/(4+1/(13/6)) = 1+ 1/(58/13) = 71/58
That works out as 1.22413793103, so we are already getting fairly close to our 1.2240535433
As cents, we have reached 350.119 cents at this stage.
By the continued fraction result, no ratio with a quotient less than 58 can do any better than this.
Now for the easy way again.
Programmers who want to cut and paste the source code can use View Source, as it is in JavaScript, so, embedded in the html.
One might be interested in the closest ratios using a particular prime limit, in which case the continued fraction method won't necessarily give the best result. Even then, it seems that it often works well if the ratios have reasonably small quotients. It will find ones like 7/4, 6/5, 11/8, 35/32, 15/8 etc.
To give an example of where it doesn't work so well, try it for 81/64 = 407.82 cents Test 407.6 cents, and it will find 62/49 and 143/113, but skips over 81/64, which one would be interested as a 3-limit ratio. Enter 407.7 cents and it will find it, but that is rather close!
One way round this is to try multiplying by likely quotients. For instance, you can find 400 cents as 81/64 by multiplying by 64, i.e. adding 6 octaves, to get a cents value of 7600 cents.
To make it easier to try this out, I've added the pre-mult box. For instance, if you pre-multiply by 64, with cents value of 400, you will find 81/64 easily.
Continued fraction basic theorems: http://archives.math.utk.edu/articles/atuyl/confrac/intro.html
Also mentions a nice algorithm for finding the denominator and denumerator for successive terms in a continued fraction as you go along, which is the same as the one used in the code here.For a useful worked example for this algorithm: http://www.ddina.demon.co.uk/maths/tutor/cfv.htm
One classic maths text on number theory, with a chapter on continued fractions, is Hardy and Wright "Introduction to the theory of numbers".