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)")
Walter Roberson
Walter Roberson 2022 年 7 月 31 日
You should be passing the independent variable into cumtrapz
Vel = cumtrapz(dugyro, New_IMU_AccZ);
dist = cumtrapz(dugyro, Vel);
Judah
Judah 2022 年 7 月 31 日
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
Walter Roberson
Walter Roberson 2022 年 7 月 31 日
ds = seconds(dugyro);
Vel = cumtrapz(ds, New_IMU_AccZ);
dist = cumtrapz(ds, Vel);
Judah
Judah 2022 年 7 月 31 日

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

リリース

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