Maths sticky

Discussion in 'Building With Reaktor' started by jjochems, Apr 26, 2007.

  1. jjochems

    jjochems Forum Member

    Messages:
    126
    Milleseconds to Frequency.

    Anyone remember the formula to convert milleseconds to frequency? Trying to get the clock oscillator to pulse by a designated time of say every 1500ms or other timespans close to that.
     
  2. jjochems

    jjochems Forum Member

    Messages:
    126
    Nevermind, i got it straightened out. Its 1/ms * 1000 for anyone that was curious.
     
  3. CList

    CList Moderator

    Messages:
    3,299
    FWIW, you should think of this like you would simplifying algebraic equations.

    e.g. if you have:
    (3x/y) * (1/x)

    The "x" in the numerator and denominator cancel out and you can simplify it to:
    3/y

    It works the same way with unit conversions if you think of the units as a variable just like "x" in the above equation. You do this stuff in high-school physics all the time.

    So if you know that frequency is measured in Hz. And that Hz are a measure of "per second", then you have the following rules that you know.

    a. Hz = 1/seconds
    b. seconds = 1000 milliseconds

    doing a replacement (inserting formula b into formula a) and working backwards here you get:
    x ms / 1000 = seconds
    Hz = 1000 / x ms

    Using these types of rules you can do any conversion no matter how complex. E.g. you also know...
    a. Sample Rate (sr) = samples/second
    b. BPM = beats / minute
    c. minute = 60 seconds

    therefore, if you need to determine the number of samples / beat, you go step by step, from the formula you know already that includes samples to the formula you know that includes beats, replacing one element at a time...
    (samples / second) * (60 seconds / minute)
    seconds cancel out....
    you now have :
    (samples / minute)

    Now to get rid of the minutes you divide by the BPM...
    (samples / minute) / (beats / minute)
    ...which is the same as: (samples/minute) * (1 / (beats/minute))

    minutes cancel out and you have:
    samples / beat

    so....
    (SR * 60) / BPM = samples / beat

    ...at the current SR and BPM

    - CList
     
  4. sowari

    sowari Moderator Moderator

    Messages:
    27,760
    a thread where Reaktor users share ask and clarify all things Maths in Reaktor.

    see picture

    Tips, have your hints active and use numeric readouts to give you the results in figures... it helps me understand more anyway ;-)

    sowari
     

    Attached Files:

  5. sowari

    sowari Moderator Moderator

    Messages:
    27,760
    so i have a question - you need to see the picture.

    i know this works, in that the resulting pitch is a prefect concert A (A above middle C, A 440 Hz) but why is -300 used as the chosen constant for the pitch? what is the maths behind this?

    sowari
     

    Attached Files:

  6. theologiae

    theologiae NI Product Owner

    Messages:
    652
    i've seen lazyfish use the -300 constant many times, and i always wondered that too.

    here is a pic of his graindelay where the -300 constant pops up in a filter. is this related, or is this something different?
     

    Attached Files:

  7. tubaman

    tubaman NI Product Owner

    Messages:
    789
    I think Clist's post should be added to the math sticky. Seems like it's stuff that just about every wonders about at some point.
     
  8. theologiae

    theologiae NI Product Owner

    Messages:
    652
    and this is something that i have always wanted to know. i understand that the math in vectory is very much linked to how exile likes to do things, not so much how they "should" be done. but there is some basic math that he uses to set the coefficient of the math core level ramp. i have a pic of it. i can see what it all is, but the why is missing me.

    any ideas out there?

    and also, why does he use the word coefficient for most of his builds? what is a coefficient in reaktor and how it is used?
     

    Attached Files:

  9. sowari

    sowari Moderator Moderator

    Messages:
    27,760

    it is related in both cases, as it is the frequency rather than pitch that is being controlled. note that Frequency is an Audio input, thus modulation changes -especially really high frequency modulations - are much more accurate and controllable.

    to clarify, if you want to Frequency Modulate as Oscillator and/or a Filter (to get those bell gong type sounds) you should use F input of a Filter or Oscillator ...oh yes, and the FM Sampler. the P input can be used for LFO wobbles, but for really FM stuff use the F input.

    DSP gurus, feel free to add to this basic explanation ;-)

    sowari
     
  10. herw

    herw NI Product Owner

    Messages:
    6,417
    The answer is very simple. If you don't use the constant of -300 at the pitch input it recognizes Pitch=0 which means (logarithmic scale) a frequency of nearly 8.1758 Hz. So you wouldn't get 440Hz but 448.1758Hz.
    If you use a very low constant f.i. Pitch=-300 you get only 0.000000243578Hz.
    So for Pitch=-300 and f=440Hz you get 440.000000243578...Hz. Reaktor recognizes 440Hz.

    The formula pitch -> frequency is
    Code:
    f=440 * 2^[(p-69)/12]
    
    see german manual of REAKTOR 2.3 ;) p.366 and p. 367.

    the formula frequency -> pitch is
    Code:
    p=69+12*log(f/440)/log(2)
    
    ciao herw
     
    Last edited: Oct 9, 2014
  11. CList

    CList Moderator

    Messages:
    3,299
    First keep in mind that this whole discussion is in the context of creating ramp-type oscillators for either playing back samples or just plain oscillators and has nothing to do with the "coefficient" calculation you find in a filter.


    OK, let's start with the basic question of "what is meant by coefficient?";
    It's the amount that needs to be added to a ramp accumulator on each tick of the sample clock. I don't know if "coefficient" is the best term to use.* I prefer to call this value the "ramp step".

    Now, as for your pic, I can't fully describe all of the motives for what was done since I didn't build the original structure. There are many ways to do the same thing, and each builder has their own styles that they're comfortable with. For starters, you've got one of the ports labeled wrong.
    The lower input is:
    "TempoInfo * 4", not "TempoInfo/4"

    Since TempoInfo is a measure of BPS, multiplying that number by 4 is the number of 1/16th notes per second.

    I'm pretty sure he's trying to get a ramp to go from from 0...x every 1/16th note, where "x" is the number of milliseconds for a 1/16th note *of the recorded sample* at it's original tempo. ...though again, I'm not 100% sure of what the objective was in context. The whole thing with the two ramps getting added together and using the same "coefficient" (step size), along with the mysterious 15000/Tmp part of the structure leaves me baffled. Ultimately, the ramp has to be outputting in ms - since that's what the sample-player is expecting, but in that case I don't get why the SR is being used in the calculation of the step size, unless that number coming in at the 16L input is somehow related to the number of samples long something is - it could be a scaled down value representing the number of samples / 16th note for the original sample - I don't know!

    - CList


    * Most people understand "coeffient" to be the term for the multipliers in polynomial expressions (e.g. in: "ax^2 + bx + c", A,b,c are the coefficients), and I think the use of the term in this context comes from some of the reaktor structures in the standard lib.

    It's most often called a "coefficient" when you have a ramp that's going from 0...1 and in this case it's usually a very small fractional number (on the order of 0.00001). If the counter were going from 0...x samples, where x was some large number (44100 samples in a second of audio), they'd most likely call it "step" or something in their structure and it'd usually have a value at or near 1 - but it's serving the same purpose, and, like I said, regardless of how the ramps being scaled, I like calling this part of the ramp the "step size", "ramp step", or something similar and not the "coefficient".
     
  12. theologiae

    theologiae NI Product Owner

    Messages:
    652
    that all makes a ton of sense.

    one of the things about vectory that confuses my is just that issue, he never factors in the "len" of the sample that is loaded. it's what confuses new comers to it all the time. i had suspected that he was using the 15000/tmp to scale the length of the sample for the ramp, but my understanding is to shaky to get it all.

    thanks for the help, i'm going to keep digging.
     
  13. jjochems

    jjochems Forum Member

    Messages:
    126
    Okay i got another one for you guys. Anyone know how you could set up a Millesecond output to a Envelope stage? By that i mean, If i want the Ramp Envelope to last exactly 5000 ms. What sort of math thread would you have to build for this?
     
  14. herw

    herw NI Product Owner

    Messages:
    6,417
    REAL TIME ENVELOPE (RTE)

    ciao herw
     
  15. CList

    CList Moderator

    Messages:
    3,299
    Envelope-Stage Time In Milliseconds

    If the envelope stage is the decay or release then the amount of time it takes for it to get to zero is effectively infinite (it never goes all the way back to zero). This is because the decay is exponential, it takes "x" milliseconds to get to 50% of it's value, then another "x" ms to get to 50% of that value, and so on. Linear envelope stages, such as the Attack of a standard env or the stages of a ramp env are a different story - you can set the time it will take to reach the next stage exactly.

    Read this thread and all the threads it links to for a detailed discussion of the math/issues involved with reaktor envelopes:

    http://www.native-instruments.com/forum_us/showthread.php?t=36706

    - CList
     
  16. CList

    CList Moderator

    Messages:
    3,299
    By the way, the core P2F module and the primary Exp(P) module should both do Pitch -> Frequency, but they give different results! This is because the precision of the exp() calculation in the core module is set to it's lowest value for CPU saving reasons. You should turn up that precision setting in the macro if you care about getting accurate
    pitch->frequency calculations in core!

    - CList
     
  17. herw

    herw NI Product Owner

    Messages:
    6,417
    yes especially for FM-modulation but i think the primary is more propperly programmed (lower cpu usage in opposite to highest precision in core)
     
  18. CList

    CList Moderator

    Messages:
    3,299
  19. BertAnt

    BertAnt NI Product Owner

    Messages:
    414
    Anyone knows the formula for converting linear amplitude to logarithmic db value ? Thanks in advance.
     
  20. herw

    herw NI Product Owner

    Messages:
    6,417
    ciao herw
     

    Attached Files: