moumenShobakey
moumenShobakey

Reputation: 426

Why do we use low-pass filter to eliminate the gravity effect on the accelerator?

I am trying to do something with the accelerator, i am reading the documentation and it gives the general formula as follows

Ad = -g - ∑F / mass

so i thought we will simply just subtract the gravity value from the result to get the acceleration, but in the documentation it says that we need to use a low-pass filter as follows

 final float alpha = 0.8;

      gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
      gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
      gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];

      linear_acceleration[0] = event.values[0] - gravity[0];
      linear_acceleration[1] = event.values[1] - gravity[1];
      linear_acceleration[2] = event.values[2] - gravity[2];

if any body can explain to me why i'll be thankful

Upvotes: 1

Views: 1029

Answers (1)

Hampus
Hampus

Reputation: 637

It's possible to just subtract the gravity if you know it. There are two reasons why this might be difficult, however. First, the gravity is a vector and the current direction is likely unknown without measuring it. Second, the exact magnitude of the gravity varies by location (and inaccuracies in the sensor).

What the low pass filter does is to estimate the gravity vector for you, since this is almost constant whereas other accelerations are assumed to be temporary. Sudden rotations or constant acceleration that lasts for long could affect the accuracy of this estimate.

To improve the estimate of the gravity, you could try to estimate the direction only and adjust its size or try to combine data from for example a gyro to take rotation into consideration also.

Upvotes: 0

Related Questions