The trapezoidal integration method is a numeric calculation which approximates the area trapped between the curve and the x axis by dividing the curve to segments. the area of each segment is calculated by calculating the area of a trapeze entrapped by the coordinates of that segment.
function [auc, integration] = trapezoidal(x,y)
dx = diff(x);
integration = ((y(1:end-1)+y(2:end)) .* dx) / 2;
auc = sum(integration);
The accuracy of this method is limited mainly by the size of the segments. smaller dx means more accurate results
so define your time vector with more elements: