back to list

Re: Hz to Ratios

🔗Patrick Pagano <ppagano@xxxxxxxxx.xxxx>

3/12/1999 7:18:08 AM

Can someone give me an easy way to generate a ratio from a cps or a hz value? I
have a friend that was asking about this equation and wanted some input/other
methods to help him out-so I said I'd post it to you all>
Thanks
Pat
SEJIS

🔗Paul Hahn <Paul-Hahn@xxxxxxx.xxxxx.xxxx>

3/12/1999 7:33:50 AM

On Fri, 12 Mar 1999, Patrick Pagano wrote:
> Can someone give me an easy way to generate a ratio from a cps or a hz value? I

There is no such way, because ratios represent intervals, and a Hz value
is only a single pitch. (I know we often use ratios here to represent
pitches, but that's always within the context of a scale, in which case
the interval is between the pitch and the root of the scale.)

If you have _two_ Hz values, however, generating a ratio is simplicity
itself--simply divide one into the other.

Well, sort of. If you want a _simple_ ratio, you may have a tricky task
of deciding what simple ratio is best approximated by the (sometimes
rather funky) actual ratio you got from the previous paragraph. Many
bytes have been spilled in this forum on _that_ particular problem.

--pH <manynote@lib-rary.wustl.edu> http://library.wustl.edu/~manynote
O
/\ "How about that? The guy can't run six balls,
-\-\-- o and they make him president."

NOTE: dehyphenate node to remove spamblock. <*>

🔗Peter Mulkers <P.Mulkers@xxx.xxxx>

3/12/1999 12:14:18 PM

> From: Patrick Pagano <ppagano@bellsouth.net>
>
>
> Can someone give me an easy way to generate a ratio from a cps or
> a hz value? I have a friend that was asking about this equation
> and wanted some input/other methods to help him out
> -so I said I'd post it to you all>
> Thanks
> Pat
> SEJIS

Like Paul Hahn said, you need at least two hz values to have a ratio.
When you divide one into the other , you get an decimal ratio.

I found an algorithm to find the exact fraction of a decimal ratio.

Step 1 :
Write this decimal number down.
You'll need it later on.

Step 2 :
Take only the frac of this decimal number.
(frac = everything what's behind the decimal point)

Step 3 :
Divide the number 1 by this frac.

Step 4 :
Now you get a new decimal number.
Go back to Step 1 and continue.

You have to go back and continue until the frac you get is equal zero.
Then you have to multiply all these decimal numbers you wrote down
with each other. The result you get is one part of the fraction.
To get the other part, divide the first part by the decimal ratio.

Example:

first given hz value : 330Hz
second given hz value: 210Hz

decimal ratio : 330/210 = 1.57142 ...
1/(0.57142 ...) = 1.75
1/(0.75 ) = 1.33333 ...
1/(0.33333 ...) = 3
____________*
11

11/(1.57142 ...) = 7

Result: 330Hz/210Hz = 11/7

Peter Mulkers

🔗Paul Hahn <Paul-Hahn@xxxxxxx.xxxxx.xxxx>

3/12/1999 12:32:47 PM

On Fri, 12 Mar 1999, Peter Mulkers wrote:
> I found an algorithm to find the exact fraction of a decimal ratio.
[snip]

Congratulations, Peter!--you've just discovered the basic idea of
continued fractions.

--pH <manynote@lib-rary.wustl.edu> http://library.wustl.edu/~manynote
O
/\ "How about that? The guy can't run six balls,
-\-\-- o and they make him president."

NOTE: dehyphenate node to remove spamblock. <*>

🔗fasano@xxxxx.xxxxxxxxxxxxxxx)

3/12/1999 1:04:12 PM

