Accelerometer + Gyro - Help?

Hello!

first sorry for any physics errors, but i nedd help.

Well, im using accelerometer data, but got a problem to "compensate" gravity.

searching in internet i found an equation that get the quaternions and get the gravity for axis.
But they quaternions are derived from gyroscope, and the gyroscope has an oscillation in the moment of the movement and after back to "normal state". And this is so bad for me.

The equation:

gx = 2 * (q1q3 - q0q2);
gy = 2 * (q0q1 + q2q3);
gz = q0q0 - q1q1 - q2q2 + q3q3;

And i execute every when the gyroscope has a change.

The result is good when i do a moviment, but when the gyroscope back to the "normal" state the gravity back too.

Sorry for my bad english.

To subtract the acceleration due to gravity you need to know the orientation of the sensor very accurately. This software package will do that, if you have a 9 DOF sensor.

It also includes a function to remove the gravity vector, but the author explains why this usually does not work well: https://richardstechnotes.wordpress.com/2015/02/26/this-is-why-trying-to-measure-position-with-a-mems-9-dof-imu-is-doomed-to-failure/