[chbot] Fast attack, slow decay, filter
Bevin Brett
bevin_brett at hotmail.com
Tue Jun 21 12:26:24 BST 2022
If you think of the input as an array of values with the latest being pushed in the front and the oldest being dropped off the back
v0 v1 v2 v3 v4 v5 ...
and the function as a sum of these values scaled by some position-specific factor sum(vi * si) = a weighted average
then "fast attack" means the first few are multiplied by big factors and the last ones by smaller factors. As Mark said, you could use
0.999**i as your factors, which is easily implemented as
latest out = 0.5 * (latest inp + previous out) - fast decay, not so fast ramp up
or = 0.9 * latest inp + 0.1 * previous out - really fast decay, really fast ramp up,
but possibly what you want is something more like
latest out = F * (average of some of the latest N inputs) + (1-F) ( decaying average of the earlier inputs)
If N is more than 2, and you are using integers, you can implement the first average by keeping the sum of the N inputs, and adding in the new one and subtracting off the one that is falling out into the decaying average
which you could easily do by keeping the latest N inputs in a ring buffer
If your h/w has slow floating point multiply, you may want to use something like integer code "out = 7*inp/8" where the multiply is a few shifts and adds, and the divide is a shift to do the scaling
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20220621/e6fb5da5/attachment.html>
More information about the Chchrobotics
mailing list