Calculate vertical distance using acceleration I have the following scenario: an iPhone is connected to a vertical rail (it's motion is restricted to the Y axis). Through mechanical means the phone is forced upwards and then allowed to return to rest. The distance varies (anywhere from 6" to 24"). The total time required for the full trip is roughly 1 - 2 seconds. The goal is to estimate the distance the device travels.
I have read through both:
Calculation of Distance from measured Acceleration vs Time
Getting position from an accelerometer on an Android phone
(although I must admit that it is been years since I've had to deal directly with these topics)
Currently I am collecting acceleration data (along the Y axis) and use the following to estimate the integral of acceleration and velocity (via Excel):
1  Time [A]  Acceleration [B]   Velocity [C]                Distance [D]
2  0         a(z)               0                           0
3  1         a(z)               =C2+(A3-A2)*(B2+B3)/2       =D2+(A3-A2)*(C2+C3)/2
4  2         a(z)               =C3+(A4-A3)*(B3+B4)/2       =D3+(A4-A3)*(C3+C4)/2
5  3         a(z)               =C4+(A5-A4)*(B4+B5)/2       =D4+(A5-A4)*(C4+C5)/2
6  4         a(z)               =C5+(A6-A5)*(B5+B6)/2       =D5+(A6-A5)*(C5+C6)/2
7  5         a(z)               =C6+(A7-A6)*(B6+B7)/2       =D6+(A7-A6)*(C6+C7)/2
8  6         a(z)               =C7+(A8-A7)*(B7+B8)/2       =D7+(A8-A7)*(C7+C8)/2
9  7         a(z)               =C8+(A9-A8)*(B8+B9)/2       =D8+(A9-A8)*(C8+C9)/2
10 8         a(z)               =C9+(A10-A9)*(B9+B10)/2     =D9+(A10-A9)*(C9+C10)/2
11 9         a(z)               =C10+(A11-A10)*(B10+B11)/2  =D10+(A11-A100)*(C10+C11)/2
12 10        a(z)               =C11+(A12-A11)*(B11+B12)/2  =D11+(A12-A11)*(C11+C12)/2
   ...       ...                ...                         ...

Here is a sample of my data: test_data_1.csv
If the units of acceleration are measured in G's (9.8 m/s^2) what are the resulting units of velocity and distance?
This is what a plot of my data looks like - it really doesn't make sense to me (which isn't surprising since I don't have much experience in these areas). Again, the goal is to come up with a distance estimate (it doesn't have to be perfect).
Any pointers/clarifications would be much appreciated.
 A: The accelerometer measures the negative of gravity plus any upwards acceleration see NOTE#1
$$ acc = -(g+\ddot{x}) $$
and you want to integrate $\ddot{x}$ to get speed $v=\dot{x}$ and position $x$. So your expressions should be 
$$v(t)=-\int_0^t ( acc+g)\,{\rm d}t \\
x(t)=-\int_0^t \int_0^t ( acc+g)\,{\rm d}t\,{\rm d}t$$
You also know that the final position should be equal to the initial, and the final velocity should be at rest. This requires you to tweak the integration results to get the desired result. This can be justified since you have discrete acceleration values This is where you calibrate the model with the measurement data.
So here are the steps to take


*

*Find the sampling frequency $n=\frac{\# samples}{second}$

*Assume intial position is zero

*Assume initial speed is zero

*From the first few seconds, find the local $g$ value while the phone is not moving

*Sample acceleration values $acc$ and calculate times for each sample using the sample frequency and the sample count.

*Find the start of the event by checking when $acc$ starts the deviate from $g$. Set time equal zero to the start of the event

*Integrate $-acc-g$ over time from zero time and note the final velocity $v_1$ and time $t_1$ in the end. 

*Now integrate the velocities to get position and note the final position $x_1$ at time $t_1$ in the end.

*Now have to tweak the acceleration values with the linear function over time in order to get the desired effect of the phone resting in the end. This is done with this piece of analytic magic see NOTE#2 $$v(t)=\int_0^{t} -( acc+g) + \left( \frac{2 v_1}{t_1} - \frac{6 x_1}{t_1^2}\right) + t \left(\frac{12 x_1}{t_1^3}-\frac{6 v_1}{t_1^2}\right) \,{\rm d}t \\
x(t)=\int_0^{t} \int_0^t -( acc+g) + \left( \frac{2 v_1}{t_1} - \frac{6 x_1}{t_1^2}\right) + t \left(\frac{12 x_1}{t_1^3}-\frac{6 v_1}{t_1^2}\right) \,{\rm d}t\,{\rm d}t$$

*You can now find the peak velocity and peak height.


NOTE #1:
  To get the accelerometer equation you need to do a free body diagram on the accelerometer itself as it is attached to the phone and follows the phone's motion. The connection force $F$ is sensed used piezoelectic materials such that $F - m_{acc} g = m_{acc} \ddot{x}$. The reported acceleration is calibrated to be $$acc=-\frac{F}{m_{acc}} = -g -\ddot{x}$$ such that an upwards reaction force indicates downwards acceleration (the so called D'Alembert rule). Note that initially when $acc=-g$ the result is $\ddot{x} = -(-g)-g = 0$.
NOTE #2:
You can verify that
$$\int_0^{t_1}  \left( \frac{2 v_1}{t_1} - \frac{6 x_1}{t_1^2}\right) + t \left(\frac{12 x_1}{t_1^3}-\frac{6 v_1}{t_1^2}\right) \,{\rm d}t =-v_1\\
\int_0^{t_1} \int_0^t  \left( \frac{2 v_1}{t_1} - \frac{6 x_1}{t_1^2}\right) + t \left(\frac{12 x_1}{t_1^3}-\frac{6 v_1}{t_1^2}\right) \,{\rm d}t\,{\rm d}t = -x_1$$
A: If your accelerations are in $g$, you should multiply the second term in column C by $9.8$.  The velocities will then be in m/sec and your integration to make D will be in meters.  You may then want to apply any constraints you know of.  If you know the velocity starts and ends at zero, you might want to add or subtract a constant acceleration to the data to make it come out so.  If you know the phone returns to its starting location, you can apply another correction (linear change in acceleration vs time?) to make that come out.  These can improve the accuracy.
A: Like Ross said, you need to try to remove the overall constant part of your acceleration data.   Most accelerators report gravity all of the time.  So even if your phone was sitting still on a desk, it would report and acceleration of -9.8 m/s^2 "down", however down lined up with the axes of your phone.
Looking at your data a bit, for the first 1/3 of your interval, the acceleration is largely constant around -0.977.  I am assuming that for that part of the data your measuring device wasn't actually moving, so I can take it as a baseline and remove it. If I remove that and then do the trapezoidal integration, we get something like:

Does that look like what you were expecting?  
Also, you've goofed in your description of the trapezoidal integration.  In both cases, when we integrate $a$ to get $v$ and when we integrate $v$ to get $x$, we want to perform that integration over time.  So in your column D, instead of something like D3=D2+(B3-B2)*(C2+C3)/2 it should be D3=D2+(A3-A2)*(C2+C3)/2
