![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194690/image.jpeg)
Calculation velocity and acceleration from X and Y coordinates
37 views (last 30 days)
Show older comments
Hi, I am trying to calculate the velocity and acceleration of a football player in a 8-minute game. I have computed XY from GPS so I have distances by a 2 matrix (9256x2). I have computed distance with hypot. I have the t (9256x1) variable as well which goes like this [0; 0,05; 0,10; 0,16; 0,21; 0,26; 0,31; 0,36; 0,41; 0,47; 0,52; 0,57; 0,62; 0,67; 0,73; 0,78; 0,83; 0,88; 0,93; 0,99;] and so on.
What I do by now is the following:
% t - tiempo; d - distance between each XY point (obtained from hypotenus)
tdiff = diff(t)
% vel - velocity
vel = d(2:end)./tdiff
figure(1)
plot (t(2:end), vel)
% ac - acceleration
veldiff = diff(vel)
ac = veldiff./tdiff(2:end)
figure (2)
plot (t(3:end), ac)
Velocities seems to be correct, but acceleration data has no sense. Any suggestion? Where do I fail?
Thanks in advance
Daniel.
0 Comments
Accepted Answer
Jim Riggs
on 31 Aug 2018
Edited: Jim Riggs
on 31 Aug 2018
It appears from the sample data that you show that the time interval is not constant in your data. This will cause some difficulties numerically and limit your options in smoothing the data. Taking a numerical derivative is an inherently noisy process, and so the second derivative is noise upon noise.
I would suggest that you first smooth the position data with a spline curve, then over-sample it at a small time interval. Then you can use higher-order differentiation methods to get smoother data. For example:
%%create the over-sampled time vector
dt = 0.02; % specify the time step you want (should be smaller than the data sampling)
tstart = 0; % specify the starting time value
tstop = ?? % specify the end time value
nsteps = (tstop-tstart)/dt +1 % calculate the number of time steps
tt = linspace(tstart,tstop,nsteps); % create the time vector
Now, using this new time vector, use the spline interpolation to generate smoothed position data:
Xsmooth = spline(t,X,tt);
Ysmooth = spline(t,Y,tt);
Now you have smoothed data for X, and Y (Xsmooth, Ysmooth) on an oversampled time scale, tt. Use this smoothed data to perform your calculations and you should see somewhat better results.
As an alternative, you might try smoothing the data after calculating the distance. Use the original X and Y data to calculate the distances, as before, then smooth and over-sample the distance vector. This might work better;
dsmooth = spline(t,d,tt);
For even more smoothing, you can now use higher-order numerical derivative calculation methods which will provide better results.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194690/image.jpeg)
2 Comments
Jim Riggs
on 31 Aug 2018
I understand. Working with real-world data is full of challenges. I recommend smoothing the data to a uniform time-step, and then using the higher-order central difference formulas to estimate the derivatives.
More Answers (0)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!