如何为iPhone加速度计实现高通滤波器? [英] How do you implement a Highpass filter for the IPhone accelerometer?

查看:321
本文介绍了如何为iPhone加速度计实现高通滤波器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我记得几天前在样本的某个地方看到了高通滤波器的代码,但是我现在无法在任何地方找到它!有人能记得我在Highpass过滤器实现代码的位置吗?

I remember seeing the code for a Highpass filter a few days back somewhere in the samples, however I can't find it anywhere now! Could someone remember me where the Highpass filter implementation code was?

或者更好的发布算法?

谢谢!

推荐答案

来自idevkit.com论坛:

#define kFilteringFactor 0.1
static UIAccelerationValue rollingX=0, rollingY=0, rollingZ=0;


- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {

    // Calculate low pass values

    rollingX = (acceleration.x * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor));
    rollingY = (acceleration.y * kFilteringFactor) + (rollingY * (1.0 - kFilteringFactor));
    rollingZ = (acceleration.z * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor));

    // Subtract the low-pass value from the current value to get a simplified high-pass filter

    float accelX = acceleration.x - rollingX;
    float accelY = acceleration.y - rollingY;
    float accelZ = acceleration.z - rollingZ;

    // Use the acceleration data.

}

这篇关于如何为iPhone加速度计实现高通滤波器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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