MATLAB Answers

Motion Tracking with Accelerometer

19 views (last 30 days)
Karlee McFarlane
Karlee McFarlane on 27 May 2020
Edited: James Tursa on 30 May 2020
Hi, I'm very new to coding and accelerometer studies, so any help is appreciated.
I have a device that has only one 3-axis accelerometer, no gyroscope, no magnetometer. After doing movements, I get a csv file with accelerations in x,y,z axes. I want to plot the movements that I did from these data in 3d. I am able to read the files on matlab, filter the noise, and use cumtrapz to get velocity and displacement. But these plots are not helpful, and I don't know how to proceed from here.
How do I track the motion of the device and basically recreate the 3d motion plot?
The figure below shows the plots of x, y and z acceleration, velocity and displacement. Thank you.


Show 2 older comments
James Tursa
James Tursa on 28 May 2020
Yes you should remove the gravity component from all of your data first (or, more precisely, add it in so that it cancels the reaction force). Is there a quiescent period at the beginning where the object is not moving? Do you know the direction of gravity in your x-y-z coordinates?
Karlee McFarlane
Karlee McFarlane on 30 May 2020
In this example, there is no quiescent period at the beginning, but I can perform new movements if it's needed. Why is this signficant?
Direction of gravity is z axis, I believe.
James Tursa
James Tursa on 30 May 2020
A quiescent period would allow you to calibrate so you know the sensor biases + gravity. For a rough result, you would just subtract the beginning value (or probably an average of some beginning values) from all of the data. This ignores the fact that the object is actually moving because of Earth rotation (there is in reality a non-zero component of centripetal acceleration present), but for your purposes I am assuming you can ignore that. You would need to decide that.
Without the quiescent period you don't have this information. So in that case you will have to use a formula for the gravity and use your best judgement for direction based on the test setup.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 27 May 2020
The cumtrapz results do not appear to be accumulating with respect to time. Without being able to see the data or your code, my guess is that you are not integrating across the time dimension. The third argument to cumtrapz is the dimension (with time being the first argument and your signal being the second argument). Check to be certain that you are integrating across the correct dimension, then see if the results change.
The ‘x’ result should probably look something like this simulation:
t = 0:10;
xacc = t.*cos(t*2*pi/9);
xvel = cumtrapz(t, xacc);
xdis = cumtrapz(t, xvel);
plot(t, xacc)
plot(t, xvel)
plot(t, xdis)


Karlee McFarlane
Karlee McFarlane on 27 May 2020
Thank you for your answer. Yes, you're right, I was doing cumtrapz(xacc, t), instead of (t,xacc). Silly me!
This is what I get now.
But still, how do I convert this into a precise 3d animation of the exact movements that I did with the device? I read somewhere that it's impossible to get exact location and orientation of device without gyro and mag...?
Star Strider
Star Strider on 27 May 2020
But still, how do I convert this into a precise 3d animation of the exact movements that I did with the device?
What you read somewhere is correct, however the might be a way to get something out of the data you have.
I have no idea what you want to animate, however using the animatedline function (R2014b and later versions) would be the place to start.

Sign in to comment.

Translated by