你如何使用移动平均值来过滤 iPhone OS 中的加速度计值 [英] How do you use a moving average to filter out accelerometer values in iPhone OS

查看:21
本文介绍了你如何使用移动平均值来过滤 iPhone OS 中的加速度计值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用移动平均值过滤加速度计值,这是如何完成的?谢谢

I want to filter the accelerometer values using a moving average, how is this done? Thanks

推荐答案

一个简单的、单极点、低通、递归的 IIR 滤波器是快速且易于实现的,例如

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;

其中 x, y 是原始(未过滤)X/Y 加速度计信号,xf, yf 是过滤后的输出信号,k 确定过滤器的时间常数(通常为 0.9 和 0.9999 之间的值...,其中k 越大,时间常数越大).

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).

您可以凭经验确定k,或者如果您知道所需的截止频率Fc,则可以使用以下公式:

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)

其中 Fs 是采样率.

请注意,xf、yf 是上式 RHS 上输出信号的先前值,以及上述表达式的 LHS 上的新输出值.

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.

另请注意,我们在这里假设您将以固定的时间间隔对加速度计信号进行采样,例如每 10 毫秒.时间常数将是 k 和采样间隔的函数.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