| Author |
Topic  |
|
|
VauWe
9 Posts |
Posted - 07/18/2017 : 09:31:21 AM
|
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 2015 SR2 b.9.2.272 Operating System: Win7
Hi, I am trying to make a multiple gaussian peak fit of a "broad" peak by labtalk. The problem is, that only 1 peak is fitted and the cumulative fit is equal to the first peak fit. The second peak is a flat liner. As a result the convergence of the fit is pour. I want to add the graph as image, but failed :-(. The code is as follows:
// Peak Fit
int nCumFitCol = wks.nCols+1;
nlbegin iy:=(1,3) func:=gauss replica:=1 nltree:=tt;
tt.y0__1 = 0;
tt.y0__2 = 0;
tt.xc__1 = 615; // center peak 1
tt.xc__2 = 650; // center peak 2
tt.A__1 = 0; // area peak 1
tt.A__2 = 0; // area peak 2
tt.w__1 = 20;
tt.w__2 = 30;
nlfit;
range yy = nCumFitCol;
yy = fit(col(1)); // use fit() function to generate fit curve to last column using 1st column as X
yy[L]$ = %(str2$)_CumFit;
loop(ii, 1, 2) {
range pk = wcol(nCumFitCol+ii);
pk = fit(col(1), ii);
pk[L]$ = %(str2$)_FitPeak$(ii);
}
nlend 1;
plotxy iy:=(1,4) ogl:=[PeakFit_PLgraph]1! plot:=200;
plotxy iy:=(1,5) ogl:=[PeakFit_PLgraph]1! plot:=200;
plotxy iy:=(1,6) ogl:=[PeakFit_PLgraph]1! plot:=200;
Any ideas what's wrong with the code? regards vauwe
|
|
|
yuki_wu
896 Posts |
Posted - 07/18/2017 : 11:30:39 PM
|
Hi Vauwe,
I think you should modify the parameter variables as follows:
tt.y0 = 0;
tt.xc = 615;
tt.xc__2 = 650;
tt.A = 0;
tt.A__2 = 0;
tt.w = 20;
tt.w__2 = 30;
You can check it in the Parameter tab of NLFit dialog:

Regards, Yuki OriginLab
|
Edited by - yuki_wu on 07/18/2017 11:34:03 PM |
 |
|
|
VauWe
9 Posts |
Posted - 07/19/2017 : 11:03:30 AM
|
@yuki_wu Have changed the parameter variables as follows:
win -a PLQEv2D;
int nCumFitCol = wks.nCols+1;
nlbegin iy:=(1,3) func:=gauss replica:=1 nltree:=tt;
tt.y0 = 0;
tt.xc = 615;
tt.xc__2 = 650;
tt.A = 0;
tt.A__2 = 0;
tt.w = 20; // center peak 2
tt.w__2 = 30;
nlfit;
range yy = nCumFitCol;
yy = fit(col(1)); // use fit() function to generate fit curve to last column using 1st column as X
yy[L]$ = %(str2$)_CumFit;
loop(jj, 1, 2) {
range pk = wcol(nCumFitCol+jj);
pk = fit(col(1), jj);
pk[L]$ = %(str2$)_FitPeak$(jj);
}
nlend 1;
// nlend 1;
plotxy iy:=(1,4) ogl:=[PeakFit_PLgraph$(ii)]1! plot:=200;
plotxy iy:=(1,5) ogl:=[PeakFit_PLgraph$(ii)]1! plot:=200;
plotxy iy:=(1,6) ogl:=[PeakFit_PLgraph$(ii)]1! plot:=200;
Now I get 3 horizontal flatliners. Peak1 and cumulative fit is still the same, peak2 has smaller y value. I don't know what happen! Has anyone a working labtalk script for a multiple peak fit (2 peaks)? vauwe |
 |
|
|
yuki_wu
896 Posts |
Posted - 07/19/2017 : 11:37:23 PM
|
Hi,
1. I notice that you haven’t declare str2$ in your given code. If you really fogot to declare str2$ in your complete code, please declare it at first.
2. Did you see an error message when you excuted this piece of script: Unknown, VarName = iy, VarValue = (1,5) If yes, you could modify as follows:
//make sure to plot the data in the active worksheet
nlend;
plotxy iy:=((1,5), (1,6), (1,7)) ogl:=[PeakFit_PLgraph]1! plot:=200;
//if you want to create the fitting report after fitting, use this:
//nlend 1;
//plotxy iy:=[BookName]SheetName!(Col(1),Col(4):Col(6)) ogl:=[PeakFit_PLgraph]1! plot:=200;
3. It seems that you want to fit the data in col(3), so make sure you have put the data in col(3) and set col(1) as X.
4. Not sure why you set the initial value of A and A__2 as 0 since A specifies the area under the curve. You should perform the fitting via NLfit dialog, and check if the initial parameters you set in code are right.

We have a similar example, you may have a look: http://www.originlab.com/doc/LabTalk/examples/Curve-Fitting#Fit_Multiple_Peaks_with_Replica
Regards, Yuki OriginLab
|
Edited by - yuki_wu on 07/19/2017 11:38:22 PM |
 |
|
|
VauWe
9 Posts |
Posted - 08/03/2017 : 06:38:11 AM
|
Hi yuki_wu,
thanks a lot. Now I can add the 2 peak fits + cumulative fits in my graph. But the second peak fit is a flat liner. Peak fit 1 and cumulative fit is the same. Code is as follows:
win -a PLQEv2D;
int nCumFitCol = wks.nCols+1;
nlbegin iy:=(1,3) func:=gauss replica:=1 nltree:=tt;
// tt.y0 = 0;
tt.xc = 550;
tt.xc__2 = 575;
// tt.A = 0;
// tt.A__2 = 0;
tt.w = 40; // center peak 2
tt.w__2 = 50;
nlfit;
range yy = nCumFitCol;
yy = fit(col(1)); // use fit() function to generate fit curve to last column using 1st column as X
yy[L]$ = %(str2$)_CumFit;
loop(jj, 1, 2) {
range pk = wcol(nCumFitCol+jj);
pk = fit(col(1), jj);
pk[L]$ = %(str2$)_FitPeak$(jj);
}
nlend 1;
plotxy iy:=[PLQEv2D]%(str2$)!(col(1),col(4):col(6)) ogl:=[PeakFitGraph$(ii)]1! plot:=200; // plot col 4 - 6 in graph
And yes, I have declared str2$ a few lines above (not seen in the code here).
My feeling is, there is only 1 iteration and than there is a failure (fit status is Failed(-103).
Any ideas
Kind regards
VauWe |
 |
|
|
yuki_wu
896 Posts |
Posted - 08/10/2017 : 02:49:21 AM
|
Hi,
I noticed that you use nlfit, and it means to fit until converge. I don’t think the error message is caused by only 1 iteration.
nlfit 1; // do only one iteration
nlfit; // fit until converge
For a detailed explanation of the syntax, please refer to this help file page: http://www.originlab.com/doc/X-Function/ref/nlfit
Have you tried to perform the nonlinear in GUI as I suggested above? Good initial values is the key of a good fit.
Regards, Yuki OriginLab
|
 |
|
|
VauWe
9 Posts |
Posted - 03/22/2018 : 08:08:00 AM
|
Hi, I come back to my nlfit work. The data sets changed a bit and the script do not use the baseline properly. I would set the baseline to y0 = 0, but it does not work. Code is as follows:
win -a LuMiDat;
int nCumFitCol = wks.nCols+1;
range ss =[LuMiDat]%(str2$)!col(4); // range for CorrPower PL column
limit ss;
int ymax = limit.ymax;
int imax = limit.imax;
int xmax = col(1)[$(imax)];
nlbegin iy:=(1,4) func:=gauss replica:=1 nltree:=tt;
tt.y0 = 0;
tt.xc = xmax - 10;
tt.xc__2 = xmax + 10;
tt.A = 20;
tt.A__2 = 20;
tt.w = 30;
tt.w__2 = 35;
nlfit;
range yy = nCumFitCol;
yy = fit(col(1));
yy[L]$ = %(str2$)_CumFit;
loop(jj, 1, 2) {
range pk = wcol(nCumFitCol+jj);
pk = fit(col(1), jj);
pk[L]$ = %(str2$)_FitPeak$(jj);
}
nlend 1;
The result is as follows:

Thanks a lot for any help.
vau |
 |
|
|
yuki_wu
896 Posts |
Posted - 03/22/2018 : 10:27:05 PM
|
Hi,
You only show a part of the result and I can not even see the Y axis.Not sure what the data looks like and the value of baseline offset y0 you got after performing fitting.
However, if you hope to fix the y0 value at 0, you could use the script like: tt.y0=0; tt.f_y0=1;
Hope this can be some help.
Regards, Yuki OriginLab
|
 |
|
| |
Topic  |
|
|
|