Distance and velocity from acceleration plot

Hi,
I have some accelration data from an IMU and would like to get velocity and distance.
How could I do that?
Thanks in advance
figure
plot(dugyro,IMU_AccZ)
title('Acc Z - Raw Data')
ylabel("(m/sec/sec)")

 채택된 답변

Walter Roberson
Walter Roberson 2022년 7월 31일

0 개 추천

You could use cumtrapz(), twice.
Caution: using numeric integration to calculate distance and velocity is rather prone to error.
Even the best accelerometers, with a standard error of 10 micro-g, would accumulate a 50-meter error within 17 minutes

댓글 수: 5

Judah
Judah 2022년 7월 31일
편집: Judah 2022년 7월 31일
I tried it but my values don't seem to make sense.
Yes I agree with you regarding the error therefore I took a small sample data but still both plots don't make sense to me.
%% Raw data
close all
figure
tiledlayout(3,1)
nexttile
New_IMU_AccZ = IMU_AccZ - mean(IMU_AccZ(:));
plot(dugyro,New_IMU_AccZ)
title('Acc Z - Raw Data')
ylabel("(m/sec/sec)")
Vel=cumtrapz(New_IMU_AccZ);
dist=cumtrapz(Vel)
nexttile
plot(dugyro,Vel)
title('Velocity')
ylabel("(m/sec)")
nexttile
plot(dugyro,dist)
title('Distance')
ylabel("(m)")
%% Sample data
sample= 1000:1500;
figure
tiledlayout(3,1)
nexttile
New_IMU_AccZ = IMU_AccZ - mean(IMU_AccZ(:));
plot(dugyro(sample,1),New_IMU_AccZ(sample,1))
title('Acc Z - Sample Data')
ylabel("(m/sec/sec)")
Vel=cumtrapz(New_IMU_AccZ(sample,1));
dist=cumtrapz(Vel)
nexttile
plot(dugyro(sample,1),Vel)
title('Velocity')
ylabel("(m/sec)")
nexttile
plot(dugyro(sample,1),dist)
title('Distance')
ylabel("(m)")
You should be passing the independent variable into cumtrapz
Vel = cumtrapz(dugyro, New_IMU_AccZ);
dist = cumtrapz(dugyro, Vel);
Then I get an error
Error using zeros
CLASSNAME argument must be a class that supports ZEROS, such as 'double' or 'single'.
Error in cumtrapz (line 81)
z = [zeros(1,n,class(y)); cumsum(dt .* (y(1:end-1,:) + y(2:end,:)),1)];
Error in accel_data (line 11)
dist = cumtrapz(dugyro, Vel);
Related documentation
ds = seconds(dugyro);
Vel = cumtrapz(ds, New_IMU_AccZ);
dist = cumtrapz(ds, Vel);
Judah
Judah 2022년 7월 31일

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2022a

태그

질문:

2022년 7월 31일

댓글:

2022년 7월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by