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)")

 Respuesta aceptada

Walter Roberson
Walter Roberson el 31 de Jul. de 2022

0 votos

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 comentarios

Judah
Judah el 31 de Jul. de 2022
Editada: Judah el 31 de Jul. de 2022
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 el 31 de Jul. de 2022

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Productos

Versión

R2022a

Etiquetas

Preguntada:

el 31 de Jul. de 2022

Comentada:

el 31 de Jul. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by