Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - High pass filter equation for accelerometer

Could someone explain how one arrives at the equation below for high pass filtering of the accelerometer values? I don't need mathematical derivation, just an intuitive interpretation of it is enough.

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

    }
like image 446
Boon Avatar asked Nov 29 '22 03:11

Boon


1 Answers

While the other answers are correct, here is an simplistic explanation. With kFilteringFactor 0.1 you are taking 10% of the current value and adding 90% of the previous value. Therefore the value retains a 90% similarity to the previous value, which increases its resistance to sudden changes. This decreases noise but it also makes it less responsive to changes in the signal. To reduce noise and keep it responsive you would need non trivial filters, eg: Complementary, Kalman.

like image 197
Jano Avatar answered Dec 10 '22 11:12

Jano