Adding initial guesses to a curve fit procedure
s0585353
Any help will be greatly appreciated.
Thank you,
-s0585353
Function Gaussian2Dfit(aavgNNN, w1, w3, xmin, xmax, ymin, ymax)
Wave aavgNNN
Wave w1
Wave w3
Variable xmin
Variable xmax
Variable ymin
Variable ymax
CurveFit/NTHR=0 Gauss2D aavgNNN[xmin,xmax][ymin,ymax] /X=w1[xmin,xmax] /Y=w3[ymin,ymax] /D
ModifyContour fit_aavgNNN labels=0
wave W_coef
End
http://www.igorexchange.com/node/4038
Since then Batch Curve Fit is in Igor 6.3 onwards.
You need to make a co-efficient wave containing your guesses. Relevant bit from that post is this
W_coef[0] = {0,1,0.0006,0.0155,600,0.999}
Make/O/T/N=2 T_Constraints
T_Constraints[0] = {"K5 > 0","K5 < 1"}
FuncFit/H="000010"/NTHR=0 /N/Q ChapmanRichards W_coef aWave[5,44] /X=bWave /D/R /C=T_Constraints
WAVE W_coef
The /H flag tells igor whether to hold any of the co-efficients and which ones.
May 14, 2014 at 01:28 pm - Permalink
You do, indeed, need to pre-make a coefficient wave and then use that with CurveFit:
Wave aavgNNN
Wave w1
Wave w3
Variable xmin
Variable xmax
Variable ymin
Variable ymax
Variable amp
Make/D gcoefs={0, amp, (xmin+xmax)/2, xmax-xmin, (ymin+ymax)/2, ymax-ymin, 0}
CurveFit/NTHR=0/G Gauss2D, kwCWave=gcoefs, aavgNNN[xmin,xmax][ymin,ymax] /X=w1[xmin,xmax] /Y=w3[ymin,ymax] /D
ModifyContour fit_aavgNNN labels=0
wave W_coef
End
I added an input parameter amp to give the initial guess of the peak height, I computed reasonable guesses for center and width from your window inputs (but you might want to pass those in directly), and I added the /G flag to tell CurveFit to use your coefficient wave to get the initial guesses.
And you might, in fact, like the convenience of Batch Curve Fit.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 14, 2014 at 04:29 pm - Permalink
Thanks,
-s0585353
Function Gaussianfit2D(aavgNNN, w1, w3)
Wave aavgNNN
Wave w1
Wave w3
Make/D gcoefs={0, -0.05, 2049.3, 3.5, 2047.2, 3.5, 0.3}
CurveFit/NTHR=0/G Gauss2D, kwCWave=gcoefs, aavgNNN /X=w1 /Y=w3 /D
ModifyContour fit_aavgNNN labels=0
wave W_coef
if (waveExists (W_coef))
Variable integral
integral = W_coef[1]*2*pi* W_coef[3]*W_coef[5]*sqrt(1-W_coef[6]^2)
Print integral
endif
End
May 15, 2014 at 12:24 am - Permalink
You have three options:
* use make/O/D gcoeffs
* use make/D/FREE gcoeffs
* use killwaves gcoeffs
See the Help information for each command to decide which will be best for your needs.
The resultant waves to the left fit have more points than those for the right fit. Increase the number of points in your resultant.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
May 15, 2014 at 05:00 am - Permalink
How do I increase the number of points?
May 15, 2014 at 09:10 am - Permalink
Use the /L flag:
CurveFit/L=100 ...
will create an autodestination wave that's 100x100.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 15, 2014 at 09:30 am - Permalink
Thanks,
-s0585353
May 15, 2014 at 10:26 am - Permalink
You can fit more than one peak if you write a user-defined function to fit a sum of Gaussian peaks. You may also need to incorporate a gradient or polynomial background.
You will have to supply initial guesses for each of the peaks in the sum, but you already have that- something is generating the windows for your original attempt.
Here are a pair of suitable fitting functions:
Wave pw
Variable xx, yy
Variable result = pw[0] // w[0] is the Z offset
Make/D/N=7/FREE onePeakCoefs = 0
Variable npeaks = (numpnts(pw)-1)/6
Variable i
for (i = 0; i < npeaks; i += 1)
onePeakCoefs[1,] = pw[6*i+p] // leave the Z offset at zero for the individual peaks
result += Gauss2d(onepeakCoefs, xx, yy)
endfor
return result
end
Function Fit2DGaussiansAAO(pw, zw, xw, yw) : FitFunc
Wave pw, zw, xw, yw
zw = pw[0] // w[0] is the Z offset
Make/D/N=7/FREE onePeakCoefs = 0
Variable npeaks = (numpnts(pw)-1)/6
Variable i
for (i = 0; i < npeaks; i += 1)
onePeakCoefs[1,] = pw[6*i+p] // leave the Z offset at zero for the individual peaks
zw += Gauss2d(onepeakCoefs, xw[p], yw[p])
endfor
end
Both do the same thing, the first is easier to use outside of curve fitting, for instance to fill a test matrix fill of values. The second is much faster than the first which is good for curve fitting. Both take a coefficient wave that has 6*npeaks+1 points. Point zero is the z offset. The next six points are coefficients for the first peak: amplitude, X center, X width, Y center, Y width and correlation coefficient. To fit two peaks you would need 13 points.
Hope this helps.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 16, 2014 at 04:31 pm - Permalink