Fitting Gaussian Distribution to Data

Hi all,

I have a certain data set with two peaks, and I want to attempt to them to two Gaussian distributions with "new fit function," which is under curve fitting.  I want to familiarize myself first with navigating new fit function, so I generated data with gnoise.   I also want to add statistical noise to the data set by adding sqrt(n) to the data.  Using new fit function, how do I come up with the coefficients and independent variables to custom fit a Gaussian distribution?  I hope this makes sense.

Here's my code so far.

Function GaussTest()

SetRandomSeed 1

Make/N=1000/O data1=sqrt(1000)+gnoise(1)
Make/N=100/O Norm_Hist

Histogram/P/B={0,1,100} data1, Norm_Hist

end

 

You could use Multipeak Fit 2 to do the fitting- that gets around trying to build your own fitting function. See File->Example Experiments->Curve Fitting->Multi-peak fit 2 Demo.

You could base your fitting function on Igor's built-in functions gauss() or Gauss1D(). Here is one I built:

Function DoubleGauss(w,xx) : FitFunc
    Wave w
    Variable xx

    //CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
    //CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
    //CurveFitDialog/ Equation:
    //CurveFitDialog/ Make/D/FREE wave1 = {y0, A1, mu1, w1}
    //CurveFitDialog/ Make/D/FREE wave2 = {0, A2, mu2, w2}
    //CurveFitDialog/ f(xx) = y0 + Gauss1D(wave1, xx) + Gauss2D(wave2, xx)
    //CurveFitDialog/ End of Equation
    //CurveFitDialog/ Independent Variables 1
    //CurveFitDialog/ xx
    //CurveFitDialog/ Coefficients 7
    //CurveFitDialog/ w[0] = y0
    //CurveFitDialog/ w[1] = A1
    //CurveFitDialog/ w[2] = mu1
    //CurveFitDialog/ w[3] = w1
    //CurveFitDialog/ w[4] = A2
    //CurveFitDialog/ w[5] = mu2
    //CurveFitDialog/ w[6] = w2

    Make/D/FREE wave1 = {w[0], w[1], w[2], w[3]}
    Make/D/FREE wave2 = {0, w[4], w[5], w[6]}
    return w[0] + Gauss1D(wave1, xx) + Gauss1D(wave2, xx)
End

I used the Curve Fit dialog's New Fit Function button. To get the two temporary waves to pass to the Gauss1D function, you need to add lines above the template's f(xx) = line in the code editing box in the New Fit Function dialog.