I am trying to use my accelerometer on my mobile device (smart watch to be specific) to calculate a persons arm swing speed.
The data returned from the accelerometer is in $m/s^2$.
Since the acceleration of a persons arm is not constant I cannot use the equation v0 + at
to calculate the velocity.
I have never been good at physics so how do I calculate speed with varied acceleration?
Answer
You need to integrate acceleration to get the velocity.
$$v(t) = \int_{t=0}^{t} a. dt$$
There are a number of ways of doing this numerically.
I assume that you get these readings regularly with a spacing of $\delta t$, for example $\delta t = 100 ms$ or something like that.
About the simplest way to do it is
$$v(t) = v(0) + \sum a \times \delta t$$
where $v(t)$ is the velocity at time $t$. but there are more sophisticated ways of doing it - I will not repeat them here, but you might want to look at using Simpson's rule, which is described here.
The problem is complicated by velocity being three dimensional - so you need to integrate in each of the three dimensions x, y and z separated.
It depends how the phone gives you the information about the acceleration, but if you get $a_x$, $a_y$ and $a_z$ at regular intervals then you can do the following...
vx += ax * dt;
vy += ay * dt;
vz += az * dt;
if you get accleration as a raw number and angle then you will have to convert from I guess polar coordinates to xyz components to be able to add them up.
Total speed, $|v|$ is, of course, given by $|v|=\sqrt{v_x^2 + v_y^2 + v_z^2}$
I would, of course, try to start at $v=0$
Curious One, raises a really interesting point about $g$ - the best way to test this is to code it and try it - shake the phone and see if the velocity returns to zero when it is at rest after shaking it or moving it....
... can you post your results if you do this and try it out?
Another issue is twisting the phone and twisting the accelerometer - this would require you to think about angular acceleration etc., but the basic principles outlined here would be the same if you needed to think about angles.
No comments:
Post a Comment