javascript - Damping of value fluctuation, filtering out spikes -
i'm working physics in javascript , have value indicating number of contacts in "physical" world. value can between 0 - 6. problem fluctuates lot. want filter out spikes. number 3 , fraction of second changes 0 , 3 again. ideas how best this?
a fit can median filter in sliding window. consider last n values, n @ least twice duration of drop. filtered value median of n. repeat forever n samples shifted 1 position.
as values discrete in tiny range, median algorithm simple. keep histogram of 7 possible values, i.e. 7 counters. whenever shift 1 position, count down oldest value , count new. median value such cumulated counts reaches n/2.
there inertia, i.e. true changes take time acknowledged, unavoidable because algorithm needs confirm permanent change vs. temporary drop.
Comments
Post a Comment