Question

I found the following piece of code in apple guidelines:

- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
{
    //Use a basic low-pass filter to only keep the gravity in the accelerometer values
    accel[0] = acceleration.x * kFilteringFactor + accel[0] * (1.0 - kFilteringFactor);
    accel[1] = acceleration.y * kFilteringFactor + accel[1] * (1.0 - kFilteringFactor);
    accel[2] = acceleration.z * kFilteringFactor + accel[2] * (1.0 - kFilteringFactor);
}

What does it exactly do? What is this low-pass filter? Why do I have to apply it?

Thank you in advance.

Was it helpful?

Solution

What you need to do depends on what you need the value for, but the basic idea is to reduce the effect of vibrations from hand movements and such. If you take the raw acceleration values and treat them as a gravity vector, you’ll get a lot of jitter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top