三角函数拟合源代码

[GENERAL INFORMATION]
Function Name=Sine
Brief Description=sine function
Function Source=fgroup.Sine
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
Initial Values=
Lower Bounds=–(X,Off),–(X,Off),0(X,On)
Upper Bounds=–(X,Off),–(X,Off),–(X,Off)
Number Of Significant Digits=


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


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


[CONSTANTS]
[Parameters Initialization]

vector<uint> vi;
x_data.Sort(SORT_ASCENDING, TRUE, vi);
y_data.Reorder(vi);
int N=y_data.GetSize(); N表示数据点的个数
double t;
vector r(N);
vector<complex> vc(N);
t = (x_data[N-1] - x_data[0]) / (N-1);
vc=y_data;
fft_complex(N, vc);
vc.GetAmplitude®;
if (t==0)
{
y0 = r[0] / N;
A = 0;
w = 1;
return;
}

y0 = r[0] / N;
double dMin,dMax;
y_data.GetMinMax(dMin, dMax);
A = 0.5 * (dMax - dMin);
int iMin, iMax;
r[0] = NANUM;
r.GetMinMax(dMin,dMax,&iMin, &iMax);

int k=iMax;
if(k>N/2) k=N-k;
double freq=k/(t*N);
w=1.0/(2.0*freq);

xc = xatymax(x_y_curve);
if( xc == NANUM) xc = 0;
xc = xc - 2*w*floor(xc/2/w) - 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.

讨论区

很好啊!开头加一段说明吧。 — 乐永康 2014/04/22 20:59