Subversion Repositories svnkaklik

Rev

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

Rev 641 Rev 643
Line 18... Line 18...
18
#include <math.h>
18
#include <math.h>
19
#include <fftw3.h>
19
#include <fftw3.h>
20
 
20
 
21
#define SOUND_SPEED	340.0	// sound speed in air in metrs per second
21
#define SOUND_SPEED	340.0	// sound speed in air in metrs per second
22
#define MAX_RANGE	10.0	// maximal working radius in meters
22
#define MAX_RANGE	10.0	// maximal working radius in meters
-
 
23
#define APERTURE	0.2	// distance between microphones
-
 
24
#define MAP_SIZE	100
23
 
25
 
24
static char *device = "plughw:0,0";			/* playback device */
26
static char *device = "plughw:0,0";			/* playback device */
25
static snd_pcm_format_t format = SND_PCM_FORMAT_S16;	/* sample format */
27
static snd_pcm_format_t format = SND_PCM_FORMAT_S16;	/* sample format */
26
static unsigned int rate = 96000;			/* stream rate */
28
static unsigned int rate = 96000;			/* stream rate */
27
static unsigned int buffer_time = 2 * (MAX_RANGE / SOUND_SPEED * 1e6);		/* ring buffer length in us */
29
static unsigned int buffer_time = 2 * (MAX_RANGE / SOUND_SPEED * 1e6);		/* ring buffer length in us */
Line 209... Line 211...
209
    unsigned int delayl[10],delayr[10];	//store delay of signifed correlation
211
    unsigned int delayl[10],delayr[10];	//store delay of signifed correlation
210
    long int l,r;  // store correlation at strict time
212
    long int l,r;  // store correlation at strict time
211
    double df;	//frequency resolution 
213
    double df;	//frequency resolution 
212
    unsigned int frequency_bins; // number of output frequency bins 
214
    unsigned int frequency_bins; // number of output frequency bins 
213
 
215
 
-
 
216
    float density_map[MAP_SIZE][MAP_SIZE];  // Array to store two dimensional image of echos
-
 
217
 
214
    double *inchirp;
218
    double *inchirp;
215
    fftw_complex *outchirp;
219
    fftw_complex *outchirp;
216
    fftw_plan fft_plan_chirp;
220
    fftw_plan fft_plan_chirp;
217
 
221
 
218
    FILE *out;
222
    FILE *out;
Line 357... Line 361...
357
        }
361
        }
358
        correlationl[n]=abs(l);
362
        correlationl[n]=abs(l);
359
        correlationr[n]=abs(r);
363
        correlationr[n]=abs(r);
360
    }
364
    }
361
 
365
 
-
 
366
    printf("Building echo map\n");		// compute map from left and right correlation data
-
 
367
    for (i=0;i < MAP_SIZE; i++)
-
 
368
    {
-
 
369
	for (j=0;j < MAP_SIZE; j++) density_map[i][j]=correlationl[(int)sqrt(i*i + j*j)]*correlationr[(int)sqrt(APERTURE*APERTURE - 2*APERTURE*i + i*i + j*j)];
-
 
370
    }
-
 
371
 
-
 
372
 
362
    printf("Searching echos\n");
373
    printf("Searching echos\n");
363
    r=0;
374
    r=0;
364
    l=0;
375
    l=0;
365
    for (n=0; n < period_size;n++) 			//najde nejvetsi korelace
376
    for (n=0; n < period_size;n++) 			//najde nejvetsi korelace
366
    {
377
    {
Line 393... Line 404...
393
    {
404
    {
394
        fprintf(out,"%2.3f %6d %6d %9ld %9ld\n",SOUND_SPEED * (float) i / rate,L_signal[i],R_signal[i],correlationl[i], correlationr[i]);
405
        fprintf(out,"%2.3f %6d %6d %9ld %9ld\n",SOUND_SPEED * (float) i / rate,L_signal[i],R_signal[i],correlationl[i], correlationr[i]);
395
    }
406
    }
396
    fclose(out);
407
    fclose(out);
397
 
408
 
-
 
409
    out=fopen("/tmp/plane_cut.txt","w");
-
 
410
    for (i=0;i < MAP_SIZE; i++)
-
 
411
    {
-
 
412
	for (j=0;j < MAP_SIZE; j++) fprintf(out,"%6f", density_map);
-
 
413
    }
-
 
414
 
398
    out=fopen("/tmp/chirp.txt","w");
415
    out=fopen("/tmp/chirp.txt","w");
399
    for (i=0; i <= (chirp_size - 1); i++)
416
    for (i=0; i <= (chirp_size - 1); i++)
400
    {
417
    {
401
        fprintf(out,"%6d %6d\n", i, chirp[i]);
418
        fprintf(out,"%6d %6d\n", i, chirp[i]);
402
    }
419
    }
Line 411... Line 428...
411
    {
428
    {
412
        fprintf(out,"%4.3f %4.3f %4.3f %4.3f\n", (i+0.5) * df, chirp_spect[i], lecho_spect[i], recho_spect[i]);
429
        fprintf(out,"%4.3f %4.3f %4.3f %4.3f\n", (i+0.5) * df, chirp_spect[i], lecho_spect[i], recho_spect[i]);
413
    }
430
    }
414
    fclose(out);
431
    fclose(out);
415
 
432
 
416
    printf("Echo zacina na: %d vzorku.\n", delayl[1]);
-
 
417
    printf("Casove na: %f s\n", ((float)delayl[1]/rate));
-
 
418
    printf("vzdalenost: %f m\n", (SOUND_SPEED*(float)delayl[1]/rate));
-
 
419
 
-
 
420
    free(correlationl);
433
    free(correlationl);
421
    free(correlationr);
434
    free(correlationr);
422
    free(L_signal);
435
    free(L_signal);
423
    free(R_signal);
436
    free(R_signal);
424
    free(chirp);
437
    free(chirp);