Subversion Repositories svnkaklik

Rev

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

Rev 533 Rev 536
Line 15... Line 15...
15
#include <sys/time.h>
15
#include <sys/time.h>
16
#include <math.h>
16
#include <math.h>
17
 
17
 
18
static char *device = "plughw:0,0";			/* playback device */
18
static char *device = "plughw:0,0";			/* playback device */
19
static snd_pcm_format_t format = SND_PCM_FORMAT_S16;	/* sample format */
19
static snd_pcm_format_t format = SND_PCM_FORMAT_S16;	/* sample format */
20
static unsigned int rate = 44100;			/* stream rate */
20
static unsigned int rate = 98000;			/* stream rate */
21
static unsigned int channels = 1;			/* count of channels */
21
static unsigned int channels = 1;			/* count of channels */
22
static unsigned int buffer_time = 500000;		/* ring buffer length in us */
22
static unsigned int buffer_time = 500000;		/* ring buffer length in us */
23
static unsigned int period_time = 100000;		/* period time in us */
23
static unsigned int period_time = 100000;		/* period time in us */
24
static int verbose = 0;					/* verbose flag */
24
static int verbose = 0;					/* verbose flag */
25
static int resample = 1;				/* enable alsa-lib resampling */
25
static int resample = 1;				/* enable alsa-lib resampling */
Line 186... Line 186...
186
{  
186
{  
187
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
187
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
188
 
188
 
189
static const float f0 = 1000;
189
static const float f0 = 1000;
190
static const float fmax = 5000;
190
static const float fmax = 5000;
191
static const float Tw = 0.2;
191
static const float Tw = 0.002;
192
static float k;
192
static float k;
193
 
193
 
194
unsigned int n=0;
194
unsigned int n=0;
195
double t;
195
double t;
196
unsigned int perioda;
196
unsigned int perioda;
Line 285... Line 285...
285
 
285
 
286
	struct async_private_data data;
286
	struct async_private_data data;
287
	snd_async_handler_t *chandler, *phandler;
287
	snd_async_handler_t *chandler, *phandler;
288
	int count;
288
	int count;
289
	unsigned int i,j,m,n;
289
	unsigned int i,j,m,n;
290
	unsigned int delay;	//store delay of maximal correlation
290
	unsigned int delay[10];	//store delay of signifed correlation
291
  	double r;
291
  	double r;
292
	double correlation[1000000]; //array to store correlation curve
292
	double correlation[1000000]; //array to store correlation curve
293
 
293
 
294
	FILE *out;
294
	FILE *out;
295
 
295
 
Line 382... Line 382...
382
		sleep(1);
382
		sleep(1);
383
		printf(".");
383
		printf(".");
384
	}	
384
	}	
385
	printf("\nData transmitted... \nprocessing...\n");
385
	printf("\nData transmitted... \nprocessing...\n");
386
 
386
 
387
	out=fopen("./output.txt","w");
-
 
388
	for(i=0;i<=100000;i++) fprintf(out,"%6d	%6d %6d \n",i,chirp[i],signal[i]); 
-
 
389
	fclose(out);
-
 
390
 
-
 
391
#define SIGNAL_SAMPLES 100000
387
#define SIGNAL_SAMPLES 100000
392
 
388
 
393
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//spocita korelaci pro mozna spozdeni
389
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//spocita korelaci pro mozna spozdeni
394
	  r=0;
390
	  r=0;
395
	  for(m=0;m < 1000;m++) r += chirp[m]*signal[m+n];
391
	  for(m=0;m < 1000;m++) r += chirp[m]*signal[m+n];
396
	  correlation[n]=r;
392
	  correlation[n]=r;
397
	}
393
	}
398
 
394
 
399
	r=0;
395
	r=0;
-
 
396
 
400
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//najde nejvetsi shodu (pro nazornost v samostatnem cyklu)
397
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//najde nejvetsi korelace
401
	  if (r < correlation[n]){
398
	  if (r < correlation[n]){
402
	  delay = n;
399
	  delay[1] = n;
403
	  r = correlation[n];
400
	  r = correlation[n];
404
	  }
401
	  }
405
	}
402
	}
406
 
403
 
-
 
404
	out=fopen("./output.txt","w");
-
 
405
	for(i=0;i<=100000;i++) fprintf(out,"%6d	%6d %6d %6.2f\n",i,chirp[i],signal[i],correlation[i]); 
-
 
406
	fclose(out);
-
 
407
 
407
	printf("\nEcho zacina na: %d vzorku.\n", delay);
408
	printf("\nEcho zacina na: %d vzorku.\n", delay[1]);
408
	printf("Casove na: %f s\n", ((float)delay/rate));
409
	printf("Casove na: %f s\n", ((float)delay[1]/rate));
409
	printf("vzdalenost: %f m\n", (SOUND_SPEED*(float)delay/rate));
410
	printf("vzdalenost: %f m\n", (SOUND_SPEED*(float)delay[1]/rate));
410
 
411
 
411
	snd_pcm_close(playback_handle);
412
	snd_pcm_close(playback_handle);
412
	snd_pcm_close(capture_handle);
413
	snd_pcm_close(capture_handle);
413
	return 0;
414
	return 0;
414
}
415
}