Removing drift from integration of accelerometer data I am trying to get a positional data from the accelerometer data using the following steps:


Re-zero the accelerometer value
Removing mean from accelerometer value
First integration of accelerometer value to get velocity
Removing mean from velocity
Integrate velocity to get position


, and the following is the result from every integration value:



Can anyone suggest on how to remove the drift appear on the velocity value? Some suggest to push the velocity value to zero when accelerometer value is near to zero but I don't think this is very robust.
Double integration amplifies any offsets, non-linearities and noise.  These can't be removed without the use of some type of external reference point measurements (e.g. not from the accelerometer) or other information.  Calibration might be able to remove most of the ones that do not vary with time (temperature, etc.)  

For instance, if the size of the room is known, you can robustly clamp position to be inside the walls and above the floor.