Subversion Repositories svnkaklik

Compare Revisions

Regard whitespace Rev 521 → Rev 522

/programy/C/ix86/signals/correlation.c
0,0 → 1,56
#include <stdio.h>
#include <stdlib.h>
 
int x[500];
int y[50];
 
int main (void)
{
fprintf(stdout,"inicializace bufferu s chirpem");
 
int i,j
double mx,my,sx,sy,sxy,denom,r;
/* Calculate the mean of the two series x[], y[] */
mx = 0;
my = 0;
for (i=0;i<n;i++) {
mx += x[i];
my += y[i];
}
mx /= n;
my /= n;
 
/* Calculate the denominator */
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);
 
/* Calculate the correlation series */
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);
*/
}
r = sxy / denom;
/* r is the correlation coefficient at "delay" */
 
}
 
exit(1);
}