tags:

views:

4694

answers:

2

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?

Or better yet post the algorithm?

Thanks!

+15  A: 

From the idevkit.com forums:

#define kFilteringFactor 0.1
UIAccelerationValue rollingX, rollingY, rollingZ;


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

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

    rollingX = (acceleration.x * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor));

    rollingY = (acceleration.y * kFilteringFactor) + (rollingY * (1.0 - kFilteringFactor));

    rollingZ = (acceleration.z * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor));

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

   // Use the acceleration data.

}
Adam Davis
Thanks! I knew I had seen it somewhere
Robert Gould
Thanks, this code helped quite a bit because the snippet on apples developer reference is incorrect (Though apparently it is correct in their accelerometerGraph application)
Thomas
+5  A: 

Just in case someone wants to know, the highpass filter can be found in the Accelerometer Graph sample.

Mike Akers