# Calculate kinematics of body movement from the set of spatial coordinates

Short intro

I have a set of 3D (x,y,z) spatial coordinates of arm movement obtained using motion capture system. The example set of such coordinates looks like this (rounded up):

 arm = c(-420.1, -419.8, -419.6, -419.4, -419.1, -418.8, -418.5, -418.2,
-417.9, -417.5, -417.1, -416.8, -416.4, -416, -415.5, -415.2,
-414.8, -414.3, -413.9, -413.5, -413.1, -412.6, -412.1, -411.6,
-411.1, -410.6, -410.1, -409.5, -408.9, -408.3, -407.7, -407.1,
-406.5, -405.8, -405.1, -404.5, -403.8, -403.1, -402.5, -401.9,
-401.2, -400.5, -399.9, -399.2, -398.6, -397.8, -397.1, -396.3,
-395.7, -395.2, -394.6, -394, -393.4, -392.9, -391.8, -391.7,
-391.8, -391.6, -391.3, -390.8, -390.3, -389.6, -389.1, -389.7,
-389.4, -387.9, -387.5, -387.9, -387, -386.7, -387.2, -387, -386.8,
-386.6, -386.3, -386.1, -385.8, -385.8, -385.8, -385.8, -385.6,
-385.5, -384.6, -384.5, -384.5, -384.5, -384.5, -384.5, -384.5,
-384.6, -385.8, -386.2, -386.9, -387.2, -387.1, -387.5, -387.8,
-388.1, -388.4, -388.9, -389.2)


where each number above stands for location of the arm on the $x$ axis, through time. I want to obtain the kinematic markers of average velocity, peak velocity, peak acceleration, peak deceleration and jerk index. Jerk index is defined as 'magnitude of the jerk averaged over the entire movement and relating to the smoothness of movement'.

How far did I get?

From what I read on kinematics in Wikipedia and this site I know that I can calculate average velocity using this equation:

$$v = \frac {\Delta x}{\Delta t}$$

I know the duration $t$ of the movement, but I am not certain how do I define displacement $x$ for this particular coordinate set. Could it be just subtracting minimal from maximal value $max(arm)-min(arm)$?

I don't know how to obtain peak velocity.

Calculating average acceleration seems easy using this equation: $$a = \frac {\Delta v}{\Delta t}$$

but not sure how to get peak acceleration and peak deceleration.

No idea how I would approach calculating jerk index (magnitude of the jerk averaged over the entire movement and relating to the smoothness of movement).

If any more complex calculations would have to be involved, I work mainly in R, also in MATLAB regarding functions.

-
See if Eureqa can help you creativemachines.cornell.edu/eureqa – ja72 Aug 17 '12 at 21:20

To be honest, most of these questions could probably be answered with a bit of reading on Wikipedia, but anyway:

• Displacement is defined as the change in position - hence the notation $\Delta x$. And the change in any quantity $X$ is defined as the final value minus the initial value, $X_f - X_i$.
• To calculate peak velocity, you'll have to determine the velocity at each time step and find the highest one. There are a couple approaches you could use to get individual velocities. You could take the naive approach of determining the differences between adjacent data points, $v_n = (x_{n+1} - x_n)/(t_{n+1} - t_n)$, which would give you an approximation for the velocity between data points. Or you could use $v_n = (x_{n+1} - x_{n-1})/(t_{n+1} - t_{n-1})$, the standard 2-point first order finite difference, which would tell you the velocity at each data point (except the first and last, of course). Or you could do some sort of interpolation on the points (which you could ask about at Scientific Computation and then find the maximum of the resulting curve. There are more complex methods which can improve the accuracy of your approximation a bit, but whichever method you use, you will still only get an approximation to the peak velocity. It is impossible to know the actual peak velocity from the data you have.
• To calculate peak acceleration, you can do the same thing except with velocities instead of positions. I'd recommend using the 3-point second order finite difference, $a_n = (x_{n-1} - 2 x_n + x_{n+1})/[(t_{n+1} - t_{n})(t_{n} - t_{n-1})]$, which corresponds to taking the numerical derivative of the velocities computed by the first method. Again, it's just an approximation; you can use fancier methods which will get you a better approximation, but you can't compute it exactly.
• There isn't any such thing as deceleration in physics, or in other words, it is just acceleration when the acceleration happens to be negative. So "peak deceleration" would probably be the most negative value of acceleration.
• For the jerk index, you could compute the jerks at each half-time step as the derivatives of acceleration and average their magnitudes. The formula for the third derivative would be $J_n = (x_{n-1} - 3 x_n + 3 x_{n+1} - x_{n+2})/[(t_{n+2} - t_{n+1})(t_{n+1} - t_{n})(t_{n} - t_{n-1})]$

Some of these computations may be implemented as functions in Matlab; it's probably worth checking the documentation. Though they would also be pretty easy to do manually.

-
That's great answer, thank you very much. I am aware of Wiki entries on this, but I was looking for something more specific to the type of data I have. The online resources usually use examples with different type of data, so I really appreciate your very focused approach to this. – Geek On Acid Aug 18 '12 at 12:22
I'm glad it was helpful. But I do want to mention that we don't usually give these kinds of answers. We generally want you to do your homework, so to speak, before asking a question here. For example, you should have been able to look up the definition of displacement. If something isn't clear about it, you can ask that, but you have to be very specific about why you are confused, especially when asking about something so simple. Similarly, it would have been better if you elaborated on why you couldn't compute peak velocity or acceleration. (cont.) – David Z Aug 18 '12 at 15:33
(cont.) Did you not know how to compute velocities at individual times, or were you wondering whether there was some formula that takes into account all the data points to get some better estimate of the peak, or something else? The more precisely you can define your question, the better. Just something to keep in mind next time you ask. – David Z Aug 18 '12 at 15:35
Yes, I admit I should have put more effort into figuring out things myself before asking. Thank you again @David for the time you took to answer it. – Geek On Acid Aug 20 '12 at 11:02

You need a tool to convert the data points into a) a polynomial fit, or b) a set of cubic splines which are easily differentiable. You might need to smooth the data first to get a nicer results. I have made an VBA script for Excel to do this because I used it with measured cam follower data.

Maybe if I convert the script into Matlab I can post it for you (maybe)

PS1. My reference for cubic splines is http://www.nrbook.com/c section 3.3. PS2. Do not use finite differences (Change over Change) as the results with be very unstable.

-
I can't think of any reason finite difference methods would be unstable for this application. – David Z Aug 18 '12 at 6:05
@ja72: Ah, thank you, I thought that it would be bad to use the data in the format I have it right now. I should be fine with the routines you suggested in C. – Geek On Acid Aug 18 '12 at 12:26
@DavidZaslavsky: When I say unstable, I mean that the derivatives will fluctuate wildly between positive and negative values. Try it if you want. Take as smooth signal add a tiny bit of noise and start differentiating with $\frac{\Delta y}{\Delta x}$. Now smooth the data and apply cubic splines for differentiation and compare. – ja72 Aug 18 '12 at 21:06
@ja72 sure, if you add a large amount of high-frequency noise, you will mess up the numerical derivatives. The OP's data looks reasonably smooth, though. And you can also use a larger numerical differentiation template to reduce the effect of the noise. In fact, a suitably chosen template would be equivalent to fitting and differentiating cubic splines. – David Z Aug 19 '12 at 15:24

If you want a point value of v or a. Use a spline interpolation of x and then derive it once for v and twice for a. There is a cubic spline function in Matlab.

-