Rev 522 | Rev 524 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int x[500];
int y[500];
#define n 500
int delay;
int maxdelay = 500;
double correlation[1000];
int obdelnik(int *pole, int delka_pulsu, int spozdeni)
{
int i;
int value=1;
for (i=0; i <= n; i++) {
if (i < spozdeni && i < n) pole[i]=value;
if ((i > spozdeni) && (i < (spozdeni+10))) pole[i] = value++;
if (i < (spozdeni+delka_pulsu+10) && i > (spozdeni+10) && i < n) pole[i]= value;
if (i < (spozdeni+delka_pulsu+20) && i > (spozdeni+delka_pulsu+10) && i < n) pole[i] = value--;
if (i > (spozdeni+delka_pulsu+20) && i < n) pole[i]=value;
}
}
int main (void)
{
int i,j;
double mx,my,sx,sy,sxy,denom;
fprintf(stdout,"inicializace bufferu s chirpem \n");
obdelnik(x,10,40);
obdelnik(y,10,75);
// vypocita stredni hodnotu signalu
mx = 0;
my = 0;
for (i=0;i<n;i++) {
mx += x[i];
my += y[i];
}
mx /= n;
my /= n;
// spoocita jmenovatele
sx = 0;
sy = 0;
for (i=0;i<n;i++) {
sx += (x[i] - mx) * (x[i] - mx);
sy += (y[i] - my) * (y[i] - my);
}
denom = sqrt(sx*sy);
//spocita korelacni koeficient
for (delay=-maxdelay;delay<maxdelay;delay++) {
sxy = 0;
for (i=0;i<n;i++)
{
j = i + delay;
if (j < 0 || j >= n)
continue;
else
sxy += (x[i] - mx) * (y[j] - my);
/* Or should it be (?)
if (j < 0 || j >= n)
sxy += (x[i] - mx) * (-my);
else
sxy += (x[i] - mx) * (y[j] - my);
*/
}
correlation[delay+maxdelay] = sxy / denom;
/* r is the correlation coefficient at "delay" */
}
for(i=0;i<=n;i++)
{
fprintf(stdout,"%2d ",x[i]);
fprintf(stdout,"%2d ",y[i]);
fprintf(stdout,"%3.2f\n",correlation[i]);
}
exit(1);
}