Subversion Repositories svnkaklik

Compare Revisions

Ignore whitespace Rev 537 → Rev 538

/programy/C/ix86/sound/plot.gn
1,5 → 1,6
!./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'
plot "./output.txt" using 1:($2/2) with lines title 'chirp' , "" using 1:($3*10-10000) with lines title 'echo' ,"" using 1:($4/5000+10000) with lines title 'Correlation'
pause 1
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
26,6 → 26,7
static int period_event = 0; /* produce poll event after each period */
 
#define SOUND_SPEED 340
#define SIGNAL_SAMPLES 100000
 
unsigned int chirp_size;
 
187,8 → 188,8
{
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
 
static const float f0 = 8000;
static const float fmax = 10000;
static const float f0 = 3000;
static const float fmax = 5000;
static const float Tw = 0.002;
static float k;
 
356,14 → 357,6
exit(EXIT_FAILURE);
}
 
//start playback
if (snd_pcm_state(playback_handle) == SND_PCM_STATE_PREPARED) {
err = snd_pcm_start(playback_handle);
if (err < 0) {
printf("Start error: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
}
 
//start capture
if ((err = snd_pcm_prepare (capture_handle)) < 0) {
377,6 → 370,17
printf("Start error: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
 
 
//start playback
if (snd_pcm_state(playback_handle) == SND_PCM_STATE_PREPARED) {
err = snd_pcm_start(playback_handle);
if (err < 0) {
printf("Start error: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
}
 
//wait until all samples aren't transmitted
printf("Waiting for transmitt all samples\n");
386,12 → 390,10
}
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 < chirp_size;m++) r += chirp[m]*signal[m+n];
correlation[n]=r;
for(m=chirp_size;m > 0;m--) r += chirp[m]*signal[m+n]; // reverse echo patern
correlation[n]=abs(r);
}
 
printf("\nFinding echos...\n");