Integrate Acceleration to velocity, wrong plot
조회 수: 23(최근 30일)
I try to use my Smartphonesensor to check if the theoretical speed of the Roboter ist the same like the real speed.
So I installed the Matlab App and used the acceleration sensor to check it. Because i didn´t mounted the smartphone totally zero in every direction (x,y,z) i needed to subtract an offset. I took the offset from the resting time bevore the movement, here i took the values from 300-500 (100hz) and calculated the average. Because i had sensor noice i also added a gauß filter. At the End i had two plots one in x-direction the over in y-direction.
So the plot for the Acceleration in the x-Direction looks very good and seems to be right.
And the Velocity of the x-direction, which i calculated with this code, doesnt look right:
velocity_y = cumtrapz(t_LP,y_ac');
How you can see there is an rising chart, which in the end has an velocity of 0.5 m/s but i the velocity should be zero.
I think the offset is not totally exact and after the integration i get an big mistake so the chart ist frequently rising. Does anyone knows how to erease this mistake?
Mathieu NOE 2021년 7월 16일
so finally... try this / adapt it to your own needs .
I can further help you if needed
FYI : this code does two integrations, to get velocity and displacement (this may not really interest you, but I leave it just in case)
% Acceleration data
acc = acc*9.81; % Add gravity effect
acc = detrend(acc);
tStep = 0.00048828; % Length of each time step
N = length(acc)*tStep;
t = 0:tStep:N;
t(end) = ;
N = length(t);
dt = mean(diff(t)); % Average dt
fs = 1/dt; % Frequency [Hz] or sampling rate
% some additionnal high pass filtering
N = 2;
fc = 0.5; % Hz
[B,A] = butter(N,2*fc/fs,'high');
acc2 = filter(B,A,acc);
velocity = cumtrapz(dt,acc2);
velocity = detrend(velocity);
disp = cumtrapz(dt,velocity);
John D'Errico 2021년 7월 16일
I would suggest your problem may be a simple one.
When you integrate a function, there is a constant of integration, which is unknown. It can be any value. Effectively, it comes down to the idea that you need to know the INITIAL velocity. Or the final velocity. Or the velocity at any given point in time. Think of it as if you are solving a differential equation. You need that initial value before the solution is complete.
Again, the integral of acceleration is velocity + C. So if you know that the final velocity must be zero, then you can correct for that by subtracting the final velocity that was obtained. Subtract that value from the entire curve.
The implicit assumption with cumtrapz is that the INITIAL velocty was zero. If that is not true, this is the source of your problem.