At 09:14 PM 3/12/99 +0100, you wrote:
>From: "Peter Mulkers" <P.Mulkers@gmx.net>
>
>
>> From: Patrick Pagano <ppagano@bellsouth.net>
>>
>>
>> Can someone give me an easy way to generate a ratio from a cps or
>> a hz value? I have a friend that was asking about this equation
>> and wanted some input/other methods to help him out
>> -so I said I'd post it to you all>
>> Thanks
>> Pat
>> SEJIS
>
>
>Like Paul Hahn said, you need at least two hz values to have a ratio.
>When you divide one into the other , you get an decimal ratio.
>
>I found an algorithm to find the exact fraction of a decimal ratio.
>
> Step 1 :
> Write this decimal number down.
> You'll need it later on.
>
> Step 2 :
> Take only the frac of this decimal number.
> (frac = everything what's behind the decimal point)
>
> Step 3 :
> Divide the number 1 by this frac.
>
> Step 4 :
> Now you get a new decimal number.
> Go back to Step 1 and continue.
>
>You have to go back and continue until the frac you get is equal zero.
>Then you have to multiply all these decimal numbers you wrote down
>with each other. The result you get is one part of the fraction.
>To get the other part, divide the first part by the decimal ratio.
>
>
>Example:
>
>first given hz value : 330Hz
>second given hz value: 210Hz
>
>decimal ratio : 330/210 = 1.57142 ...
> 1/(0.57142 ...) = 1.75
> 1/(0.75 ) = 1.33333 ...
> 1/(0.33333 ...) = 3
> ____________*
> 11
>
> 11/(1.57142 ...) = 7
>
>Result: 330Hz/210Hz = 11/7
>
>
>Peter Mulkers
>
>
Here's C code to do that:

#include <stdio.h>
#include <math.h>

void main(int argc, char **argv)
{
double m,d;
double n1, n2;
double n;
double intPart,frac;

if (argc != 3)
{
printf("Usage: GENRATIO n1 n2\n");
return;
}

n1 = atof(argv[1]);
n2 = atof(argv[2]);

for (m = d = n = n1 / n2;
(frac = modf(n,&intPart)) > 0.00001;
m *= (n = 1.0 / frac)) {}

printf("%d/%d\n",(int)m,(int)(m / d));
}

Ken Fasano

🔗Patrick Pagano <ppagano@xxxxxxxxx.xxxx>

3/12/1999 4:58:38 PM

Thanks for the help Paul --I felt a little silly asking cause it seems so easy going
to Hz and I had never needed to go the other way --until now.
Pat

Paul Hahn wrote:

> From: Paul Hahn <Paul-Hahn@library.wustl.edu>
>
> On Fri, 12 Mar 1999, Patrick Pagano wrote:
> > Can someone give me an easy way to generate a ratio from a cps or a hz value? I
>
> There is no such way, because ratios represent intervals, and a Hz value
> is only a single pitch. (I know we often use ratios here to represent
> pitches, but that's always within the context of a scale, in which case
> the interval is between the pitch and the root of the scale.)
>
> If you have _two_ Hz values, however, generating a ratio is simplicity
> itself--simply divide one into the other.
>
> Well, sort of. If you want a _simple_ ratio, you may have a tricky task
> of deciding what simple ratio is best approximated by the (sometimes
> rather funky) actual ratio you got from the previous paragraph. Many
> bytes have been spilled in this forum on _that_ particular problem.
>
> --pH <manynote@lib-rary.wustl.edu> http://library.wustl.edu/~manynote
> O
> /\ "How about that? The guy can't run six balls,
> -\-\-- o and they make him president."
>
> NOTE: dehyphenate node to remove spamblock. <*>
>
> ------------------------------------------------------------------------
> Start a new hobby. Meet a new friend.
> http://www.onelist.com
> Onelist: The leading provider of free email list services
> ------------------------------------------------------------------------
> You do not need web access to participate. You may subscribe through
> email. Send an empty email to one of these addresses:
> tuning-subscribe@onelist.com - subscribe to the tuning list.
> tuning-unsubscribe@onelist.com - unsubscribe from the tuning list.
> tuning-digest@onelist.com - switch your subscription to digest mode.
> tuning-normal@onelist.com - switch your subscription to normal mode.

🔗Patrick Pagano <ppagano@xxxxxxxxx.xxxx>

3/12/1999 5:04:55 PM

Thanks Peter that really helps
I appreciate it
Resonate and Extenuate
Pat

Peter Mulkers wrote:

> From: "Peter Mulkers" <P.Mulkers@gmx.net>
>
> > From: Patrick Pagano <ppagano@bellsouth.net>
> >
> >
> > Can someone give me an easy way to generate a ratio from a cps or
> > a hz value? I have a friend that was asking about this equation
> > and wanted some input/other methods to help him out
> > -so I said I'd post it to you all>
> > Thanks
> > Pat
> > SEJIS
>
> Like Paul Hahn said, you need at least two hz values to have a ratio.
> When you divide one into the other , you get an decimal ratio.
>
> I found an algorithm to find the exact fraction of a decimal ratio.
>
> Step 1 :
> Write this decimal number down.
> You'll need it later on.
>
> Step 2 :
> Take only the frac of this decimal number.
> (frac = everything what's behind the decimal point)
>
> Step 3 :
> Divide the number 1 by this frac.
>
> Step 4 :
> Now you get a new decimal number.
> Go back to Step 1 and continue.
>
> You have to go back and continue until the frac you get is equal zero.
> Then you have to multiply all these decimal numbers you wrote down
> with each other. The result you get is one part of the fraction.
> To get the other part, divide the first part by the decimal ratio.
>
> Example:
>
> first given hz value : 330Hz
> second given hz value: 210Hz
>
> decimal ratio : 330/210 = 1.57142 ...
> 1/(0.57142 ...) = 1.75
> 1/(0.75 ) = 1.33333 ...
> 1/(0.33333 ...) = 3
> ____________*
> 11
>
> 11/(1.57142 ...) = 7
>
> Result: 330Hz/210Hz = 11/7
>
> Peter Mulkers
>
> ------------------------------------------------------------------------
> If you like orange and blue, then you will love our new web site!
> http://www.onelist.com
> Onelist: Fostering connections and information exchange
> ------------------------------------------------------------------------
> You do not need web access to participate. You may subscribe through
> email. Send an empty email to one of these addresses:
> tuning-subscribe@onelist.com - subscribe to the tuning list.
> tuning-unsubscribe@onelist.com - unsubscribe from the tuning list.
> tuning-digest@onelist.com - switch your subscription to digest mode.
> tuning-normal@onelist.com - switch your subscription to normal mode.

🔗Patrick Pagano <ppagano@xxxxxxxxx.xxxx>

3/12/1999 5:06:20 PM

Thanks Ken
I appreciate the Help
Resonate and Extenuate
Pat

Ken Fasano wrote:

> From: fasano@sysar.com (Ken Fasano)
>
> At 09:14 PM 3/12/99 +0100, you wrote:
> >From: "Peter Mulkers" <P.Mulkers@gmx.net>
> >
> >
> >> From: Patrick Pagano <ppagano@bellsouth.net>
> >>
> >>
> >> Can someone give me an easy way to generate a ratio from a cps or
> >> a hz value? I have a friend that was asking about this equation
> >> and wanted some input/other methods to help him out
> >> -so I said I'd post it to you all>
> >> Thanks
> >> Pat
> >> SEJIS
> >
> >
> >Like Paul Hahn said, you need at least two hz values to have a ratio.
> >When you divide one into the other , you get an decimal ratio.
> >
> >I found an algorithm to find the exact fraction of a decimal ratio.
> >
> > Step 1 :
> > Write this decimal number down.
> > You'll need it later on.
> >
> > Step 2 :
> > Take only the frac of this decimal number.
> > (frac = everything what's behind the decimal point)
> >
> > Step 3 :
> > Divide the number 1 by this frac.
> >
> > Step 4 :
> > Now you get a new decimal number.
> > Go back to Step 1 and continue.
> >
> >You have to go back and continue until the frac you get is equal zero.
> >Then you have to multiply all these decimal numbers you wrote down
> >with each other. The result you get is one part of the fraction.
> >To get the other part, divide the first part by the decimal ratio.
> >
> >
> >Example:
> >
> >first given hz value : 330Hz
> >second given hz value: 210Hz
> >
> >decimal ratio : 330/210 = 1.57142 ...
> > 1/(0.57142 ...) = 1.75
> > 1/(0.75 ) = 1.33333 ...
> > 1/(0.33333 ...) = 3
> > ____________*
> > 11
> >
> > 11/(1.57142 ...) = 7
> >
> >Result: 330Hz/210Hz = 11/7
> >
> >
> >Peter Mulkers
> >
> >
> Here's C code to do that:
>
> #include <stdio.h>
> #include <math.h>
>
> void main(int argc, char **argv)
> {
> double m,d;
> double n1, n2;
> double n;
> double intPart,frac;
>
> if (argc != 3)
> {
> printf("Usage: GENRATIO n1 n2\n");
> return;
> }
>
> n1 = atof(argv[1]);
> n2 = atof(argv[2]);
>
> for (m = d = n = n1 / n2;
> (frac = modf(n,&intPart)) > 0.00001;
> m *= (n = 1.0 / frac)) {}
>
> printf("%d/%d\n",(int)m,(int)(m / d));
> }
>
> Ken Fasano
>
> ------------------------------------------------------------------------
> Have you visited our new web site?
> http://www.onelist.com
> Onelist: Helping to create Internet communities
> ------------------------------------------------------------------------
> You do not need web access to participate. You may subscribe through
> email. Send an empty email to one of these addresses:
> tuning-subscribe@onelist.com - subscribe to the tuning list.
> tuning-unsubscribe@onelist.com - unsubscribe from the tuning list.
> tuning-digest@onelist.com - switch your subscription to digest mode.
> tuning-normal@onelist.com - switch your subscription to normal mode.