[proFit-list] Program or function for multiple peak fitting

pro Fit Support profit at quansoft.com
Thu Dec 17 22:48:01 CST 2009


Dear Ludovic

The piece of code of the Peaks function is written in C++, so it is not of any real use to the end user. However, there has been a predecessor of the Gaussian function with multiple peaks written in pro Fit Pascal, which was part of earlier pro Fit versions (where that functionality was not yet built-in). Here it is

-------------

{This function allows you to easily fit multiple Gaussian peaks.

 To compile the function, click the button "To Menu" above.

 To start a fit, first display your data in the preview window.
 Also make sure that the function 'Peaks' is displayed in the 
 parameter window: choose Peaks from the Func menu, then check
 "Show function" in the preview.

 Now, you should set the parameters 'const' and 'm' of the
 function. These parameters describe the background of your
 data. You must set these parameters such that the function
 approximately goes through the lowermost data points of your
 data set.
 To do this, you preferably use the Fit tool of the preview window.
 
 Then you choose the Marker tool of the preview window and set a
 marker on top of each peak you see in your data. Once this is
 done, click the button "Read Markers" in the parameters window.
 This sets the position and amplitude of all gaussian peaks.

 In a next step, set the parameters k1, k2, etc. such that each
 peak has approximately the correct width. You again can use
 the Fitting tool in the parameter window for this work.

 Finally, choose "Nonlinear Fit..." from the Calc menu to run the
 fit. 


 This example shows how to use the markers in the preview window
 from a function/program. It also shows how to bring up a button
 in the Parameters window.
}

function MultipleGaussians;

defaults


  a[1] := 9,constant,'#peaks',0,9;
  a[2] := 0,active,'const';
  a[3] := 0,active,'m';

  a[4] := 0,active,'x1'; a[5] := 1,active,'A1'; a[6] := 1,active,'k1';
  a[7] := 5,active,'x2'; a[8] := 1,active,'A2'; a[9] := 1,active,'k2';
  a[10] := 10,active,'x3'; a[11] := 1,active,'A3'; a[12] := 1,active,'k3';
  a[13] := 15,active,'x4'; a[14] := 1,active,'A4'; a[15] := 1,active,'k4';
  a[16] := 20,active,'x5'; a[17] := 1,active,'A5'; a[18] := 1,active,'k5';
  a[19] := 25,active,'x6'; a[20] := 1,active,'A6'; a[21] := 1,active,'k6';
  a[22] := 30,active,'x7'; a[23] := 1,active,'A7'; a[24] := 1,active,'k7';
  a[25] := 35,active,'x8'; a[26] := 1,active,'A8'; a[27] := 1,active,'k8';
  a[28] := 40,active,'x9'; a[29] := 1,active,'A9'; a[30] := 1,active,'k9';


description
  'Multiple Gaussian peaks. #peaks = number of peaks.',
  '$BRead Markers...$ y := SUM(Ai*exp(-ki*(x-xi)^2)) + const';
  {note that the second string starts with $B...$, which indicates
   that there should be a button in the Parameters window}
 var
   i:integer;

procedure Check;
 var xm, ym,i,max;
begin
 if pNumber = 30000 then  {if button clicked, pNumber is always 30000}
 begin
  max := 0;
  for i := 0 to 8 do
  begin
    GetMarkedCoord(i,xm,ym);
    if not (Invalid(xm) or Invalid(ym)) then
    begin
      SetParameterProperties(param 3*i+4, value xm);
      SetParameterProperties(param 3*i+5, value ym-a[2]-a[3]*xm);
      max := i+1;
    end
    else
      SetParamDefaultValue(3*i+5, 0);
  end;
  SetParamDefaultValue(1, max);
  check := update;
 end
 else if pNumber = 1 then
 begin
   for i := 0 to 8 do
     if a[1] > i then
     begin
        if mode[3*i+3] = constant then mode[3*i+4] := active;
        if mode[3*i+4] = constant then mode[3*i+5] := active;
        if mode[3*i+5] = constant then mode[3*i+6] := active;
     end
     else
     begin
       mode[3*i+4] := constant;
       mode[3*i+5] := constant;
       mode[3*i+6] := constant;
     end;
   check := update;
   SetFunctionProperties(nrParams 3*a[1]+3);
 end
 else check := ok;
end;

begin
  y := a[2] + a[3]*x;
  for i := 1 to a[1] do
    y := y + a[3*i+2]*exp(-a[3*i+3]*sqr(x-a[3*i+1]));
end;

-----------

Hope this helps.

Best regards

Kurt Sutter



On 17. Dec 2009, at 14:21, Ludovic Pecqueur wrote:

> Dear Profit developers,
> 
> I would like to fit a curve with multiple peaks that may be described by a logNormal distribution.
> I really appreciate the way multiple peaks fitting is implemented in the Peaks function (ie the user definition of the number of peaks ...)
> 
> I would like to implement the log Normal distribution function in the same way as the built-in function and I was wondering if the Profit developers could release the piece of code of the "Peaks"  function so that I could use it as a base for my particular case.
> 
> Thank you for your help
> 
> Ludovic
> 
> 
> 
> 
> 
> 
> _______________________________________________
> proFit-list mailing list
> proFit-list at quantum-soft.com
> http://quantum-soft.com/mailman/listinfo/profit-list_quantum-soft.com




More information about the proFit-list mailing list