[GENERAL INFORMATION]
Function Name=SineSqr
Brief Description=sine square function
Function Source=fgroup.SineSqr
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=y0,xc,w,A
Meanings=offset,phase shift,period,amplitude
Lower Bounds=--(X,Off),--(X,Off),0.0(X,On)
Upper Bounds=--(X,Off),--(X,Off),--(X,Off)
Number Of Significant Digits=


[FORMULA]
y= y0 + A*(sin(pi*(x-xc)/w))^2


[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 = min(y_data);
freq=k/(t*N);
w=1.0/freq;
phi=atan2(vc[k].m_im,vc[k].m_re);
A = max(y_data) - min(y_data);

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;

[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=3
Peak Center=2
Peak Width=3
Peak Amplitude=4
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.
