如何为iPhone加速度计实现高通滤波器?

时间:2008-09-27 03:59:42

标签: iphone

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

或者更好的发布算法?

谢谢!

3 个答案:

答案 0 :(得分:36)

From the idevkit.com forums:

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

}

答案 1 :(得分:8)

如果有人想知道,可以在Accelerometer Graph sample中找到高通滤波器。

答案 2 :(得分:1)

这是链接,我也在寻找这个。这是自适应/非自适应高通和低通滤波器的示例:Apple iOS Reference Library - AccelerometerGraph Example