Subversion Repositories svnkaklik

Rev

Rev 522 | Rev 524 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

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