I want to filter the accelerometer values using a moving average, how is this done? Thanks
views:
553answers:
1
+2
A:
A simple, single pole, low pass, recursive IIR filter is quick and easy to implement, e.g.
xf = k * xf + (1.0 - k) * x;
yf = k * yf + (1.0 - k) * y;
where x, y are the raw (unfiltered) X/Y accelerometer signals, xf, yf are the filtered output signals, and k determines the time constant of the filters (typically a value between 0.9 and 0.9999..., where a bigger k means a longer time constant).
Note that xy, yf are the previous values of the output signal on the RHS, and the new output values on the LHS of the expression above.
Note also that we are assuming here that you will be sampling the accelerometer signals at regular time intervals, e.g. every 10 ms. The time constant will be a function both of k and of this sampling interval.
Paul R
2010-02-16 11:41:31
so x and y are the accelerometer.x and accelerometer.y, I am confused, i dont no what 'raw input signal' is. :/
DotSlashSlash
2010-02-16 11:45:10
No, y is the filtered signal, x is what the accelerometer gave. It would be clearer to write that `xf = k*xf + (1.0-k)*x` where xf is the filtered version of x, and a similar equation for the y axis.
Andrew McGregor
2010-02-16 11:48:53
@Andrew - thanks for the suggestion - now edited for improved clarity (I hope !).
Paul R
2010-02-16 12:10:13