[GENERAL INFORMATION]
Function Name=Fourier2D
Brief Description=
Function Source=fgroup.Fourier2D
Function Type = Built-in
Function Form=Equations
Number Of Parameters=7
Number Of Independent Variables=2
Number Of Dependent Variables=1
Analytical Derivatives for User-Defined=Off


[FITTING PARAMETERS]
Naming Method=User-Defined
Names=z0, a, b, c, d, w1, w2
Meanings=?
Initial Values=--(V)
Lower Bounds=--(X,OFF)
Upper Bounds=--(X,OFF)
Number Of Significant Digits=


[FORMULA]
z=z0+a*cos(x/w1)+b*sin(x/w1)+c*cos(y/w2)+d*sin(y/w2);


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


[CONSTANTS]


[Parameters Initialization]

double t,k,m,freq;

Curve x_curve, y_curve;
bool bRes = get_interpolated_xz_yz_curves_from_3D_data(x_curve, y_curve, x_data, y_data, z_data);
if(!bRes) return; 

int nVecSize = x_curve.GetSize();

vector<complex> vc(nVecSize);
vector vAmpl(nVecSize);

z0 = min(z_data);

vector vX, vY, vZ;

x_curve.CopyData(vX, vZ);
t = vX[2]-vX[1];
vc = vZ;
fft_complex(vX.GetSize(), vc);
vc.GetAmplitude(vAmpl);
double dMin, dMax; 
int iMin, iMax;
vAmpl.GetMinMax(dMin,dMax,&iMin,&iMax);
k = iMax;
m = dMax;
if (k==0) 
{	
	vAmpl[k]=0;
	vAmpl.GetMinMax(dMin, dMax, &iMin, &iMax);
	k = iMax;
	m = dMax;
}

if(k > nVecSize/2) k = nVecSize - k;
a=m/sqrt(nVecSize);
b=a;
freq=k/(t*nVecSize);
w1=1.0/(10.0*freq);


y_curve.CopyData(vY, vZ);
t = vY[2]-vY[1];
vc = vZ;
fft_complex(vX.GetSize(), vc);
vc.GetAmplitude(vAmpl);
vAmpl.GetMinMax(dMin,dMax,&iMin,&iMax);
k = iMax;
m = dMax;
if (k==0) 
{	
	vAmpl[k]=0;
	vAmpl.GetMinMax(dMin, dMax, &iMin, &iMax);
	k = iMax;
	m = dMax;
}


if(k > nVecSize/2) k = nVecSize - k;
c = m/sqrt(nVecSize);
d = c;
freq=k/(t*nVecSize);
w2 = 1.0/(10.0*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=
y=


[DEPENDENT VARIABLES]
z=


[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=0
Compile On Param Change Script=1


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


[ORIGIN C FUNCTION HEADER]



[ORIGIN C PARAMETER INITIALIZATION HEADER]
#include <origin.h>
#include <nag_utils.h>
#include <fft_utils.h>


