#pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 // Use modern global access method and strict wave access. //This procedure is modeled after PeakFunctions2.ipf, check that out for more help. //It was made because the original lognormal function packaged with multipeak fitting //doesn't allow for assymetric fits, and this version, while definitely less intuitive //allows for that. //Information Function Function/S MRGLogNormal_PeakFuncInfo(InfoDesired) Variable InfoDesired String info="" Switch (InfoDesired) case PeakFuncInfo_ParamNames: info = "Start Location (l);Spread (b);Height (h);Shape (a);" break; case PeakFuncInfo_PeakFName: info = "MRGLogNormal" break; case PeakFuncInfo_GaussConvFName: info = "MRGLogNormalGuess" break; case PeakFuncInfo_ParameterFunc: info = "MRGLogNormalParams" break; case PeakFuncInfo_DerivedParamNames: info = "Location;Height;Area;FWHM;" break; default: break; endSwitch return info end Function MRGLogNormalGuess(w) Wave w //w[1] = w[1]/w[0] w[1]=ln(w[0]) w[0]=w[0]-w[3] w[2]=w[2]^(2/3) w[3]=0.4 Redimension/N=4 w return 0 end //This is the peak function - the actual fitting function Function MRGLogNormal(w, yw, xw) Wave w Wave yw, xw Variable l = w[0] Variable b = w[1] Variable h = w[2] Variable a = w[3] //print("l: " + num2str(l)) //print("b: " + num2str(b)) //print("h: " + num2str(h)) //print("a: " + num2str(a)) yw = (h/(xw*a*sqrt(2*pi)))*exp(-((ln(xw-l)-b)^2)/(2*a^2)) //print(num2str(yw[0])+ num2str(l)) end Function MRGLogNormalParams(cw, sw, outWave) Wave cw, sw, outWave //location outWave[0][0] = logNormalPeakLocation(cw) //<-incorrect outWave[0][1] = NaN // amplitude outWave[1][0] = NaN outWave[1][1] = NaN // area outWave[2][0] = cw[2] //<-also incorrect outWave[2][1] = NaN //FWHM outWave[3][0] = NaN outWave[3][1] = NaN end //this is a version of the log normal fitting for the regular fit Function MRGLogNormal_2(w,x) : FitFunc Wave w Variable x //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/ f(x) = (h/(x*a*sqrt(2*pi)))*exp(-((ln(x-l)-b)^2)/(2*a^2)) //CurveFitDialog/ End of Equation //CurveFitDialog/ Independent Variables 1 //CurveFitDialog/ x //CurveFitDialog/ Coefficients 4 //CurveFitDialog/ w[0] = a //CurveFitDialog/ w[1] = b //CurveFitDialog/ w[2] = h //CurveFitDialog/ w[3] = l return (w[2]/(x*w[0]*sqrt(2*pi)))*exp(-((ln(x-w[3])-w[1])^2)/(2*w[0]^2)) End Function logNormalPeakLocation(w) Wave w Variable l = w[0] Variable b = w[1] Variable h = w[2] Variable a = w[3] return exp(b-a^2)+w[0] End