PDA

View Full Version : Math help is this possible?

Dgswaner
01-15-2008, 07:37 AM
Is there a way to do this equation on a propeller? 27.5*(1.0594630943593^x) Yes I do need that many decimal places. Before X get very big the difference adds up enough to matter. I only need the answer to be to the 2nd decimal though.

Thanks

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Post Edited (Dgswaner) : 1/14/2008 11:45:11 PM GMT

deSilva
01-15-2008, 08:16 AM
As generally known, nothing is impossible for the Propeller...
The standard floating point imlementation (32 bit) however uses 7 digits only (= 1.059463)
The accuracy also depends on what X should be. A small integer? A large integer? A floating point number?
In the latter case the accuracy of the result will be likewise influenced by the accuracy of that exponent...

Even worse, in that case there is hardly any other possiblility but to use the log/antilog tables for the exponentiation, which will determe the quality of the results eventually.

If X be an integer you could easily extend the floating point algorithm to "double precision" which will be the 16 digits you are requesting.

Post Edited (deSilva) : 1/15/2008 1:22:18 AM GMT

mirror
01-15-2008, 08:58 AM
Would it be worthwhile considering doing a piecewise linear conversion from x to the output value?

As you only need 2 decimal places you may be able to do it with a table of say 100 or less entries - maybe much less depending on the actual requirements.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

VIRAND
01-15-2008, 09:18 AM
Is this for a music synthesizer? Surely I recognize the 12th root of 2 and the very low A note.
If so, perhaps you can start with a High common denominator and first divide out the top octave,
which then can be divided by 2's by counters to get all the lower octaves, with mostly integer math.
Some of the divisions will have remainders.
"If necessary", just divide your remainders by your divisors to include the fraction.

As I wrote above:
N=2_002_400 Hz (THE common denominator frequency)

C=N/478 (high octave frequencies: )
C#=N/451
D=N/436
D#=N/402
E=N/379
F=N/358
G=N/338
G#=N/319
A=N/301
A#=N/284
B=N/268
B#=n/253

C=N/239 ... or C=C/2 or C=C/4 or C=C/8 or C=C/16 for lower octave's
- thus counting in binary does all octave divisions for all "C" notes (for example) at once.

I think a Moog instrument used that technique and that integer common denominator frequency.
It should be very accurate and stable.

deSilva
01-15-2008, 09:24 AM
@VIRAND : quite ingenious! This shows again how important it is to state the problem, rather than what one thinks is the problem http://forums.parallax.com/images/smilies/smile.gif

Dgswaner
01-15-2008, 09:25 AM
X will be an integer between 1 and 88.

I was trying to get away from a 88 statement long case statement but it might be what happens. if that formula would work it would only take a small object file (with the frequency synth object) to do a 88 note synthesizer. 1-88 would be the keys from left to right.

This would make it really easy to write songs with the propeller.

the decimal place doesn't become a factor until about ^15+ that's more than an octave so perhaps the formula could be adjusted per octave. rather than start with 27.5 you could start somewhere else in the sequence and the drift wouldn't be noticeable. but I was hoping not to get a work around.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Dgswaner
01-15-2008, 09:31 AM
sweet we must have been writing at the same time. I'll see if I can get the actual code to work.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Paul Baker
01-15-2008, 10:56 AM
I think an 88 element lookup table is your easiest solution, even in assembly with the table residing in the hub it would be faster than calculating it directly every time.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker (mailto:pbaker@parallax.com)
Propeller Applications Engineer
[/url][url=http://www.parallax.com] (http://www.parallax.com)
Parallax, Inc. (http://www.parallax.com)

Phil Pilgrim (PhiPi)
01-15-2008, 11:48 AM
A lookup table is definitely the way to go. It really needs only twelve entries for the frequencies, since the notes in the lower octaves will be the equivalent notes in the highest octave, shifted right by the number of octaves lower. (This is the method I used in the SoundPAL, BTW, to reduce memory requirements.) The Propeller's barrel shifter makes this a cinch.

-Phil

Tracy Allen
01-15-2008, 02:59 PM
I agree about the lookup table as a practical matter. However, as question of "math help, is it possible", I think yes, with sufficient accuracy, using integer math.

PUB shownotes
x := 35200000 ' A7 * 10000, high note to start, but note extra significant figures are necessary to avoid buildup of error
repeat 85
noteFreq := x/100 ' drop two extra significant figures for display, keep two past decimal
fulldplxplus.dec(noteFreq) ' show frequency *100
fulldplxplus.tx(CR)
x := x ** 4053909305 ' multiply times 4053909305 / 4294967296 = 1 / 1.0594631 using ** operator

to show...

352000 ' A7 3520.00 Hz
332244
313596
295996
279383
263702
248902
234932
221746
209300
197553
186465
176000 A6 1760.00 Hz
... etc.
4120
3889
3671
3465
3270
3087
2913
2750 A0 27.5 Hz

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com (http://www.emesystems.com)

Dgswaner
01-15-2008, 11:34 PM
Phil, I don't quite get how I can only have 12 values in the table. and what you mean by shifting right? I see that each column would be 12 notes long so C4 being 0 C5 is +12 C6 is +24 etc. But I don't get how to modify the frequency based on how many time you shift right.

This is over my head a bit but I am trying to learn so if you would bear with me I would appreciate it.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

01-16-2008, 12:12 AM
A shift right is a divide by two.

eg: 12 = %1100 if you shift every bit to the right, once, then you get: 6 = %110, where the right most digit just goes away.

Shift left is multiply by two.

Your base table then equals one octave, and the number of shifts relate to other octaves, and the divide necessary to derive the value from the base table.

Think of it the same way you do the zero in ordinary decimal math. If you've got 1200, and you shift right, the right most digit goes away, leaving 120, which is a divide by 10.

And a shift left, in decimal, would be a multiply by 10.

Each octave equals one shift then, with multipliers being, 2, 4, 8, etc... Same for divisors, depending on what you need to do.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)

Dgswaner
01-16-2008, 12:49 AM
ok the the Light just turned on!!! so if my look up table, I have the upper active frequency values, to go from A7 to A0 I divide A7 by 2, 7 times. or the equivalent, in decimal Binary... if I shift the values to the right, 7 times. ok I'm a little slow.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Post Edited (Dgswaner) : 1/15/2008 6:21:15 PM GMT