MATLAB: Double integrate a precise series of numbers

accelerometerdouble intergationnumerical integration

Hi All, I'm very new in Matlab and I would like to ask about this situation. I'm getting some data from my accelerometer, and I directly putting them in a file using this format:
X: 125, x: 103, Y: 127, y: 106, Z: 051, z: 043
X: 120, x: 100, Y: 129, y: 108, Z: 054, z: 045
X: 123, x: 103, Y: 127, y: 106, Z: 053, z: 044
….
X: 111, x: 093, Y: 135, y: 113, Z: 053, z: 044
I want to double integrate for example just the X axis, I know that I can use "integral2" to do that, but it needs a defined function as parameter. in my case is a set of numbers.
Note that the time is t = 1.5s, and the number of lines (readings from the accelerometer) is 78.
how can double integrate it using only this set of numbers?
Thanks in advance.

Best Answer

I am going to guess that these are accelerations sampled at given times. The poster wants the integral over time to find the velocity, and the second integral over time to find the position. We need to approximate the integral with a cumulative sum.
% given
del_t=1.5; % seconds
accel_x=[125 126 126 127 128 129 131 126 126 125];
% need to know initial position and velocity
v_0=0;
x_0=0;
% time vector corresponding to data
t=del_t*(0:(length(accel_x)-1));
% compute integrals
vel_x=del_t*cumtrapz(accel_x)+v_0; %or cumsum()

pos_x=del_t*cumtrapz(vel_x)+x_0; %or cumsum()
% examine results
plot(t,accel_x, t,vel_x, t,pos_x);
legend('accel_x','vel_x','pos_x');
Related Question