I'm obtaining readings from an accelerometer, and only care about using these readings to measure the total amount of motion which is occurring. However in order to interpret these readings, I need to somehow account for the contribution to the measured acceleration from gravity. However I'm not sure how to do this without knowing the direction of the gravity vector, which the accelerometer readings alone don't provide. How can I get at this idea of motion which I'm interested in? (Sorry, I'm sure this is a stupid question, but I appreciate the help.)
[Physics] How to account for acceleration due to gravity when reading from accelerometer
accelerationexperimental-physicsgravityMeasurementsvectors
Related Solutions
Your procedure gives:
$$ a_{xz} = \sqrt{a_x^2 + a_z^2} $$
then:
$$ a_{total} = \sqrt{a_y^2 + a_{xz}^2} $$
but if you substitute for $a_{xz}$ in the second equation you get:
$$ a_{total} = \sqrt{a_y^2 + (\sqrt{a_x^2 + a_z^2})^2} = \sqrt{a_y^2 + a_x^2 + a_z^2}$$
so you don't need to split the calculation into two steps.
Your accelerometer may already exclude the acceleration due to gravity. If it doesn't then yes you need to use the inclination to work out the three components of gravity then subtract them from $a_x$, $a_y$ and $a_z$. It's hard to say exactly how to do this without knowing how your phone reports it's inclination.
response to comment:
Suppose you have your device held flat so $a_z$ = -1. Now move the device downwards at and angle of $\theta$ as shown below:
Assuming it's moving in the $xz$ plane the value of $a_z$ will be decreased a bit and the value of $a_x$ will increase from zero. Suppose you're applying an acceleration to the phone of $2g\space cos(\theta)$ - you'll see why i've chosen this value in a moment. Now the values of $a_x$ and $a_z$ are:
$$ a_x = 2g\space cos\theta \space sin\theta $$
$$ a_z = g - 2g \space cos^2 \theta $$
You now calculate $a_{total}$ by just squaring and adding as we discussed above to get:
$$a_{total}^2 = 4g^2 \space sin^2\theta \space cos^2\theta + g^2 + 4g^2 \space cos^4\theta - 4g^2 \space cos^2\theta $$
and a bit of rearrangement gives:
$$a_{total}^2 = g^2 + 4g^2 \space cos^2\theta \left( sin^2\theta + cos^2\theta - 1\right) $$
and because $sin^2\theta + cos^2\theta = 1$ the quantity in the brackets is zero so you end up with:
$$a_{total}^2 = g^2 $$
that is:
$$a_{total} = g $$
which is the same as when the phone is stationary. So it's possible to be accelerating the phone and still have the total acceleration come out as $g$ ($g$ = -1 in the phone's units). That's why just subtracting one isn't a reliable way to tell if the phone is accelerating.
This is a hard thing to do. If you know the magnitude of $g$ accurately, you can look at the actual total acceleration observed by your accelerometer and subtract the "known" g. What you are left with is the difference vector. The problem is that the difference between two large vectors that point almost in the same direction is a small vector with a large error on it.
This is why it is preferable to have some independent information about the rotation of the sensor: if you have rotation sensing (not just linear acceleration measurement) you can integrate that to get the angular position; this helps improve the estimate of the orientation, and then it's easier to subtract the gravity vector.
For example this answer assumes you know the rotation (orientation of the sensor) after which things are simple. But when you don't, the problem is very ill posed unless the acceleration is large compared to $g$ (or at least "not small").
Details of the calculation can be found in this paper. If that doesn't answer your question, can you please be more specific in your question about the concept you are stuck on?
update
Here is the reason that your problem is not easy to solve. For simplicity I will do this in 2D - it should be easy to see how to extend it to 3D (but that doesn't make it better-behaved).
I show two situations where the $a_x$ sensor records the same acceleration, but the $a_y$ sensor records a slightly different value. When the sensor is rotated and stationary, and the values are perfectly known, then
$$a_x^2+a_y^2=g^2\\ a_y = g\sqrt{1-\left(\frac{a_x}{g}\right)^2}$$
Now in the second case (not rotated, and accelerating), the reading from the $a_y$ sensor will be exactly equal to $g$. In the first case, we can only estimate the rotation from the fact that it is not quite g: from trigonometry, we see that
$$\cos\theta = \frac{a_y}{g}$$
so we expect the measured horizontal component of acceleration to be
$$a_x = g \sin\theta = g \sin\cos^{-1}\frac{a_y}{g}$$
if we want to do error propagation, we can start by looking at the derivative of the $\cos^{-1}(x)$ function, which is $-\frac{1}{\sqrt{1-x^2}}$.
For small angles of rotation, when $a_y\approx g$, that error becomes exponentially bigger - in other words, even with an accurate accelerometer it's hard to estimate $\theta$ when the angle is small. And that means that you can't tell the difference between the two cases I drew very well - the uncertainty in $a_x$ will be very large. The problem becomes less important when the acceleration is very large - but for small (compared to $g$) accelerations this really won't work very well.
This is why it is necessary to have some independent indication of orientation / rotation if you want to use an accelerometer for an IMU.
Best Answer
As you note (as per General Relativity), an accelerometer cannot separate acceleration from gravity. Whether there is a solution for you depends on what other information may be available and on what the physics objective is. More details on both the accelerometer (e.g. is it 3-axis, what is its sensitivity?) and your goals would help (e.g. what does "total amount of motion" mean?).
I suggest looking at the answers to How to remove gravity component from accelerometer X, Y readings and https://stackoverflow.com/questions/3377288/how-to-remove-gravity-factor-from-accelerometer-readings-in-android-3-axis-accel.
You can just measure g when the accelerometer is not moving and subtract it from your moving readings if the orientation of the accelerometer relative to the local gravitation field never changes and motion is only local, i.e. you are not travelling far enough for the magnitude of g to vary by a measurable amount. It is tough if the accelerometer can rotate and there is no gyroscope or other way to measure rotations. Bandpass filtering can help if the timescale for rotations differs from the timescales for changes in translational motions of interest. Sometimes simply subtracting $|g|$ from the magnitude of the acceleration is adequate. If you are measuring physical activity, you may want to look at "Separating Movement and Gravity Components in an Acceleration Signal and Implications for the Assessment of Human Daily Physical Activity" (http://dx.doi.org/10.1371/journal.pone.0061691)