|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
#include "mex.h"
#include "math.h"
/*****************************************************************
* the function is used to calculate correlation dimention with G-P algorithm
* data:the time series
* r: the r series
* N: the length of the time series
* delay : the delay of the time series
* rlen: the length of r series
* ln_C: the correlation dimention series
* xiaoxiaoyu
******************************************************************/
void G_P(double data[], double r[], int N, int m,
int rlen, int delay, double ln_C[],double ln_r[])
{
double distance;
double max=0;
int cr=0;
int i,j,k,l;
double Cr=0;
int M=N-(m-1)*delay;
for (l=0; l<rlen; l++)
{
for (i=0; i<M-1; i++)
{
for (j=i+1; j<M; j++)
{
for (k=0; k<m; k++)
{
distance = fabs(data[i+k*delay]-data[j+k*delay]);
if (distance>max)
max = distance;
}
if (r[l]>=max)
cr++;
max = 0;
}
}
Cr = cr*2.0/(M*(M-1));
cr = 0;
ln_C[l] = log(Cr);
ln_r[l] = log(r[l]);
}
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *data;
double *r;
int m;
int delay;
double *ln_C;
double *ln_r;
int datalen,rlen;
if (nrhs!=4)
mexErrMsgTxt("Four inputs required!");
else if (nlhs>2)
mexErrMsgTxt("Too many output arguments!");
datalen = mxGetN(prhs[0]);
rlen = mxGetN(prhs[1]);
m = mxGetScalar(prhs[2]);
delay = mxGetScalar(prhs[3]);
//define the two output arguments
plhs[0] = mxCreateDoubleMatrix(1,rlen,mxREAL);
plhs[1] = mxCreateDoubleMatrix(1,rlen,mxREAL);
data = mxGetPr(prhs[0]);
r = mxGetPr(prhs[1]);
ln_C = mxGetPr(plhs[0]);
ln_r = mxGetPr(plhs[1]);
G_P(data,r,datalen,m,rlen,delay,ln_C,ln_r);
}
我总感觉这个程序中少了r的计算呢?对了,计算r有哪几种方法?最近一直在学混沌,但一直没怎么弄懂,希望大侠小虾们帮帮我,小弟在这谢谢了! |
|