[sdiy] Help with math, please

Magnus Danielson magnus at rubidium.dyndns.org
Tue Aug 9 23:57:53 CEST 2011


On 09/08/11 18:18, Tim Ressel wrote:
> Hi,
>
> Okay, I admit it: math is not my strong suit, and I need help with a problem. I am trying to program a cv envelope generator with exponential and linear curves. The linear part works just fine, but I am having a real hard time wrapping my neurons around the exponential part.
>
> The way I've implemented the code is this: there is an accumulator that values get added or subtracted to at each time slice, which is 1ms currently. An ADC value adjusts the amount that gets added. In the case of the exponential curve I am trying to use the RC time constant equation to calculate the value to add to the accumulator. The thing is, the RC time constant formula calculates from time zero, and I need an incremental value. So given the current accumulator value (analogous to voltage on the cap) and the current ADC value (the RC value) I need an equation that gives an increment value to add to the accumulator.
>
> Any math whizzes out there that can help?

Considering that your accumulator value is A and target value (input) is 
T and TC is your time-constant, then you do

A = A + TC*(T-A)

As the difference between the target value and accumulator value becomes 
smaller, the increments becomes smaller.

Is that easy enough for you?

Cheers,
Magnus



More information about the Synth-diy mailing list