I am assuming that your question is that you don't understand Simpson's rule. Below is an exerpt from Wikipedia:
Simoson's Rule is a method of approximating the integral of a function. From the figure, above, Simpson'e rule approximates the integral of f(x) (the blue curve) by using a polynomial function shape (the red curve).
The botom equation shows the parameters for this equation. The method uses pairs of intervals (interval a to m, and m to b in the figure) . There must be an even number if intervals, therefore, there will be an odd number of data points.
Let's assume that your velocity data is in vector Y, which is n samples long (n needs to be an odd number). They also need to be evenly spaced. (interval a to m must be the same length as interval m to b on the independent axis).
You will add up approximations for each pair of intervals in Y, like so:
The first approximation consists of a pair of interval defined by a, m, and b; f(a) = Y(1) and f(m) = Y(2), f(b) = Y(3)
The area under the curve is given by the formula S = (h/3) * [ f(a) + 4 f(m) + f(b)], where h = (b-a)/2 , therefore
S1 = (h/3) * ( Y(1) + 4*Y(2) + Y(3) );
Now compute the area for the next 2 intervals:
S2 = (h/3) * ( Y(3) + 4*Y(4) + Y(5) );
The total area from Y(1) to Y(5) is: S = S1 + S2.
To generalize, you sum up the areas using interval pairs:
h = Time(2) - Time(1);
n = length(Y);
S = 0;
S = S + (h/3) * (Y(i) + 4*Y(i+1) + Y(i+2) );
The first pass through this loop, i=1 and the area increment = (h/3)*( Y(1) + 4*Y(2) + Y(3))
The second pass, i increments by 2 and is equal to 3, so the second increment is (h/3)*( Y(3) + 4*Y(4) + Y(5) ).
When the loop completes, S is the area under curveY from Y(1) to Y(n) (which is the distance traveled from Time(1) to Time(n).