Subversion Repositories svnkaklik

Rev

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

Rev 525 Rev 526
Line 3... Line 3...
3
 
3
 
4
#include <stdio.h>
4
#include <stdio.h>
5
#include <stdlib.h>
5
#include <stdlib.h>
6
#include <math.h>
6
#include <math.h>
7
 
7
 
8
int sample[100];
8
#define SAMPLES  1000
9
int signal[500];
9
#define SIGNAL_SAMPLES  SAMPLES*20
10
 
10
 
-
 
11
int sample[SAMPLES];
-
 
12
int signal[SIGNAL_SAMPLES];
-
 
13
 
11
double correlation[1000];
14
double correlation[SIGNAL_SAMPLES];
12
 
15
 
13
int obdelnik(int *pole, int delka_pole, int delka_pulsu, int spozdeni) //generuje testovaci lichobeznikovy puls  do zadaneho pole
16
int obdelnik(int *pole, int delka_pole, int delka_pulsu, int spozdeni) //generuje testovaci lichobeznikovy puls  do zadaneho pole
14
{
17
{
15
int i;
18
int i;
16
int value=1;
19
int value=1;
Line 25... Line 28...
25
 
28
 
26
    if (i > (spozdeni+delka_pulsu+20) && i < delka_pole) pole[i]=value;
29
    if (i > (spozdeni+delka_pulsu+20) && i < delka_pole) pole[i]=value;
27
  }
30
  }
28
}
31
}
29
 
32
 
30
int linear_chirp(int *pole, int delka_pole, int delka_pulsu, int spozdeni){
33
int linear_chirp(int *pole, int delka_pole, int delka_pulsu, int spozdeni){  // vygeneruje linearni chirp a vzorky ulozi do pole
31
 
34
 
32
static const double pi = 3.141592653589793238462643383279502884197; // Archimedes constant pi
35
static const double pi = 3.141592653589793238462643383279502884197; // Archimedes constant pi
33
static const float f0 = 1;
36
static const float f0 = 0.01;
34
static const float k = 1;
37
static const float k = 0.0001;
35
 
38
 
36
int t;
39
int t;
-
 
40
float ble;
-
 
41
  if((spozdeni+delka_pulsu) < delka_pole)
-
 
42
    for(t=0;t < delka_pulsu;t++) pole[spozdeni+t] = round ( 100*sin(2*pi*t*(f0+(k/2)*t)) );
-
 
43
  else return 0;
-
 
44
 
-
 
45
}
-
 
46
 
-
 
47
int exp_chirp(int *pole, int delka_pole, int delka_pulsu, int spozdeni){  // vygeneruje linearni chirp a vzorky ulozi do pole
-
 
48
 
-
 
49
static const double pi = 3.141592653589793238462643383279502884197; // Archimedes constant pi
-
 
50
static const float f0 = 0.01;
-
 
51
static const float k = 0.0001;
-
 
52
 
-
 
53
int t;
-
 
54
float ble;
-
 
55
  if((spozdeni+delka_pulsu) < delka_pole)
-
 
56
    for(t=0;t < delka_pulsu;t++) pole[spozdeni+t] = round ( 100*sin(2*pi*t*(f0+(k/2)*t)) );
-
 
57
  else return 0;
37
 
58
 
38
//  for(t=0;t < delka_pole;t++){ pole[t] = (int) ( 100*sin(2*pi*t*(f0+(k/2)*t)) ) ;
-
 
39
//  }
-
 
40
  for(t=0;t < delka_pole;t++){ pole[t] = (int) ( 100*sin(t/2) ) ;
-
 
41
  }
-
 
42
}
59
}
43
 
60
 
-
 
61
 
44
int main (void)
62
int main (void)
45
{
63
{
46
   int i,n,m,delay;
64
   int i,n,m,delay;
47
   double r;
65
   double r;
48
 
66
 
49
   linear_chirp(sample,100,10,0);			// vyrobi vzorek signalu
67
   linear_chirp(sample,SAMPLES,100,0);			// vyrobi vzorek signalu
50
   obdelnik(signal,500,10,100);			// vyrobi signal ve kterem se vzorek hleda
68
   linear_chirp(signal,SIGNAL_SAMPLES,500,1000);			// vyrobi signal ve kterem se vzorek hleda
51
 
69
 
52
   for(n=0; n < 400;n++){			//spocita korelaci pro mozna spozdeni
70
   for(n=0; n < (SIGNAL_SAMPLES - SAMPLES);n++){			//spocita korelaci pro mozna spozdeni
53
     r=0;
71
     r=0;
54
     for(m=0;m < 100;m++) r += sample[m]*signal[m+n];
72
     for(m=0;m < SAMPLES;m++) r += sample[m]*signal[m+n];
55
     correlation[n]=r;
73
     correlation[n]=r;
56
   }
74
   }
57
 
75
 
58
   r=0;
76
   r=0;
59
   for(n=0; n < 400;n++){			//najde nejvetsi shodu (pro nazornost v samostatnem cyklu)
77
   for(n=0; n < (SIGNAL_SAMPLES - SAMPLES);n++){			//najde nejvetsi shodu (pro nazornost v samostatnem cyklu)
60
     if (r < correlation[n]){
78
     if (r < correlation[n]){
61
       delay = n;
79
       delay = n;
62
       r = correlation[n];
80
       r = correlation[n];
63
     }
81
     }
64
   }
82
   }
65
 
83
 
66
 
84
 
67
   for(i=0;i<400;i++)
85
   for(i=0;i<SAMPLES;i++)
68
   {
86
   {
69
     fprintf(stdout,"%3u ",i);	 		// vypise cislo bunky v poli (spozdeni)
87
//     fprintf(stdout,"%3u ",i);	 		// vypise cislo bunky v poli (spozdeni)
70
     fprintf(stdout,"%2d ",sample[i]);
88
     fprintf(stdout,"%2i ",sample[i]);
71
//     fprintf(stdout,"%2d ",signal[i]);
89
//     fprintf(stdout,"%2d ",signal[i]);
72
//     fprintf(stdout,"%3.2f\n",correlation[i]);		// vypise hodnotu korelace nejvissi cislo je nejvetsi korelace.
90
//     fprintf(stdout,"%3.2f\n",correlation[i]);		// vypise hodnotu korelace nejvissi cislo je nejvetsi korelace.
73
   }
91
   }
74
   fprintf(stdout,"\nvzorek v signalu zacina na miste: %3u \n",delay);
92
   fprintf(stdout,"\nvzorek v signalu zacina na miste: %3u \n",delay);
75
 
93