The accelerometers always tell you the 3 components of acceleration - including gravity.
If the aircraft is on the ground, and the Z accelerometer is truly vertical, it will have an output equal to the value of gravity at that point on the earth.
If you know the value of gravity at that point, and subtract that from the Z accelerometer output, the result is zero. The outputs from the other 2 accelerometers will be zero.
So, allowing for local gravity, we have an acceleration vector of zero, which is correct since the aircraft is not accelerating w.r.t. the earth.
When the aircraft takes off, you need to integrate up the gyro outputs to calculate the angular orientation of the aircraft at any time. This is not trivial!
You can then use the angular orientation to calculate the acceleration vector at any time - again allowing for the value of local gravity.
This acceleration vector would usually be calculated in a reference frame that has a vertical Z axis, and can be integrated up to give velocity in that frame and position with respect to the starting point. The Z component tells you what you wanted to know.
The most complicated part of this process is using the gyro outputs to get the instantaneous angular orientation of the aircraft.
All accelerometers and gyros have errors which will affect your results.
For further details, I suggest you look for information on Inertial Navigation Systems (INS) - here or by Googling. Any decent reference on INS will cover what you need, including the integration of the gyro outputs and the errors involved.
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$$
Best Answer
If you don't care about the direction of the horizontal acceleration, the answer is yes.
When the car is stationary (user acceleration very small, below some limit you define for the RMS of the three axes) you measure the vector $\vec g$ for the total acceleration - this is "down".
Now during motion you find the user acceleration perpendicular to this vector with these steps:
Normalize $\vec g$ to unit length: $\vec n$
Take dot product of unit gravity and user acceleration: $d=\vec n \cdot \vec u$
Subtract vertical component from user acceleration: $\vec h = \vec u - d \vec n$
Finally take the magnitude of this answer (square root of sum of squares of components) for the total horizontal acceleration.
To separate out the acceleration into lateral (from car turning) and linear (accelerate/brake) you would have to do a similar procedure to find the remaining orientation by looking for horizontal acceleration when there is no corresponding rotation - this tells you which way the phone is facing.