Calculate Totalizing or Integral
Alex Karpov
Oct-21st, 2020 8:14

Totalizing is a kind of integral (find area under curve).

1. You have to sample Analog Input and store samples in memory vector or in data table.

Similar to next:

Where number of subintervals is 4, and number of samples is 5.

Sample 0 is at left and sample 4 is at right.

Lets say that this curve is for 30 sec, then sampling interval is 7.5 sec.

*Refer to right trapezoidal drawing.

Then total T can be calculated as follows:

T=((S0+S1)/2)*7.5+((S1+S2)/2)*7.5+((S2+S3)/2)*7.5+((S3+S4)/2)*7.5

T=(((S0+S1)/2)+((S1+S2)/2)+((S2+S3)/2)+((S3+S4)/2))*7.5

Or

T=SUM of all ((Sn+S(n+1))/2) multiplied by sampling interval.

*Formula may be optimized for better precision.

Next is a picture where number of subintervals is 20, and number of samples is 21.

Making interval smaller make precision better.

Sampling with constant sampling period simplify total calculation.

Sampling 

with constant sampling period simplify total calculation.

Was this article helpful?
1 out of 5 found this helpful