How to fit an 1D discontinuous wave with user-defined function?

I have an 1D wave, which is discontinuous because of NAN points (please see the black curve in the attached image). I want to fit it with a user-defined function (like the red curve in the image).

But the data can not be fitted with NAN points. Should I just delete them or there is a better way? Fitting the sub-range data separately is not what I want because I need a consistent parameter set.

Thanks!

Comparison of observed (black) and modeled (red) data. The curves are discontinuous  because of NAN points.

I might consider one of two things:

  • Collapse the regions to overlap
  • Fill the regions with an appropriate function

For the second case, you may want to search for the spline baseline fitting packages on this site.

A third option: Use a mask wave during the fit which excludes unwanted point (the NaNs). For this create a wave with the same number of points as your data wave and execute:

MyMaskWave = numtype(MyDataWave[p]) == 0 ? 1 : 0

Then set this wave in the Fitting Dialog / your fitting function. I think you could also use your data as a mask directly (i.e., without creating a separate wave), since NaNs in the mask wave count as ignore value as well, but I don't know how values other than 1 behave in a mask wave. You might try it and see if it works.

Can you make any assumptions about the parts where you did not acquire data (the gaps)?

If you can't make any assumptions, which would mean that the modeled wave can behave any way in the gaps, then I think the mask wave is the right approach. If you use that approach, I would also plot the modeled function in the gap to not hide anything from the reader.

If you can assume that the gaps are filled by something like a spline extrapolation from the observed data, then I would do the extrapolation and fit the observed data with the extrapolated data in the gaps.

When FuncFit starts up, it looks through the data set to check for NaN and Inf. It automatically removes them from the fitted data, so it shouldn't cause a problem to have NaNs, and you shouldn't need a mask wave to remove them.

Are you experiencing a problem that led to the conclusion that NaN data points are a problem? Perhaps you got the error about "Your fitting function returns NaN for at least one X value"?