# How to use accelaration data of moving object to calculate distance?

I read couple of similar question on this forum and few blogs on web, though I am still confused,I am determined to calculate object displacement using accelerometer data.

So, I tried using www.freescale.com/files/sensors/doc/app_note/AN3397.pdf , which gives nearly 20-50% error.

I also tried this equation on data and got some better results.

V1 = V0 + ((a1) * t)
X2 = abs((V1 * t) + (((a1)/2)*t*t))
X2 = X0 + X2
V0 = V1
X0 = X2


Here t is the time differance between two samples. X0 is the final displacement. V1,a1 current values. V0 previous value.

Here is my graphs for the movement from Android sensors readings.

1)From Linear Acceleration Z axis graph, how do I calculate the distance? 2)Which values should I take and which should not? how many data samples I should use for calculation. For positive acceleration only or for an entire positive negative cycle of acceleration data? 3) What the Linear acceleration graph means. Please explain its values based on movement of object.

Nulling gravity is an enormous problem, unless your accelerometer is perfectly perpendicular to Earth's gravity vector! The accelerations you want to measure are probably on the order of $1m/s^2$ or less, right? That is overlaid by $\vec{g}=9.81m/s^2\vec{z}$. Before you can even estimate the displacement causing acceleration your are interested in, you have to determine angles of your three accelerometer channels relative to $\vec{g}$, then subtract $\vec{g}$. Thankfully that procedure will give you a direction towards the floor... however, you still don't know which way your $\vec{x}$ and $\vec{y}$ axes are pointing! Your accelerometer could be turning around 180 degrees while it is accelerating... and the real displacement could end up in the opposite direction of where you thought it was going. Now, a perfect acceleration sensor would not even be sensitive to this rotation, for that you would need a different sensor that can detect rotations! Such a gyroscope may, or may not be built into your device. Given the way most accelerometer chips are implemented, gyroscopes and accelerometers will not even sample synchronously, which means that you need to have a digital resampling filter in place to correlate the readings of both sensors to get a reliable six axis position/orientation vector. I don't think that the Android platform gives you enough information to do that, right now. iOS might... on newer phones and tablets which have both sensors.
Having said that, if you want to simplify things to the level you are on, right now, you can (theoretically) mount your cell phone on a straight rail, carefully rotate it, until the motion vector points exactly in the direction of one of the accelerometer axes, and that axis is perpendicular to $\vec{g}$ and then you can apply a good numerical integration algorithm to what it measures on one axis, like one of the higher order integrators described by http://mathworld.wolfram.com/NumericalIntegration.html.