double coefficient(double acuan[],double sample[],int start1,int start2,int m)
{
int Length=m;
double sum_sam=0;
double avg_sam=0;
double sum_acu=0;
double avg_acu=0;
for(int i=start1,j=start2;i<(start1+Length),j<(start2+Length);i++,j++)
{
sum_acu=sum_acu+acuan[i];
sum_sam=sum_sam+sample[j];
}
avg_sam=sum_sam/Length;
avg_acu=sum_acu/Length;
double coeff=-1;
double top=0;
double bottom=0;
double bottom1=0;
double bottom2=0;
for(int i=start1,j=start2;i<(start1+Length),j<(start2+Length);i++,j++)
{
top=top+(acuan[i]-avg_acu)*(sample[j]-avg_sam);
bottom1=bottom1+(acuan[i]-avg_acu)*(acuan[i]-avg_acu);
bottom2=bottom2+(sample[j]-avg_sam)*(sample[j]-avg_sam);
}
bottom=sqrt(bottom1*bottom2);
if(bottom !=0)
{
coeff=top/bottom;
}
else
{
printf("the bottom is 0\n");
}
return coeff;
}
//double acuan[],double sample[] 输入两个向量
//int start1,int start2 截取向量的位置
//int m 进行相关性计算的两个向量的长度