# Thread: Area under the curve

1. ## Area under the curve

Hello,

I have been asked by a user of some software I have created if I can add a calculation for Area Under The Curve...

From what I understand, I need to use Calculus to do this ... not my area of expertise

I need to add some code to figure this out but have no idea where to even start.

Here is a screen shot of the type of data that I need to work with:

This is an expanded view:

Data is collected every 4 seconds usually over an 8 to 12 hour period.

Can anyone help point me in the right direction or is this not possible with this type of graph?

Thanks,
Jeff

2. ## Re: Area under the curve

If "Data is collected every 4 seconds usually over an 8 to 12 hour period", then the simplest and most reasonable thing to do is to add all data points and multiply by 4 seconds. If the function value is in "beats per second" then that will give "total beats".

3. ## Re: Area under the curve

I have the values for Total Beats and Total SPO2 points ... I need to calculate the Area Under The Curve.
I just spoke with the user, and they tell me that they only want to calculate the Area Under The Curve for any SPO2 points that are under a value of 89.

4. ## Re: Area under the curve

Originally Posted by Jeff141
Hello,

I have been asked by a user of some software I have created if I can add a calculation for Area Under The Curve...

From what I understand, I need to use Calculus to do this ... not my area of expertise

I need to add some code to figure this out but have no idea where to even start.

Data is collected every 4 seconds usually over an 8 to 12 hour period.

Can anyone help point me in the right direction or is this not possible with this type of graph?

Thanks,
Jeff
Actually you do not need calculus. In fact, calculus might well balk at dealing with such a curve. You need to use numerical integration, which is a set of methods for estimating the area under curves when calculus will not work.

The basic idea is to break the area into many small pieces. It makes things easier (though not necessarily more exact) to divide the horizontal axis into N pieces of equal length. If your readings are at 4 second intervals, 4 seconds is an intuitively appealing length to choose along the x axis. Call that length L. And suppose you have N such intervals. (It is important that N be a relatively large number to get relatively exact results.) Having done so, one way to proceed is to find the vertical value at the beginning and end of each interval. Let's call those values for the $i^{th}$ interval $B_i$ and $E_i$.

Then the area $\approx \displaystyle \dfrac{L}{2N} * \sum_{i = 1}^N(B_i + E_i).$

This just requires a loop for doing each sum and accumulating those sums building with a final multiplication and division. Not hard at all.

If you want a more complete and rigorous explanation look at Numerical integration - Wikipedia, the free encyclopedia