/programy/C/ix86/signals/correlation |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/programy/C/ix86/signals/correlation.c |
---|
16,7 → 16,7 |
int obdelnik(int *pole, int delka_pole, int delka_pulsu, int spozdeni) //generuje testovaci lichobeznikovy puls do zadaneho pole |
{ |
int i; |
int value=1; |
int value=0; |
for (i=0; i <= delka_pole; i++) { |
if (i < spozdeni && i < delka_pole) pole[i]=value; |
24,9 → 24,9 |
if (i < (spozdeni+delka_pulsu+10) && i > (spozdeni+10) && i < delka_pole) pole[i]= value; |
if (i < (spozdeni+delka_pulsu+20) && i > (spozdeni+delka_pulsu+10) && i < delka_pole) pole[i] = value--; |
if (i < (spozdeni+delka_pulsu+19) && i > (spozdeni+delka_pulsu+10) && i < delka_pole) pole[i] = value--; |
if (i > (spozdeni+delka_pulsu+20) && i < delka_pole) pole[i]=value; |
if (i > (spozdeni+delka_pulsu+19) && i < delka_pole) pole[i]=value; |
} |
} |
65,8 → 65,8 |
double r; |
FILE *out; |
linear_chirp(sample,SAMPLES,100,0); // vyrobi vzorek signalu |
linear_chirp(signal,SIGNAL_SAMPLES,500,1000); // vyrobi signal ve kterem se vzorek hleda |
obdelnik(sample,SAMPLES,100,0); // vyrobi vzorek signalu |
obdelnik(signal,SIGNAL_SAMPLES,100,1100); // vyrobi signal ve kterem se vzorek hleda |
for(n=0; n < (SIGNAL_SAMPLES - SAMPLES);n++){ //spocita korelaci pro mozna spozdeni |
r=0; |
82,13 → 82,13 |
} |
} |
out=fopen("output.txt",'w'); |
for(i=0;i<SAMPLES;i++) |
out=fopen("./output.txt","w"); |
for(i=0;i< SIGNAL_SAMPLES;i++) |
{ |
// fprintf(stdout,"%3u ",i); // vypise cislo bunky v poli (spozdeni) |
fprintf(stdout,"%2i ",sample[i]); |
// fprintf(stdout,"%2i ",sample[i]); |
// fprintf(stdout,"%2d ",signal[i]); |
// fprintf(out,"%3.2f\n",correlation[i]); // vypise hodnotu korelace nejvissi cislo je nejvetsi korelace. |
fprintf(out,"%3.2f\n",correlation[i]); // vypise hodnotu korelace nejvissi cislo je nejvetsi korelace. |
} |
fprintf(stdout,"\nvzorek v signalu zacina na miste: %3u \n",delay); |
fclose(out); |
/programy/C/ix86/sound/plot.gn |
---|
0,0 → 1,5 |
!./sonar |
set xrange [0:4000] |
set yrange [-30000:30000] |
plot "./output.txt" using 1:($2/2) with lines title 'chirp' , "" using 1:($3*2-10000) with lines title 'echo' ,"" using 1:($4/10000+10000) with lines title 'Correlation' |
reread |
/programy/C/ix86/sound/sonar |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/programy/C/ix86/sound/sonar.c |
---|
87,6 → 87,7 |
printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err); |
return -EINVAL; |
} |
else printf("Rate set to %i Hz\n", rate, err); |
/* set the buffer time */ |
err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, &dir); |
if (err < 0) { |
186,8 → 187,8 |
{ |
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1; |
static const float f0 = 1000; |
static const float fmax = 5000; |
static const float f0 = 8000; |
static const float fmax = 10000; |
static const float Tw = 0.002; |
static float k; |
296,6 → 297,7 |
snd_pcm_hw_params_alloca(&hwparams); |
snd_pcm_sw_params_alloca(&swparams); |
//open and set playback device |
if ((err = snd_pcm_open(&playback_handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { |
printf("Playback open error: %s\n", snd_strerror(err)); |
382,18 → 384,18 |
sleep(1); |
printf("."); |
} |
printf("\nData transmitted... \nprocessing...\n"); |
printf("\nData transmitted... \ncorrelating...\n"); |
#define SIGNAL_SAMPLES 100000 |
for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){ //spocita korelaci pro mozna spozdeni |
r=0; |
for(m=0;m < 1000;m++) r += chirp[m]*signal[m+n]; |
for(m=0;m < chirp_size;m++) r += chirp[m]*signal[m+n]; |
correlation[n]=r; |
} |
printf("\nFinding echos...\n"); |
r=0; |
for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){ //najde nejvetsi korelace |
if (r < correlation[n]){ |
delay[1] = n; |