Issue with Gaussian fit if there is a break in the data

I am having an issue while attempting a Gaussian fit on a wave. Attached is an example wave (Table5.csv). In this wave there are bad data points in which I do not want to use. I therefore set these values to NaN (new wave: Table6.csv). I then perform a Gaussian fit on the new wave (Table6) with the following command:

CurveFit/N/H="0000"/N/NTHR=0/Q gauss Table6

This yields W_coef={-26653.9, 75811, 36.241, 5.3166}
Note: I have also tried setting different values for the initial guess for the fit. Results do not change.

The problem is it seems it is only performing the fit on the block of data before the NaN values occur. So any good data after the NaN values are ignored. I've attached a graph to make this easier to visualize (graph.png). The black solid line is the original wave which includes the bad data. The dotted red line is the wave after removing the bad data points. This red curve is the one I want the fit to occur. The dotted blue line is the curve using the coefficients found after the Gaussian fit. As you can see, the fit seems to only be influenced by the data before any bad data points occurred.

I hope this is easy to understand and that I'm posting this in the right spot. Thanks for any help!
Table5.csv (753 bytes) Table6.csv (525 bytes)
I think Thomas is right about the mask. Note also table6 only contains the left side of the curve.

It is possible to force a good fit by telling Igor to use constraints. Something like:
•K0 = -31668;
Make/O/T/N=5 T_Constraints
•T_Constraints[0] = {"K1 > 40000","K2 > 50","K2 < 70","K3 > 10","K3 < 20"}
CurveFit/H="1000"/NTHR=0 gauss  tester[pcsr(A),pcsr(B)] /D /C=T_Constraints
Setting the data points to Nan is fine. I believe the problem truly is in the initial guess. I used the Curve Fit dialog's Graph Now button to pre-flight some manual initial guesses; I made sure that the width was sufficient to span the truncated Gaussian. I think the original fit was not smart enough to find both sides and realize that they are part of the same curve. But with good initial guesses it will fit the way you want, instead of trying to find a little peak that "fits" the left side of the data.

Here is my history report:
•K0 = -31688;K1 = 80000;K2 = 50;K3 = 30;
CurveFit/G/NTHR=0 gauss  tracemat1 /D
  Fit converged properly
  fit_tracemat1= W_coef[0]+W_coef[1]*exp(-((x-W_coef[2])/W_coef[3])^2)
  W_coef={-31693,1.0761e+06,55.478,13.124}
  V_chisq= 1.83817e+07;V_npnts= 54;V_numNaNs= 45;V_numINFs= 0;
  V_startRow= 0;V_endRow= 98;
  W_sigma={109,4.93e+04,0.0212,0.0906}
  Coefficient values ± one standard deviation
    y0      =-31693 ± 109
    A       =1.0761e+06 ± 4.93e+04
    x0      =55.478 ± 0.0212
    width   =13.124 ± 0.0906

Note the starting guesses that set the amplitude quite high, and the width pretty large. Note also that the resulting fit has a *really* large amplitude.
I have attached a graph of my fit. Note that you are asking a lot of this fit!

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Graph1_5.png (10.08 KB) Graph1_5.png (10.08 KB) Graph1_5.png (10.08 KB)
Thanks for the replies everyone.

I was able to get it to work while keeping the NaNs in the wave. I was never able to get it to fit properly by adjusting the initial guesses. However, for all of my cases I ~ know what the width of the Gaussian is going to be. Setting a constraint of K3 > 10 has fixed the problem for all of my cases.

Thanks again.