One problem with exponentially weighted moving averages is that the weight that older samples decays sharply even for very recent samples.
The impulse response of such an average shows this clearly. In the graph to the right, the red line is the impulse response of the exponential weighted average is shown by the red line. The impulse response of a different kind of moving average derived by John Canny in the early 80's is shown by the black line.
The Canny filter puts higher weight on the events in the recent past which makes it preferable when you don't want to forget things right away, but do want to forget them before long and also want an on-line algorithm.
The cool thing about the Canny filter is that it is only twice as much work as a simple exponential moving average. The idea is that if you take the difference between two exponentially weighted averages with different time constants, you can engineer things to give you an impulse response of the sort that you would like.
The formula for such a difference looks like this
w(x)=k1e−x/α−k2e−x/β
Here k1 and k2 scale the two component filters in magnitude and α and β are the time constants for the filters.
It is nice to set the magnitude of the filter at delay 0 to be exactly 1. We can use this to get a value for k2 in terms of k1
w(0)=k1−k2=1k2=k1−1
Similarly, we can constrain the slope of the impulse response to be 0 at delay 0. This gives us β in terms α
w′(0)=k1α−k2β=0k1α=k1−1ββ=αk1−1k1
The final result is this impulse response
w(x)=kexp(−xα)−(k−1)exp(−kxα(k−1))
We can do a bit better if we note that as k→∞, the shape of the impulse quickly converges to a constant shape with mean of w(x)→3a2 and a total volume of 2a.
Sunday, May 29, 2011
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment