The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 labtalk nlsf non-replica multipeak & constraint
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cab0008

25 Posts

Posted - 02/19/2011 :  5:41:23 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello everyone,

I was wondering if anyone had a good solution to creating multiple peaks by the nlsf begin method but using more than just one type of peak. Also, I was hoping that someone may be able to help with creating a constraint that says something like "experimental dataset values >= fitting values" so that the fitted function would act more as a baseline.

The reason I need the multiple peaks is to fit a spectrum with 5 lorentzians (only one coded so far) and 1 BWF. However, before I do that I would like to do savitsky golay smoothing and then subtract off a baseline using a fitting function.

So far for the baseline Iv'e just been trying to subtract off an average value at two places, but this isn't always going to work.
And for the multiple peak fit, I've been doing one lorentzain fit and then taking a temporary dataset with the lorentzian subtracted from it, and fitting the BWF to that. I suspect that there's an easier way to do this, especially since I'm planning on adding many more peaks. Here's what Iv'e been trying so far:

//scalars for %calc
double sSC;
double sM;
//scalar to be subtracted as "baseline"
double sBase;
//scalar from first and second range to be considered
double sBase1;
double sBase2;
//sum of ranges 1 and 2
double sumBase1;
double sumBase2;

//open workbook and add relevant columns
work -b [RAMAN];
if [RAMAN]Sheet1.ncols <> 5 then work -a 2;

//ranges for "baseline"
range rBase1=[RAMAN]Sheet1!2[1132]:2[1358];
range rBase2=[RAMAN]Sheet1!2[1725]:2[1931];

//get averages and calc. "baseline"
sum(rBase1);
sumBase1=sum.total;
sBase1 = sumBase1/(1358-1132);
sum(rBase2);
sumBase2=sum.total;
sBase2 = sumBase2/(1931-1725);
sBase=(sBase2+sBase1)/2;

//ranges for spectra fitting and results
range rWSRslt = [RESULTSGF]Sheet1!;
range rRmn = [RAMAN]Sheet1!Col(2);
range rRmnx = [RAMAN]Sheet1!Col(1);
range rFitTotal = [RAMAN]Sheet1!Col(3);
range rSC=[RAMAN]Sheet1!Col(4);
range rM=[RAMAN]Sheet1!Col(5);

//subtract "baseline" from initial spectra
rRmn = rRmn - sBase;

//names for fitting function columns
rSC[L]$ = "SC lorentzian";
rM[L]$ = "M BWF";


//begin fitting for lorentz profile
nlbegin iy:=[RAMAN]Sheet1!2[1235]:2[1515] func:=Lorentz nltree:=myt;

//baseline should be taken care of (=0) and fixed
myt.p1=0;
myt.f1=1;

//peak center around 1580~1590
myt.p2=1587;
myt.lbon2=1;
myt.lb2=1570;
myt.ubon2=1;
myt.ub2=1600;
//width
myt.p3=20;
myt.lbon3=1;
myt.lb3=0;
myt.ubon3=1;
myt.ub3=50;
//amplitude
myt.p4=0;
myt.lbon4=1;
myt.lb4=0;
//myt.ubon4=1;
//myt.ub4=1;

nlfit 200;

rSC = fit(rRmnx);

nlend;

sec;

//create new temporary range to fit
range _rtemp = [Book1]Sheet1!Col(2);
_rtemp = rRmn - rSC;

range _rtempx = [Book1]Sheet1!Col(1);
_rtempx = rRmnx;

//fit only the same portion of it
range rBWFcalc = [Book1]Sheet1!2[1235]:2[1515];
range rBWFcalcx = [Book1]Sheet1!Col(1);

//begin BWF fit
nlbegin iy:=rBWFcalc func:=BWF nltree:=myt1;

//nlsf.Execute("parainit");
//baseline (set again to 0)
myt1.p1=0;
myt1.f1=1;

//peak center
myt1.p2=1550;
myt1.lbon2=1;
myt1.lb2=1520;
myt1.ubon2=1;
myt1.ub2=1570;

//H
myt1.p3=80;
myt1.lbon3=1;
myt1.lb3=0;
myt1.ubon3=1;
myt1.ub3=200;

//w
myt1.p4=30;
myt1.lbon4=1;
myt1.lbon4=.01;
myt1.ubon4=1;
myt1.ub4=100;

//q
myt1.p5=-6;
myt1.lbon5=1;
myt1.lbon5=-30;
myt1.ubon5=1;
myt1.ub5=0;


nlfit 200;

rM=fit(rBWFcalcx);

nlend out:=1;

sec;

//total fit BWF + lorentzians
rFitTotal = rSC+rM;
rFitTotal[L]$ = "SC+M Total Fit";

//area of SC range
sum(rSC);
sSC=sum.total;

//area of M range
sum(rM);
sM=sum.total;

//add column to results to place % in
rWSRslt.addCol(RamanFit SC);
sec;
[RESULTSGF]Sheet1!cell(1,rWSRslt.ncols)=sSC/(sM+sSC);


we'll be using this code on the same structured data many times a day but we still have other types of spectra to do similar types of analysis on, so any help is greatly appreciated and will be used many times over.

Origin Ver. and Service Release (Select Help-->About Origin): 8.0 SR5
Operating System: windows xp

larry_lan

China
Posts

Posted - 02/22/2011 :  04:26:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Nonlinear fitting cannot fit more than one functions at a time. Now that you have multiple peaks, you can either define a "multiple peaks" function, or perform 6 fits in a loop.

The Peak Analyzer allows you select different peaks for one curve, and also supports fit, subtract a baseline before fitting. However, it's not LabTalk accessible, you can do that in GUI only.

Thanks
Larry
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000