程式碼示例:
void Convert(double BMWL,double NORMAL,double *BMwindowVct,float *RR,int * rR,int lenz,double *RRproc)
{
double *X=NULL;
double *Y=NULL;
if (NULL==X)
X=new double[BMWL];
}
if (NULL==Y)
Y=new double[NORMAL];
for(int i=0;i<BMWL;i++)
X[i]=BMwindowVct[i];
for(int i=0;i<NORMAL;i++)
Y[i]=RR[(int)rR[i]];
double *zptr=NULL;
double s;
double *xp=NULL;
double *yp=NULL;
int n,n_lo,n_hi;
double *Z=NULL;
if (NULL==Z)
Z=new double[lenz];
zptr=Z;
for (int i=0;i<lenz;i++)
s=0.0;
n_lo=0>(i-NORMAL+1)?0:i-NORMAL+1;
n_hi=BMWL-1<i?BMWL-1:i;
xp=X+n_lo;
yp=Y+i-n_lo;
for (n=n_lo;n<=n_hi;n++)
s+=*xp * *yp;
xp++;
yp--;
*zptr=s;
zptr++;
for(int i=0;i<lenz;i++)
RRproc[i]=Z[i];
delete [] X;
X=NULL;
delete [] Y;
Y=NULL;
delete [] Z;
Z=NULL;
int m=0;
for(int l=(ceil((double)BMWL/2-2));l<(ceil((double)BMWL/2)+NORMAL-2);l++)
RRproc[m]=RRproc[l];
m++;
程式碼示例:
void Convert(double BMWL,double NORMAL,double *BMwindowVct,float *RR,int * rR,int lenz,double *RRproc)
{
double *X=NULL;
double *Y=NULL;
if (NULL==X)
{
X=new double[BMWL];
}
if (NULL==Y)
{
Y=new double[NORMAL];
}
for(int i=0;i<BMWL;i++)
{
X[i]=BMwindowVct[i];
}
for(int i=0;i<NORMAL;i++)
{
Y[i]=RR[(int)rR[i]];
}
double *zptr=NULL;
double s;
double *xp=NULL;
double *yp=NULL;
int n,n_lo,n_hi;
double *Z=NULL;
if (NULL==Z)
{
Z=new double[lenz];
}
zptr=Z;
for (int i=0;i<lenz;i++)
{
s=0.0;
n_lo=0>(i-NORMAL+1)?0:i-NORMAL+1;
n_hi=BMWL-1<i?BMWL-1:i;
xp=X+n_lo;
yp=Y+i-n_lo;
for (n=n_lo;n<=n_hi;n++)
{
s+=*xp * *yp;
xp++;
yp--;
}
*zptr=s;
zptr++;
}
for(int i=0;i<lenz;i++)
{
RRproc[i]=Z[i];
}
delete [] X;
X=NULL;
delete [] Y;
Y=NULL;
delete [] Z;
Z=NULL;
int m=0;
for(int l=(ceil((double)BMWL/2-2));l<(ceil((double)BMWL/2)+NORMAL-2);l++)
{
RRproc[m]=RRproc[l];
m++;
}
}