[chbot] Fast attack, slow decay, filter

Trevor Wignall zl3adz at gmail.com
Tue Jun 21 14:10:47 BST 2022


The fastest way of doing the multiply by 7 in Bevin's example is probably
to avoid it. Rather than calculating vout = 7/8*vin, calculate vout = vin -
(vin >> 3).

You want to avoid multiplying by numbers near unity as you can run out of
resolution. Calculating the amount to add or subtract can be done with less
precision until the final addition or subtraction.

Trevor

On Tue, Jun 21, 2022 at 11:26 PM Bevin Brett <bevin_brett at hotmail.com>
wrote:

> 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
>
>
>
>
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.ourshack.com
> https://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Meetings usually 3rd Monday each month. See http://kiwibots.org for
> venue, directions and dates.
> When replying, please edit your Subject line to reflect new subjects.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20220622/9afb31db/attachment-0003.html>


More information about the Chchrobotics mailing list