#include <graphics.h>
#include <dos.h>
#include <bios.h>
#include<conio.h>
#include<stdlib.h>
#include <stdio.h>
#include<math.h>
#define pi 3.1415926
int graphdriver,graphmode;
void draw()
{int i,j;
double c[800];
double d[800]; double s=0;
char *e;
for(i=0;i<800.00;i++){
c[i]=20*sin(5*(i-285)*pi/180);
}
setlinestyle(0,0,1);setcolor(4);
moveto(50,100);
for(i=0;i<800.00;i++)lineto(i+50,c[i]+100);
for(i=0;i<800.00;i++){
if(rand()%2==0)
c[i]=20*sin(5*(i-285)*pi/180)+rand()%20;
else
c[i]=20*sin(5*(i-285)*pi/180)-rand()%20;
}
for(i=0;i<800.00;i++){
d[i]=0;
for(j=0;j<800.00-i;j++){
d[i]+=c[j]*c[i+j];
}
d[i]=d[i]/(j+1);
}
moveto(50,250);
setlinestyle(0,0,1);setcolor(14);
for(i=0;i<800.00;i++)lineto(i+50,c[i]+250);
setlinestyle(0,0,1);setcolor(4);
moveto(50,450);
for(i=0;i<800.00;i++){lineto(i+50,d[i]/5+400);}
setcolor(3);line(50,450,650,450);line(50,450,50,3);
for(i=0;i<800;i+=72)
{ s=2*i/72*pi;
gcvt(s,6,e);
outtextxy(i+50,455,e);
}
outtextxy(0,50,"the old signal");
outtextxy(0,200,"the signal add noise");
outtextxy(0,350,"the xcorr signal");
}
void main()
{
graphdriver=DETECT;
registerbgidriver(EGAVGA_driver);
initgraph(&graphdriver,&graphmode,"c: \\tc\\bgi");
setbkcolor(15);
cleardevice();
draw() ; getch(); system("pause");
}