#include <math.h>
#include <stdlib.h>
#include "iostream.h"
#include "stdio.h"
#include <assert.h>
#define pi 3.14159
void juanji(int s[], int n1, int h[], int n2,int result[],int r_len)
{
int min_n;
int max_n;
int k;
int i;
int temp;
int ts[10000],th[882];
int sum[10881];
//初始化sum
for(int test=0;test<n1+n2-1;test++)
{
sum[test]=0;
}
if(n1>=n2)
{
max_n=n1;
min_n=n2;
for(i=0;i<max_n;i++)
{
ts[i]=s[i];
}
for(i=0;i<min_n;i++)
{
th[i]=h[i];
}
}
else
{
max_n=n2;
min_n=n1;
for(i=0;i<max_n;i++)
{
ts[i]=h[i];
}
for(i=0;i<min_n;i++)
{
th[i]=s[i];
}
}
for(k=0;k<n1+n2-1;k++)
{
if(k<min_n-1)
{
for(i=0;i<=k;i++)
{
sum[k]=sum[k]+ts[i]*th[k-i];
}
}
if(k>=min_n-1&&k<max_n)
{
temp=min_n-1;
for(i=k-(min_n-1);i<k-(min_n-1)+min_n;i++)
{
sum[k]=sum[k]+ts[i]*th[temp];
temp--;
}
}
if(k>=max_n&&k<min_n+max_n-1)
{
temp=min_n-1;
for(i=k-(min_n-1);i<k-(min_n-1)+(max_n+min_n-k-1);i++)
{
sum[k]=sum[k]+ts[i]*th[temp];
temp--;
}
}
result[k]=sum[k];
}
}
int myRand(int iMax)
{
assert( iMax >0 );
int iRand;
iRand = rand();
if ( iRand < iMax )
return iRand;
else
iRand = iRand%iMax;
return iRand;
}
void main()
{
int i;
int F_start=9000;
int B=3000;
int Fs=44100;
double T=0.02;
double K0=(double)B/T;
double Num0=T*(double)Fs;
int Num=(int)Num0;
int buffer[6000];
int LFM[882];
int LFMs[882];
int singal[10000];
int result[10881];
for( int j = 0; j < 6000;j++ )
{
buffer[j]=myRand(2);
}
for(int n=0;n<882;n++)
{
LFM[n]=0; //初始化
LFM[n]=(int)cos(2*pi*F_start*n/Fs-pi*K0*(n/Fs)*(n/Fs));
}
for(i=0;i<10000;i++)
{
singal[i]=0;
}
//-----
for(int n3=0;n3<882;n3++)
{
int temp;
temp=LFM[881-n3];
LFMs[n3]=temp;
}
for(i=2000;i<2882;i++)
{
singal[i]=LFM[i-2000];
}
for(i=3764;i<9764;i++)
{
singal[i]=buffer[i-3764];
}
juanji(singal,10000,LFMs,882,result,10881);
int max_address;
double max=result[0];
for(int j1=1;j1<10881;j1++)
{
if(max<abs((int)result[j1]))
{
max=abs((int)result[j1]);
max_address=j1;
}
}
cout<<"max_address="<<max_address<<endl;
}