如何使用移动平均值来滤除iPhone OS中的加速计值 [英] How do you use a moving average to filter out accelerometer values in iPhone OS
问题描述
我想用移动平均值来过滤加速度计值,这是怎么完成的?
Thanks $ / $>
一个简单的单极低通递归IIR滤波器实现起来快速简单
xf = k * xf +(1.0 - k)* x;
yf = k * yf +(1.0 - k)* y;
k
,或者如果您知道所需的截止频率 Fc
,则可以使用公式:
k = 1 - exp(-2.0 * PI * Fc / Fs)
$ c
$ b其中 Fs
是取样率。
请注意,xf,yf是RHS输出信号的前一个值,以及上面表达式的LHS的新输出值。
还要注意,我们在这里假定你将以规则的时间间隔对加速度计信号进行采样,例如每10毫秒。时间常数将是k和这个采样间隔的函数。
I want to filter the accelerometer values using a moving average, how is this done?
Thanks
解决方案 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).
You can determine k
empirically, or if you know your required cut-off frequency, Fc
, then you can use the formula:
k = 1 - exp(-2.0 * PI * Fc / Fs)
where Fs
is the sample rate.
Note that xf, 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.
这篇关于如何使用移动平均值来滤除iPhone OS中的加速计值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!