Author |
Topic  |
|
Geneiah
Singapore
Posts |
Posted - 10/27/2004 : 10:44:10 AM
|
Origin Version : 6.1 Operating System: Win XP
I am trying very hard to fit a curve with two user-defined functions. One has a asymmetrical lineshape; called the Breit-Wigner-Fano (BWF) function. The other is a symmetrical Breit-Wigner function.
I used the following equation for the BWF fitting;
y=(yg* (1 + 2*(x - xg)/(q*w))^ 2)/ (1 + (2*(x - xg)/w)^2) + (a + b*x);
Fitting single peak using this function is okay.
However, when I use the following equations for multi-peak fit (setting to y-script) (p2 is Breit-Wigner Function);
p1=(yg* (1 + 2*(x - xg)/(q*w))^ 2)/ (1 + (2*(x - xg)/w)^2) + (a + b*x);
p2=(yd)/ (1 + (2*(x - xd)/r)^2) + (a + b*x);
y=p1 + p2;
the fitting cannot work. And the values of some parameters after fitting goes beyond what Ive set in the constraint.
Even if the fitting using the two functions is successful, is it possible to get something like the graph fitted using two Lorentzians (i.e. with the two fitted peaks shown in the graph)?
Please advice!!! Really need the help!!! |
|
easwar
USA
1965 Posts |
Posted - 10/28/2004 : 10:51:30 AM
|
Hi,
First of all, you should avoid using variables such as p1,p2 etc which are reserved for parameter names. So I suggest renaming your two variables to peak1, peak2 and then y = peak1+peak2. See if that helps.
Also, in the Fitter function definition page, you need to set the Form drop-down at the bottom to Y-Script when using multiple lines of code. (In ver 7, 7.5, you can use Origin C).
If the above suggestions do not fix your problem, please contact tech support.
I tried the following funciton in ver 6.1 which is a combination of Gaussian and Lorentzian and it worked fine for me with some test data: Parameters: y0,Ag,xg,wg, Al,wl,xl Indep var: x Dep var: y Function code: peak1=Ag*exp(-(x-xg)^2/(2*wg^2)); peak2=Al*wl/((x-xl)^2+wl^2); y=y0+peak1+peak2;
As for setting constraints, did you also try setting bounds on the parameters, such as limiting the centroid of the peak so that the minimization routine does not take the centroid out of your set limits?
Easwar OriginLab
|
 |
|
Geneiah
Singapore
Posts |
Posted - 10/29/2004 : 02:19:53 AM
|
Thank you so much Easwar!!! The fitting can be done now, and the values are within the set boundary.
But is it possible for me to know the independent data points (y value)for each peak? |
 |
|
easwar
USA
1965 Posts |
Posted - 10/29/2004 : 1:24:06 PM
|
Hi,
The fit does create a single dataset which is a sum of the two peaks. In this case, to get individual datasets for each peak, you could write after-fit script such as below.
In NLSF tool, go to Scripts->After Fit panel, and paste the following code in the edit box, and check the "Enabled" checkbox. Save the function. Then when you fit with the function, and click the Done button on the Fit page, you will get a new worksheet with two Y columns that contain the individual peak data.
Note that the code here is for my example of Gaussian + Lorentzian. You will need to modify for your peak functions.
Easwar OriginLab
// Create a new wks and add a 3rd col win -t; wks.addcol(); // Fill first X col with 101 points over x range step = ( nlsf.dataend - nlsf.databegin ) / 100; %( %h, 1 ) = data( nlsf.databegin, nlsf.dataend, step); // Loop over all x and compute peak1 and peak2 for( i = 1; i <= 101; i++) { x = %( %h, 1, i ); %( %h, 2, i ) = y0 + Ag * exp( -( x - xg )^2 / ( 2 * wg^2 ) ); %( %h, 3, i ) = y0 + Al * wl / ( ( x - xl )^2 + wl^2 ); }
|
 |
|
Geneiah
Singapore
Posts |
Posted - 10/30/2004 : 02:41:19 AM
|
Thank you for your attention Easwar!
The dataset can be created with the code, and the shape is of the nature of the functions used. However, the data starts only at x=1. My data for x starts at 1000 to a higher value. I only need the data within this range, so is it possible to offset the starting point? I've have keyed in the value "1000" as "for( i = 1000; i <= 2000; i++)", but this will not work - no results has been computed. What have I done wrong?
Regards. . . |
 |
|
easwar
USA
1965 Posts |
Posted - 10/30/2004 : 11:22:07 AM
|
Hi,
Sorry...my mistake...the properties nlsf.begin and nlsf.end point to the row numbers of the fit data x columns and not to the x values themeselves. So try the following code instead.
You can then look up the nlsf object and its properties in the LabTalk help files to learn more.
Easwar OriginLab
// Create a new wks and add a 3rd col win -t; wks.addcol(); // Fill first X col with 101 points over x range %a = nlsf.x$; xbegin = %a[ nlsf.databegin ]; xend = %a[ nlsf.dataend ]; xstep = ( xend - xbegin ) / 100; %( %h, 1 ) = data( xbegin, xend, xstep ); // Loop over all x and compute peak1 and peak2 for( i = 1; i <= 101; i++) { x = %( %h, 1, i ); %( %h, 2, i ) = y0 + Ag * exp( -( x - xg )^2 / ( 2 * wg^2 ) ); %( %h, 3, i ) = y0 + Al * wl / ( ( x - xl )^2 + wl^2 ); }
|
 |
|
Geneiah
Singapore
Posts |
Posted - 10/31/2004 : 11:16:01 PM
|
Hi Easwar,
It works now beautifully! Thank you very much for your attention!
Best regards, Gene |
 |
|
|
Topic  |
|
|
|