17,7 → 17,7 |
|
static char *device = "plughw:0,0"; /* playback device */ |
static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample format */ |
static unsigned int rate = 44100; /* stream rate */ |
static unsigned int rate = 98000; /* stream rate */ |
static unsigned int channels = 1; /* count of channels */ |
static unsigned int buffer_time = 500000; /* ring buffer length in us */ |
static unsigned int period_time = 100000; /* period time in us */ |
188,7 → 188,7 |
|
static const float f0 = 1000; |
static const float fmax = 5000; |
static const float Tw = 0.2; |
static const float Tw = 0.002; |
static float k; |
|
unsigned int n=0; |
287,7 → 287,7 |
snd_async_handler_t *chandler, *phandler; |
int count; |
unsigned int i,j,m,n; |
unsigned int delay; //store delay of maximal correlation |
unsigned int delay[10]; //store delay of signifed correlation |
double r; |
double correlation[1000000]; //array to store correlation curve |
|
384,10 → 384,6 |
} |
printf("\nData transmitted... \nprocessing...\n"); |
|
out=fopen("./output.txt","w"); |
for(i=0;i<=100000;i++) fprintf(out,"%6d %6d %6d \n",i,chirp[i],signal[i]); |
fclose(out); |
|
#define SIGNAL_SAMPLES 100000 |
|
for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){ //spocita korelaci pro mozna spozdeni |
397,17 → 393,22 |
} |
|
r=0; |
for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){ //najde nejvetsi shodu (pro nazornost v samostatnem cyklu) |
|
for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){ //najde nejvetsi korelace |
if (r < correlation[n]){ |
delay = n; |
delay[1] = n; |
r = correlation[n]; |
} |
} |
|
printf("\nEcho zacina na: %d vzorku.\n", delay); |
printf("Casove na: %f s\n", ((float)delay/rate)); |
printf("vzdalenost: %f m\n", (SOUND_SPEED*(float)delay/rate)); |
out=fopen("./output.txt","w"); |
for(i=0;i<=100000;i++) fprintf(out,"%6d %6d %6d %6.2f\n",i,chirp[i],signal[i],correlation[i]); |
fclose(out); |
|
printf("\nEcho zacina na: %d vzorku.\n", delay[1]); |
printf("Casove na: %f s\n", ((float)delay[1]/rate)); |
printf("vzdalenost: %f m\n", (SOUND_SPEED*(float)delay[1]/rate)); |
|
snd_pcm_close(playback_handle); |
snd_pcm_close(capture_handle); |
return 0; |