[GENERAL INFORMATION]
Function Name=SineDamp
Brief Description=sine damp function
Function Source=fgroup.SineDamp
Function Type=Built-in
Function Form=Expression
Number Of Parameters=4
Number Of Independent Variables=1
Number Of Dependent Variables=1
 
[FITTING PARAMETERS]
Naming Method=User-Defined
Names=xc,w,t0,A
Meanings=center,width,decay constant,amplitude
Initial Values=
Lower Bounds=--(I,Off),0(X,On),0(X,On),0(X,Off)
Upper Bounds=--(I,Off),--(I,Off),--(I,Off),--(I,Off)
Number Of Significant Digits=


[FORMULA]
y=A*exp(-x/t0)*sin(PI*(x-xc)/w)


[CONSTRAINTS]
/*Enter general linear constraints here*/


[CONSTANTS]


[Parameters Initialization]
sort(x_y_curve);
int i,k,N=y_data.GetSize();
double t,m,freq,phi;
vector r(N);
vector<complex> vc(N),vr(N);
t=x_data[2]-x_data[1];
vc=y_data;
FFT(vc,vr);
vr.GetAmplitude(r);
Dataset temp1(r);
BasicStats bsStat1;
Data_sum(&temp1,&bsStat1);
k=bsStat1.iMax;
m=bsStat1.max;
if (k==0) 
{	
	r[k]=0;
	Dataset temp2(r);
	BasicStats bsStat2;
	Data_sum(&temp2,&bsStat2);
	k=bsStat2.iMax;
	m=bsStat2.max;
}
if(k>N/2) k=N-k;
A=m*2.0/sqrt(N);
freq=k/(t*N);
w=1.0/(2.0*freq);
phi=atan2(vr[k].m_im,vr[k].m_re);
xc=-phi*w/pi-w/2;
Dataset y1(y_data),y2(y_data);
y1.SetUpperBound(N/2-1);
y2.SetLowerBound(N/2);
y1.TrimRight(true);
y2.TrimLeft(true);
int k1,n1=y1.GetSize(),n2=y2.GetSize();
vector r1(n1),r2(n2);
vector<complex> vc1(n1),vc2(n2),vr1(n1),vr2(n2);
double m1,Tm=max(x_data);
vc1=y1;
FFT(vc1,vr1);
vr1.GetAmplitude(r1);
Dataset t1(r1);
BasicStats bs1;
Data_sum(&t1,&bs1);
k1=bs1.iMax;
m1=bs1.max;
vc2=y2;
FFT(vc2,vr2);
vr2.GetAmplitude(r2);
t0=Tm/(2.0*ln(m1/r2[k1]));


[INITIALIZATIONS]
/*Code to be executed before fitting, a good place for complicated initialization.*/


[AFTER FITTING]
/*Code to be executed after fitting, a good place for generating results.*/


[ON PARAM CHANGE]
/*Code to be executed when parameters change.*/


[INDEPENDENT VARIABLES]
x=


[DEPENDENT VARIABLES]
y=


[CONTROLS]
General Linear Constraints=Off
Initialization Scripts=Off
Scripts After Fitting=Off
Number Of Duplicates=N/A
Duplicate Offset=N/A
Duplicate Unit=N/A
Generate Curves After Fitting=Yes
Curve Point Spacing=Uniform on X-Axis Scale
Generate Peaks After Fitting=Yes
Generate Peaks During Fitting=Yes
Generate Peaks with Baseline=Yes
Paste Parameters to Plot After Fitting=Yes
Paste Parameters to Notes Window After Fitting=Yes
Generate Residuals After Fitting=No
Keep Parameters=No
Enable Parameters Initialization=N/A
Compile On Param Change Script=1


[COMPILE FUNCTION]
Compile=0
Compile Parameters Initialization=1
On Param Change Scripts Enabled=N/A


[ORIGIN C FUNCTION HEADER]



[ORIGIN C PARAMETER INITIALIZATION HEADER]
#include <origin.h>
//#include <stdio.h>
//#include <data.h>
#include <matrix.h>
//#include <math.h>
//#include <vector.h>
#include <utilities.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.



