T O P I C R E V I E W |
hgibhar |
Posted - 12/21/2016 : 08:33:35 AM Origin Ver. and Service Release (Select Help-->About Origin): 9 Operating System: 7 prof 64bit
Hi all,
I want to fit a spectrum with 2 peaks (voigtians with linear background) (from Worksheet without plotting). For this, I wrote a new fitting function with OriginC (tools). I would like to initialize the peak parameters using the function
ocmath_find_peaks_2nd_derivative
If I compile the code attached at the end in workbuilder, I get a compilation error (in the line with the find_peaks-function)
compiling... _nlpvgt2.fit xxxxxx\OriginC\NLSF\_nlpvgt2.fit(76) :Fehler, Nichtkompatible Variablentypen in Ausdruck xxxxxx\OriginLab\90\OriginC\NLSF\_nlpvgt2.fit(76) :Fehler, Nichtkompatible Variablentypen in Ausdruck xxxxxx\OriginLab\90\OriginC\NLSF\_nlpvgt2.fit(76) :Fehler, allgemeiner Kompilierungsfehler xxxxxx\OriginLab\90\OriginC\NLSF\_nlpvgt2.fit(31) :Fehler, Fehler gefunden in Kompilierungsfunktion _nlsfParamvgt2 Kompilieren fehlgeschlagen!
The example for the pure function ocmath_find_peaks_2nd_derivative from the help-file works very well (but this example is with plotting first) and I can find correct initial parameters for the fitting function.
Can anybody tell me, what the problem in _nlsfParamvgt2 is? const double * ???? vector& ????
Thx Holger
#pragma numlittype(push, TRUE) #pragma numlittype(push, TRUE) #pragma numlittype(push, TRUE) #pragma numlittype(push, TRUE) #pragma numlittype(push, TRUE) #pragma numlittype(push, TRUE) #include <origin.h>
// Add your special include files here. // For example, if you want to use functions from the NAG library, // add the header file for the NAG functions here.
// Add code here for other Origin C functions that you want to define in this file, // and access in your parameter initialization.
// You can access C functions defined in other files, if those files are loaded and compiled // in your workspace, and the functions have been prototyped in a header file that you have // included above.
// You can access NLSF object methods and properties directly in your function code.
// You should follow C-language syntax in defining your function.
// For instance, if your parameter name is P1, you cannot use p1 in your function code.
// When using fractions, remember that integer division such as 1/2 is equal to 0, and not 0.5
// Use 0.5 or 1/2.0 to get the correct value.
// For more information and examples, please refer to the "User-Defined Fitting Function"
// section of the Origin Help file.
//----------------------------------------------------------
//
void _nlsfParamvgt2(
// Fit Parameter(s):
double& y0, double& m, double& xc1, double& A1, double& wG1, double& wL1, double& xc2,
double& A2, double& wG2, double& wL2,
// Independent Dataset(s):
vector& x_data,
// Dependent Dataset(s):
vector& y_data,
// Curve(s):
Curve x_y_curve,
// Auxilary error code:
int& nErr)
{
// Beginning of editable part
//Code to be executed to initialize parameters
//seeking linear background
sort(x_y_curve);
double xMin,xMax,yMin,yMax;
Curve_MinMax(&x_y_curve,&xMin,&xMax,false,&yMin,&yMax);
y0 = yatxmin( x_y_curve );
m=(yatxmin( x_y_curve ) - yatxmax( x_y_curve )) /(xMin - xMax) ;
//seeking 2 peaks in data for guessing start parameters
uint nDataSize = x_data.GetSize();
int iSize = x_data.GetSize();
vector vxPeaks, vyPeaks;
vector<int> vnIndices;
vxPeaks.SetSize(nDataSize);
vyPeaks.SetSize(nDataSize);
vnIndices.SetSize(nDataSize);
int nRet;
nRet = ocmath_find_peaks_2nd_derivative( &nDataSize, &x_data, &y_data, vxPeaks, vyPeaks, vnIndices, POSITIVE_DIRECTION | NEGATIVE_DIRECTION, 1, NULL, 19, 3);
if( nRet < OE_NOERROR )
{
printf("error code: %d\n", nRet);
return;
}
vxPeaks.SetSize(nDataSize);
vyPeaks.SetSize(nDataSize);
vnIndices.SetSize(nDataSize);
double ymaxfirst,ymaxsecond;
int indexmaxfirst,indexmaxsecond;
//first peak maximum
ymaxfirst=0;
int j;
for(j=0;j<nDataSize;j++){
if(vyPeaks[j]>ymaxfirst){
indexmaxfirst=j;
ymaxfirst=vyPeaks[j];
}
}
printf("j=%d xc=%f amp=%f\n",indexmaxfirst,vxPeaks[indexmaxfirst],ymaxfirst);
//second peak maximum
ymaxsecond=0;
for(j=0;j<nDataSize;j++){
if ((vyPeaks[j]>ymaxsecond) && (vyPeaks[j]<ymaxfirst)) {
indexmaxsecond=j;
ymaxsecond=vyPeaks[j];
}
}
//printf("j=%d xc=%f amp=%f\n",indexmaxfirst,vxPeaks[indexmaxsecond],ymaxsecond);
xc1=vxPeaks[indexmaxfirst];
A1=vyPeaks[indexmaxfirst];
wG1=1.5;
wL1=1.1;
xc2=vxPeaks[indexmaxsecond];
A2=vyPeaks[indexmaxsecond];
wG2=1.5;
wL2=1.1;
// End of editable part
} |
2 L A T E S T R E P L I E S (Newest First) |
hgibhar |
Posted - 12/22/2016 : 03:33:17 AM Dear Yuki,
thx very much! Now it works! Especially the second point.
Best wishes for the new year! Holger |
yuki_wu |
Posted - 12/22/2016 : 02:34:28 AM Hi Holger,
You should modified that line of ocmath_find_peaks_2nd_derivative as below:
nRet = ocmath_find_peaks_2nd_derivative( &nDataSize, x_data, y_data, vxPeaks, vyPeaks, vnIndices, (int)POSITIVE_DIRECTION | (int)NEGATIVE_DIRECTION, 1, NULL, 19, 3);
This is to say: 1.Remove “&” at the front of x_data and y_data. You can check the syntax here: http://www.originlab.com/doc/OriginC/ref/ocmath_find_peaks_2nd_derivative
2.Force to convert the type of Control ID back to integer. Since there is a piece of code at the beginning of the file:
#pragma numlittype(push, TRUE);
which means to make Origin C compiler to treat all numeric literals as double type. Thus, you have to convert the type of Control ID, or it cannot perform logical operations.
Hope this can be some help.
Regards, Yuki OriginLab
|
|
|