Subversion Repositories svnkaklik

Rev

Rev 522 | Rev 524 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
522 kaklik 1
#include <stdio.h>
2
#include <stdlib.h>
523 kaklik 3
#include <math.h>
522 kaklik 4
 
5
int x[500];
523 kaklik 6
int y[500];
7
#define n 500
8
int delay;
9
int maxdelay = 500;
10
double correlation[1000];
522 kaklik 11
 
523 kaklik 12
int obdelnik(int *pole, int delka_pulsu, int spozdeni)
13
{
14
int i;
15
int value=1;
16
  for (i=0; i <= n; i++) { 
17
    if (i < spozdeni && i < n) pole[i]=value;
18
 
19
    if ((i > spozdeni) && (i < (spozdeni+10))) pole[i] = value++;
20
 
21
    if (i < (spozdeni+delka_pulsu+10) && i > (spozdeni+10) && i < n) pole[i]= value;      
22
 
23
    if (i < (spozdeni+delka_pulsu+20) && i > (spozdeni+delka_pulsu+10) && i < n) pole[i] = value--;      
24
 
25
    if (i > (spozdeni+delka_pulsu+20) && i < n) pole[i]=value;
26
  }
27
}
28
 
522 kaklik 29
int main (void)
30
{
523 kaklik 31
   int i,j;
32
   double mx,my,sx,sy,sxy,denom;
522 kaklik 33
 
523 kaklik 34
   fprintf(stdout,"inicializace bufferu s chirpem \n");
35
   obdelnik(x,10,40);
36
   obdelnik(y,10,75);
37
 
38
 
39
// vypocita stredni hodnotu signalu  
522 kaklik 40
   mx = 0;
41
   my = 0;   
42
   for (i=0;i<n;i++) {
43
      mx += x[i];
44
      my += y[i];
45
   }
46
   mx /= n;
47
   my /= n;
48
 
523 kaklik 49
// spoocita jmenovatele
50
 
522 kaklik 51
   sx = 0;
52
   sy = 0;
53
   for (i=0;i<n;i++) {
54
      sx += (x[i] - mx) * (x[i] - mx);
55
      sy += (y[i] - my) * (y[i] - my);
56
   }
57
   denom = sqrt(sx*sy);
58
 
523 kaklik 59
//spocita korelacni koeficient
522 kaklik 60
   for (delay=-maxdelay;delay<maxdelay;delay++) {
61
      sxy = 0;
523 kaklik 62
      for (i=0;i<n;i++)
63
      {
522 kaklik 64
         j = i + delay;
65
         if (j < 0 || j >= n)
66
            continue;
67
         else
68
            sxy += (x[i] - mx) * (y[j] - my);
69
         /* Or should it be (?)
70
         if (j < 0 || j >= n)
71
            sxy += (x[i] - mx) * (-my);
72
         else
73
            sxy += (x[i] - mx) * (y[j] - my);
74
         */
75
      }
523 kaklik 76
      correlation[delay+maxdelay] = sxy / denom;
522 kaklik 77
 
78
      /* r is the correlation coefficient at "delay" */
79
 
80
   }
81
 
523 kaklik 82
   for(i=0;i<=n;i++)
83
   {
84
     fprintf(stdout,"%2d ",x[i]);
85
     fprintf(stdout,"%2d ",y[i]);
86
     fprintf(stdout,"%3.2f\n",correlation[i]);
87
   }
88
 
522 kaklik 89
  exit(1);
90
}