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


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


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


[CONSTANTS]


[Parameters Initialization]
sort(x_y_curve);
//smooth(x_y_curve);
int i,k,N=y_data.GetSize();
double t,m,freq,phi;
vector r(N);
vector<complex> vc(N);
t=x_data[2]-x_data[1];
vc=y_data;
fft_complex(N, vc);
vc.GetAmplitude(r);

double dMin,dMax;
int iMin, iMax;
r.GetMinMax(dMin,dMax,&iMin, &iMax);

k=iMax;
m=dMax;
if (k==0) 
	{	
		r[k]=0;
		r.GetMinMax(dMin,dMax,&iMin,&iMax);
		k=iMax;
		m=dMax;
	}
if(k>N/2) k=N-k;
y0 = 0.5*( max(y_data) + min(y_data) );
freq=k/(t*N);
w=1.0/(2.0*freq);
phi=atan2(vc[k].m_im,vc[k].m_re);
xc = xatymax(x_y_curve);
if( xc == NANUM) xc = 0;
if( xc < - 0.5*w ) 
{
	while( xc < -0.5*w ) xc = xc + 2*w;
}
if( xc >= 1.5*w )
{
	while( xc>1.5*w) xc = xc - 2*w;
}
xc = xc - 0.5*w;

// calculate t0;
vector yy;
vector vcoeff;
yy.SetSize(x_data.GetSize());
yy = log( (y_data - y0 )/(sin( PI*(x_data-xc)/w ) ));
fitpoly( x_data, yy, 1, vcoeff );
A = exp( vcoeff[0]);
t0 = fabs(1/vcoeff[1]); // to make sure it is in decay


[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=2
Duplicate Unit=4
Peak Center=2
Peak Width=3
Peak Amplitude=5
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 <fft_utils.h>


[Moments]
mz0 =  N.A.
mz1 =  N.A.
mc2 =  N.A.
mc3 =  N.A.
mc4 =  N.A.


