Problem using cumtrapz with acceleration data
Mostra commenti meno recenti
Hello :)
I am facing problems determing velocity and position from my acceleration data. Therefor I am using cumtrapz, but the results are not what I expect them to be.
Here is what I am doing: I have recorded acceleration data for 3 minutes (without moving the sensor, so the data is just showing the sensor noise). I am using a matlab script, to remove the offset of the recorded data (using mean function). The next step is to determine velocity and position. When I look at the velocity, the course of the function goes back to zero at the end (see first picture). The position resulting from this velocity is about -20 m, which is quite big (I need to implement filtering next).
The problem I am facing with cumtrapz is the following: When I use only the first 120 seconds of the given signal (180 seconds represent the full signal), the signal ends at zero again (see picture 2). The value should be the same as before (looking at the full signal, 180 seconds, upper part in picture 2).
I did a quick check using a sine wave (see picture 3). When I integrate the sine wave using cumtrapz, everything is the way I expect it to be (full signal = 20 seconds, cut off @10 seconds): When comparing the full signal with only 10 seconds of the full signal, the integrated value is the same @10 seconds.
Does anybody have a suggestion what I am doing wrong here?
And here is the matlab script I am using (sorry, forgot that...):
%%init
clear; % clear workspace
close all; % close opened figures
%%defines
samplefreq_kx = 0.00125; % Accel data has been recorded with 1600 hz -> 1600Hz/2=800hz
%%Step 1: Load profile
addpath('C:...'); % Define path with profiles
% Define profile to load here:
load('Profil_20_2.mat'); % Profil 20_2 = Sensor KX022 in hold position, 3 minutes.
t_180_kx = 0:samplefreq_kx:180; % define time array for 180 seconds
t_120_kx = 0:samplefreq_kx:120; % define time array for 120 seconds
% Use acceleration data of KX022 @180 seconds
% Signal has to be converted, because sensor gives out g!
% Use only every second entry in KX022_Signals
% Entry 8001 = Start at 5 seconds (first 5 seconds of signal is not
% important!)
accel_z_kx_180 = KX022_Signals(4,8001:2:end) * 9.80665; % convert from g to m/s2
% Use acceleration data of KX022 @120 seconds
accel_z_kx_120 = KX022_Signals(4,8001:2:200001) * 9.80665;
%%Remove offset of given signals (for 180 & 120 seconds)
% mean calculates the given offset
% acceleration value has to be zero without offset!
accel_z_kx_180_offsetfree = accel_z_kx_180 - mean(accel_z_kx_180);
accel_z_kx_120_offsetfree = accel_z_kx_120 - mean(accel_z_kx_120);
%%Plot offset free signals (180s & 120s)
figure('Name','Acceleration data','NumberTitle','off')
ax1 = subplot(2,1,1);
plot(t_180_kx,accel_z_kx_180_offsetfree)
grid on;
title('KX022 z acceleration (@180s)');
xlabel('time [s]');
ylabel('accel [m/s^2]');
ax2 = subplot(2,1,2);
plot(t_120_kx,accel_z_kx_120_offsetfree)
grid on;
title('KX022 z acceleration (@120s)');
xlabel('time [s]');
ylabel('accel [m/s^2]');
% link y-axis of subplot ax1 and ax2
% First argument in linkaxes defines which subplot is used as reference
% (ax2 has bigger noise)
linkaxes([ax2,ax1],'y');
%%Calculate velocity for 180 & 120 seconds
v_z_kx_180 = cumtrapz(t_180_kx,accel_z_kx_180_offsetfree);
v_z_kx_120 = cumtrapz(t_120_kx,accel_z_kx_120_offsetfree);
figure('Name','Calculated velocity','NumberTitle','off')
ax3 = subplot(2,1,1);
plot(t_180_kx,v_z_kx_180)
grid on;
title('KX022 calculated velocity @180s');
xlabel('time [s]');
ylabel('velocity [m/s]');
ax4 = subplot(2,1,2);
plot(t_120_kx,v_z_kx_120)
grid on;
title('KX022 calculated velocity @120s');
xlabel('time [s]');
ylabel('velocity [m/s]');
linkaxes([ax3,ax4],'y');
linkaxes([ax3,ax4],'x');
%%Calculate position for 180 & 120 seconds
s_z_kx_180 = cumtrapz(t_180_kx,v_z_kx_180);
s_z_kx_120 = cumtrapz(t_120_kx,v_z_kx_120);
figure('Name','Calculated position','NumberTitle','off')
ax5 = subplot(2,1,1);
plot(t_180_kx,s_z_kx_180)
grid on;
title('KX022 calculated position @180s');
xlabel('time [s]');
ylabel('position [m]');
ax6 = subplot(2,1,2);
plot(t_120_kx,s_z_kx_120)
grid on;
title('KX022 calculated position @120s');
xlabel('time [s]');
ylabel('position [m]');
linkaxes([ax5,ax6],'y');
linkaxes([ax5,ax6],'x');
Best regards,
Niko
3 Commenti
John D'Errico
il 2 Giu 2016
Modificato: John D'Errico
il 2 Giu 2016
Since the one thing you have not provided is your code, it is difficult to guess. It would be much easier if you simply attached your script as an m-file to a comment, or best is if you can paste it into your question. Please use the "{} Code" button to format the code so it is readable though.
Student88
il 2 Giu 2016
John D'Errico
il 2 Giu 2016
I'll be darned! COMMENTS! :)
Risposta accettata
Più risposte (1)
Student88
il 2 Giu 2016
1 Commento
John D'Errico
il 2 Giu 2016
But again, that all happens because the mean of a series can be interpreted as application of rectangle rule, so just another integration rule like trapz.
Categorie
Scopri di più su Numerical Integration and Differentiation in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!