Subversion Repositories svnkaklik

Rev

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

Rev 541 Rev 542
Line 24... Line 24...
24
static int resample = 1;				/* enable alsa-lib resampling */
24
static int resample = 1;				/* enable alsa-lib resampling */
25
static int period_event = 0;				/* produce poll event after each period */
25
static int period_event = 0;				/* produce poll event after each period */
26
 
26
 
27
#define SOUND_SPEED	340
27
#define SOUND_SPEED	340
28
#define SIGNAL_SAMPLES 100000
28
#define SIGNAL_SAMPLES 100000
29
#define CHIRP_OFFSET	300 
29
#define CHIRP_OFFSET	0 
30
 
30
 
31
unsigned int chirp_size;
31
unsigned int chirp_size;
32
 
32
 
33
int period=0;
33
int period=0;
34
int cperiod=0;
34
int cperiod=0;
Line 300... Line 300...
300
	snd_async_handler_t *chandler, *phandler;
300
	snd_async_handler_t *chandler, *phandler;
301
	int count;
301
	int count;
302
	unsigned int i,j,m,n;
302
	unsigned int i,j,m,n;
303
	unsigned int delay[10];	//store delay of signifed correlation
303
	unsigned int delay[10];	//store delay of signifed correlation
304
  	long int l,r;  // store correlation at strict time
304
  	long int l,r;  // store correlation at strict time
305
	long int correlationl[100000]; //array to store correlation curve
305
	long int correlationl[SIGNAL_SAMPLES]; //array to store correlation curve
306
	long int correlationr[100000]; //array to store correlation curve
306
	long int correlationr[SIGNAL_SAMPLES]; //array to store correlation curve
-
 
307
	int L_signal[SIGNAL_SAMPLES];
-
 
308
	int R_signal[SIGNAL_SAMPLES];
307
 
309
 
308
	FILE *out;
310
	FILE *out;
309
 
311
 
310
	snd_pcm_hw_params_alloca(&hwparams);
312
	snd_pcm_hw_params_alloca(&hwparams);
311
	snd_pcm_sw_params_alloca(&swparams);
313
	snd_pcm_sw_params_alloca(&swparams);
Line 401... Line 403...
401
	printf("Waiting for transmitt all samples\n");
403
	printf("Waiting for transmitt all samples\n");
402
	while(cperiod<10) {
404
	while(cperiod<10) {
403
		sleep(1);
405
		sleep(1);
404
		printf(".");
406
		printf(".");
405
	}	
407
	}	
-
 
408
//// 
-
 
409
	j=0;
-
 
410
	for(i=0;i < SIGNAL_SAMPLES;i++){
-
 
411
	  L_signal[i]=signal[j];
-
 
412
	  R_signal[i]=signal[j+1];
-
 
413
	  j+=2;
-
 
414
	}
-
 
415
 
406
	printf("\nData transmitted... \ncorrelating...\n");
416
	printf("\nData transmitted... \ncorrelating...\n");
407
	i=0;
-
 
408
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//we have interleaved data we must have 2 saples step
417
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){
409
	  l=0;
418
	  l=0;
410
          r=0;
419
          r=0;
411
	  j=0;
-
 
412
	  for(m=CHIRP_OFFSET;m < chirp_size;m++)
420
	  for(m=CHIRP_OFFSET;m < 500;m++)
413
          {
421
          {
414
            l += chirp[m]*signal[i+j];	// correlate with left channel
422
            l += chirp[m]*L_signal[m+n];	// correlate with left channel
415
            r += chirp[m]*signal[i+j+1];	// correlate with right channel
423
            r += chirp[m]*R_signal[m+n];	// correlate with right channel
416
	    j+=2;
-
 
417
          }
424
          }
418
	  correlationl[n]=l;
425
	  correlationl[n]=l;
419
	  correlationr[n]=r;
426
	  correlationr[n]=r;
420
	  i+=2;
-
 
421
	}
427
	}
422
 
428
 
423
	printf("\nSearching echos...\n");
429
/*	printf("\nSearching echos...\n");
424
	r=0;
430
	r=0;
425
	l=0;
431
	l=0;
426
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//najde nejvetsi korelace
432
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//najde nejvetsi korelace
427
	  if (l < correlationl[n]){
433
	  if (l < correlationl[n]){
428
	  delay[1] = n;
434
	  delay[1] = n;
Line 430... Line 436...
430
	  }
436
	  }
431
	  if (r < correlationr[n]){
437
	  if (r < correlationr[n]){
432
	  delay[2] = n;
438
	  delay[2] = n;
433
	  r = correlationr[n];
439
	  r = correlationr[n];
434
	  }
440
	  }
435
	}
441
	}*/
436
 
442
 
437
	out=fopen("./output.txt","w");
443
  out=fopen("./output.txt","w");
438
  j=0;
444
  j=0;
439
  for(i=0;i<=60000;i++){
445
  for(i=0;i<=60000;i++){
440
    fprintf(out,"%6d %6d %6d %6d %9ld %9ld\n",i,chirp[i],signal[j],signal[j+1],correlationl[i], correlationr[i]);
446
    fprintf(out,"%6d %6d %6d %6d %9ld %9ld\n",i,chirp[i],L_signal[i],R_signal[i],correlationl[i], correlationr[i]);
441
    j+=2;
447
    j+=2;
442
  }
448
  }
443
	fclose(out);
449
  fclose(out);
444
 
450
 
445
	printf("\nEcho zacina na: %d vzorku.\n", delay[1]);
451
	printf("\nEcho zacina na: %d vzorku.\n", delay[1]);
446
	printf("Casove na: %f s\n", ((float)delay[1]/rate));
452
	printf("Casove na: %f s\n", ((float)delay[1]/rate));
447
	printf("vzdalenost: %f m\n", (SOUND_SPEED*(float)delay[1]/rate));
453
	printf("vzdalenost: %f m\n", (SOUND_SPEED*(float)delay[1]/rate));
448
 
454