Shop OBEX P1 Docs P2 Docs Learn Events
Math help is this possible? — Parallax Forums

Math help is this possible?

DgswanerDgswaner Posts: 795
edited 2008-01-15 16:54 in Propeller 1
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

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2008-01-15 00:16
    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
  • mirrormirror Posts: 322
    edited 2008-01-15 00:58
    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.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • VIRANDVIRAND Posts: 656
    edited 2008-01-15 01:18
    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.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-15 01:24
    @VIRAND : quite ingenious! This shows again how important it is to state the problem, rather than what one thinks is the problem smile.gif
  • DgswanerDgswaner Posts: 795
    edited 2008-01-15 01:25
    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
  • DgswanerDgswaner Posts: 795
    edited 2008-01-15 01:31
    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 BakerPaul Baker Posts: 6,351
    edited 2008-01-15 02:56
    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
    Propeller Applications Engineer

    Parallax, Inc.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-15 03:48
    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 AllenTracy Allen Posts: 6,662
    edited 2008-01-15 06:59
    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
  • DgswanerDgswaner Posts: 795
    edited 2008-01-15 15:34
    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
  • potatoheadpotatohead Posts: 10,261
    edited 2008-01-15 16:12
    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!
  • DgswanerDgswaner Posts: 795
    edited 2008-01-15 16:49
    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
  • potatoheadpotatohead Posts: 10,261
    edited 2008-01-15 16:54
    Sweet! Now you are cooking.

    Who cares about slow. It's about fun!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
Sign In or Register to comment.