Calculating distance for vertical circular motion using accelerometer data

조회 수: 14(최근 30일)
I tried calculating distance from acceleration by integrating acceleration to get velocity and then velocity to get distance for linear motion. Surprisingly, I got accurate results for linear motion(Plots attached for distance travelled 6 cms).
However, when I tried the same code on vertical circular motion (moving from 0 to 180 degrees), I am getting weird distance. I am expecting the answer to be pi or 3.14.
Can anyone help me with my code and logic?
Here's the code:
opts.VariableNames = ["ELAPSEDS", "XAXIS", "YAXIS", "ZAXIS", "GYROX", "GYROY", "GYROZ"];
liuxinlinear = readtable("C:\Wellness_May_2020\liuxin\liuxin_vertical.csv", opts);
%% METHOD 1 - Using Moving Average filter
rng default
windowSize = 50;
b = (1/windowSize)*ones(1,windowSize);
a = 1;
y1 = filter(b,a,liuxinlinear.XAXIS);
y2 = filter(b,a,liuxinlinear.YAXIS);
y3 = filter(b,a,liuxinlinear.ZAXIS);
figure;
plot(liuxinlinear.ELAPSEDS,liuxinlinear.XAXIS)
hold on
plot(liuxinlinear.ELAPSEDS,y1)
hold on
plot(liuxinlinear.ELAPSEDS,liuxinlinear.YAXIS)
hold on
plot(liuxinlinear.ELAPSEDS,y2)
hold on
plot(liuxinlinear.ELAPSEDS,liuxinlinear.ZAXIS)
hold on
plot(liuxinlinear.ELAPSEDS,y3);
title('Acceleration using Moving average filter');
xlabel('time(seconds)')
ylabel('Acceleration(mm/s^2)')
legend('OriginalX', 'predictedX', 'OriginalY', 'predictedY', 'OriginalZ','PredictedZ','Location','northwest');
movegui('northwest')
velocityX = cumtrapz(liuxinlinear.ELAPSEDS,y1/16384);
velocityY = cumtrapz(liuxinlinear.ELAPSEDS,y2/16384);
velocityZ = cumtrapz(liuxinlinear.ELAPSEDS,y3/16384);
%%Filter the velocity data
rng default
windowSize = 50;
b1 = (1/windowSize)*ones(1,windowSize);
a1 = 1;
Filtered_velX = filter(b1,a1,velocityX);
Filtered_velY = filter(b1,a1,velocityY);
Filtered_velZ = filter(b1,a1,velocityZ);
figure;
plot(liuxinlinear.ELAPSEDS,Filtered_velX);
hold on;
plot(liuxinlinear.ELAPSEDS,Filtered_velY);
hold on;
plot(liuxinlinear.ELAPSEDS,Filtered_velZ);
title('Velocity using Moving average filter');
xlabel('time(seconds)')
ylabel('Velocity(mm/s)')
legend('Filter_velocityX','Filtered_velocityY', 'Filtered_velocityZ','Location','northwest');
movegui('northwest')
figure;
deltaT = liuxinlinear.ELAPSEDS(581)- liuxinlinear.ELAPSEDS(580);
plot(liuxinlinear.ELAPSEDS,cumtrapz(liuxinlinear.ELAPSEDS,Filtered_velX));
hold on
plot(liuxinlinear.ELAPSEDS,cumtrapz(liuxinlinear.ELAPSEDS,Filtered_velY));
hold on
plot(liuxinlinear.ELAPSEDS,cumtrapz(liuxinlinear.ELAPSEDS,Filtered_velZ));
legend('X-axis','Y-axis','Z-axis','Location','northwest');
title('Distance for acceleremoter using Moving Average Filter') , shg
xlabel('time(seconds)')
ylabel('Distance(mm)')
  댓글 수: 1
Omar Alawneh
Omar Alawneh 2021년 12월 23일
hello,
can you please tell me how did you get the distance using moving mean ?

댓글을 달려면 로그인하십시오.

답변(1개)

Prudhvi Peddagoni
Prudhvi Peddagoni 2020년 9월 1일
Hi Alhamd Khan,
This method of integrating acceleration is not that reliable and the errors accumulate when the device moves in a non straight line.
Having said that, there might be also an issue of device orientation. The device cannot differentiate between acceleration due to earth’s gravity and the device’s acceleration. So just subtracting g from the z-axis may not be ideal because the device’s orientation of the device is changing. If it is calculating device’s orientation using gyroscope data then there won’t be any issue. But the issue of accuracy still persists.
And one more thing, it is better to calculate overall distance instead of x , y and z components as the it is not a straight line motion.
Hope this helps.
  댓글 수: 2
Prudhvi Peddagoni
Prudhvi Peddagoni 2020년 9월 3일
Hi,
Generally GPS is used to calculate the distance and also for calculating the speed of the user. (but GPS is accurate to within 3 meters.
Yes you can incorporate gyroscope data for understanding device orientation data so that you can eliminate g.
I think centripetal force won't be an isse when you calculate the absolute distance instead of component wise distances. Because, let's assume that your device moves a quarter of a circle. if you calculate x and y component accelerations (centripetal) and find distance moved in that instant (component wise) and find the absolute distance travelled in that instant. and repeat this process for whole journey, then you should get theoretically. But when you don't calculate absolute distance at every instant, then finally you'll get r and r as the x and y distance components.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by