Calculate Total - Totalizing
Alex Karpov
Jul-26th, 2020 8:03

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 sub-intervals 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.

2. 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 sub-intervals is 20, and number of samples is 21.

Making interval smaller make precision better.

Sampling with constant sampling period simplify total calculation.


Was this article helpful?
0 out of 0 found this helpful