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
 Centroids
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

josbpatin

USA
3 Posts

Posted - 05/21/2003 :  1:07:05 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I'm trying to fit spectral data and I do not want to use the Gaussian peak fit function. I'd much rather find the centroid of the region I've set then to find the center of the Gaussian. I have a mathematical formula that I use in Excel, but it would make my life much easier if there was a simple fit function, or script command that could find the centroid for me.

I have a generic c code that calculates these values as well, but I'd much rather again have something in Origin.

Any help would be appreciated.

josbpatin

easwar

USA
1965 Posts

Posted - 05/21/2003 :  2:17:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

With the data column highlighted/selected, or with the dataset plotted in a graph, go to script window and type:
integ %c
You can then get the max y value using
integ.y0=
and you can get the x value corresponding to max y value using
integ.y0=

Note: %c just refers to active dataset/data plot. You can use literal dataset name instead, such as:
integ data1_b
Also, you can set limits on your plot using data markers etc. to restrict the integ command to operate on only part of your data.

For more information on the integ command, refer to LabTalk documentation/help file.

You should be able to port your generic c code to Origin C (version 7) and have that operate as a command from the script window, to compute your parameters. Also, you could port your Excel function to Origin C or LabTalk. If you need help with either of these, please post specifics/code here, or contact tech support.


Easwar
OriginLab.

Go to Top of Page

josbpatin

USA
3 Posts

Posted - 05/22/2003 :  11:22:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for the suggestion. I'm assuming that the integ command is similar to the Integrate command found in the Analysis/Calculus window.

I've seen that command but require more precision than just the channel with the most counts.

The formula that I would like to use looks something like this in C-code.

for (j=1;j<=bins;j++)
{
centroidvalue=channel[j]*value[j]/sumvalue;
centroid=centroid+centroidvalue;
}

'bins' would correspond to the total number of channels that would be in the peak of interest, between the two data markers. 'channel' and 'value' are self-explanatory. 'sumvalue' would be the sum of the values of all the channels.

I have a beginners experience with C and little to none with C in Origin. Any help with coding this little formula so that I could use this in the future would be a tremendous help not only to me, but also to others I'm sure.

Thanks in advance,

josbpatin
Go to Top of Page

easwar

USA
1965 Posts

Posted - 05/22/2003 :  12:34:11 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Origin C code for computing centroid using your formula is pasted below.

Here are some instructions:
1> version 7 SR3 or higher recommended - get the SR3 patch if you don't have it already
2> Open Code Builder (menu: View->Code Builder)
3> Create new C file (menu: File->New), give name such as centroid.c
4> Cut and paste code from below into window, and compile and build
5> Now you can go to script window and type the command:
centroid %c
OR
centroid data1_b
etc.
You should see output such as:
centroid %c;
Curve name: Gaussian_Ampl
X range: 8.000000 to 41.000000
Centroid = 24.827855

6> To make this funciton available to you in all Origin sessions, go back to Code Builder, and drag-and-drop your C file from User folder to System folder in the Code Builder Workspace tree. From now on, any time you start Origin, your function will be compiled and ready to use. Note that this requires SR3 - the tree strucutre was added in SR3.

Easwar
OriginLab.




void centroid(string strCurve)
{
Curve crv( strCurve );
Dataset dsX;
crv.AttachX(dsX);
if( !crv || !dsX )
{
printf("%s is not a valid curve!\n", strCurve);
return;
}

int iBegin = crv.GetLowerBound();
int iEnd = crv.GetUpperBound();
double dCentroid = 0, dSum = 0;

for( int j = iBegin; j <= iEnd; j++)
{
dCentroid += dsX[j] * crv[j];
dSum += crv[j];
}
dCentroid /= dSum;

printf("Curve name: \t %s\n", strCurve);
printf("X range: \t %f to %f\n", dsX[iBegin], dsX[iEnd]);
printf("Centroid = \t %f\n\n", dCentroid);
}


Go to Top of Page

josbpatin

USA
3 Posts

Posted - 05/22/2003 :  4:51:33 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks so much for the code and the instructions. I have it working and it looks like it works rather well.

Thanks again, this rather simplifies my life greatly!
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