原创很久没动过C语言,有点生疏.程序是根据相关函数公式直接计算.
int Rxy( x, N, y, M, rxy) /* Rxy()计算两个序列的互相关函数,返回值为结果序列的0点位置,注意0点位置是从0开始的,不是从1开始。*/
double x[], y[], rxy[]; /* x[] 存放x序列,y[] 存放y序列,rxy[]存放结果序列,其中rxy[]长度为x序列长度+y序列长度-1 */
int N, M; /* N 是x序列长度, M是y序列长度 */
{
int t;
int n;
int index = 0;
int index1 =0;
for (t = 1-M; t<N; t++ )
{
if (t==0) index=index1;
index1++;
rxy[t+M-1]=0.0;
for (n = 0; n<N; n++)
{
if(n-t<0) continue;
if(n-t>M) continue;
rxy[t+M-1] = rxy[t+M-1] + x[n]*y[n-t];
}
}
return index;
}
int main(int argc, char *argv[])
{
double xx[4]={2,1,3,2};
double yy[3]={3,2,1};
double xyxy[6]={0};
int i;
int tt;
tt = Rxy(xx,4,yy,3,xyxy);
for (i=0;i<6;i++)
printf("%f \n",xyxy
); /* 输出结果序列*/
printf("\n%d\n",tt); /* 输出结果序列的0点位置 */
return 0;
}[ 此贴被lyhinsohu在2009-02-03 08:04重新编辑 ]