Area under curve when missing values

Hello fellow Igor enthusiasts,

I have waves that look like the picture attached where sometimes there are one or several values missing. In the example graph there is a value missing close to the end of the x axis.
My question is how can I take the area under the curve in this case? Would I have to fit the data through spline interpolation for ex. and then assign a value where it is missing?
I would appreciate if people could comment on the mathematical process to determine the area under the curve given missing values and any help as to how this may be implement in Igor would be further appreciated.

Thanks for your time
A simple rectangular numeric integration for constant step size is to sum all values of y and multiply by step size.

If area(…) or integrate … cannot handle NaN values, then convert them to zero.

You could write a trapezoidal rule or integration function and handle NaN.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
Thanks for your reply jj. When I try the areaxy function it gives NaN for waves with gaps. If you wouldn't mind, could you post an example script of how the latter part of your suggestion would turn out? I had trouble understanding exactly how to implement it.

Thanks
How do you want to handle the missing data? One of JJ's suggestions is to change any NAN to 0; another is to assume that missing values fall linearly between existing data points. Either of these methods should be relatively easy to code. Then the area of the modified wave could be found.

If you're uncertain how to treat the NANs maybe you should look at the effect of these methods by replacing values in a good data set with NANs and proceding with the modifications.

I would first agree with jt … You should decide how you want to handle the NaN values.

In addition, I would ask how accurately do you need to calculate the area? Your trace has peaks that are for all intents only 1 data point. Rectangular, trapezoidal, and triangular integration will give three different answers for such peaks. Which one do you want?

My suggestion … Since your spectrum seems to have only a few NaN values and those values appear to be on the baseline of your overall spectrum, set them to zero. Alternatively, set them to the half-way point of the two values to either side. Here are the one-line methods ...

mywave = numtype(mywave[p]) == 2 ? 0 : mywave[p]  // set to zero
mywave = numtype(mywave[p]) == 2 ? (mywave[p - 1] + mywave[p + 1])/2 : mywave[p]  // set to half value of neighbors


I leave the exercise in the second case for you to handle the cases where the NaN values are at the end points of the wave and/or fall sequentially one right after the other.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
Thank you jj and jtigor. This led me to the corresponding computations in the manual and I was able to figure out from there what to do next.