I am using the Accelerometer in an Android Device to track and detect certain motions, using only one axis as the motions are linear along that axis.
I am using a simple filter to remove the noise from the accelerometer data:
ouput = ouput + alpha * (input - output)
The result looks like I would expect and seems usable for my purposes:
I want to calculate velocity from the accelerometer data I'm getting, but this is where I run into problems, as can be seen here:
As with the acceleration, the velocity curve looks plausible, but it doesn't return to zero after each repetition and falls off into negative values.
For now, I'm just writing the raw accelerometer data to a file and later modify and analyze it using spreadsheets, so these calculations are all done by hand.
- It is raw data, and thus includes the effect of gravity, which I just subtract (I'm using the average of the values of the short period at the beginning in which there is no movement, in this case it was 9.55)
- I have the timestamp of each data point, so I know the interval between readings
- I'm using the simple formula
V = V0 + A * dtto calculate velocity.
V0is initially zero, then it's set to the previous value
Ais the adjusted acceleration (i.e.
accel - grav)
dtis the interval, the difference between the current and previous timestamp
I thought that the issue maybe is that the acceleration does not return to zero either and instead stays slightly below zero (as can bee seen in the first image above), which adds too many negative values that propagate in the calculation. So I set
grav to be a smaller number, and there seems to be a sweet spot. In this example, large values for
grav lead to the velocity dropping into negative, small values reverse the effect, with the velocity curve rising toward higher positive values.
grav = 9.3 (9.32 in this image), the graph seems to be most plausible. This interval is very small, 9.28 and 9.35 already show significant tendency to go up or down, respectively.
What could be the reason for this? Where does the ~9.32 come from? Why is it not the ~9.55 that I observe during the initial motionless period? Is there some way I could modify the calculations to get more consistent values? For example between each repetition there should be a short period of
V = 0.