[sdiy] Help with math, please

Scott Gravenhorst music.maker at gte.net
Tue Aug 9 20:37:21 CEST 2011


Tim Ressel <madhun2001 at yahoo.com> 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?

I hope this is addressing your question.

I'm assuming digital...  No math whiz here, but I have implemented
exponential curves in envelope generators.  What I did was to digitally
implement an RC circuit, that is, a single pole IIR lowoass filter. 
The formula here is y = a0 * target + b1 * y.  "target" is the target
value you wish to reach (the asymptote value).  b1 = 1.0 - a0, but I
don't know how to compute seconds from that.  What I did was just to
leave the b1 (or "delay" value) as an arbitrary number - if I don't
like it - I change it until I do.  "y" which is both the output value
and the memory value (z^-1) can also be preloaded with a starting
value.  Eg, y set to 0.5 and target set to 0.0 causes an envelope
starting at 0.5 and decaying exponentially to 0.0.


-- ScottG
________________________________________________________________________
-- Scott Gravenhorst
-- FPGA MIDI Synthesizer Information: 
   jovianpyx.dyndns.org:8080/public/FPGA_synth/
-- FatMan: 
   jovianpyx.dyndns.org:8080/public/fatman/
-- NonFatMan: 
   jovianpyx.dyndns.org:8080/public/electronics/
-- When the going gets tough, the tough use the command line.




More information about the Synth-diy mailing list