[GENERAL INFORMATION]
Function Name=SineSqr
Brief Description=sine square function
Function Source=fgroup.SineSqr
Function Type=Built-in
Function Form=Expression
Number Of Parameters=3
Number Of Independent Variables=1
Number Of Dependent Variables=1

 
[FITTING PARAMETERS]
Naming Method=User-Defined
Names=xc,w,A
Meanings=center,width,amplitude
Lower Bounds=--(X,Off),0.0(X,On),--(X,Off)
Upper Bounds=--(X,Off),--(X,Off),--(X,Off)
Number Of Significant Digits=


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


[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=2.0*m*2.0/sqrt(N);
freq=k/(t*N);
w=1.0/freq;
phi=atan2(vr[k].m_im,vr[k].m_re);
xc=-(phi+pi)/(2.0*pi*freq);


[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 <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.



