Subversion Repositories svnkaklik

Rev

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

Rev 647 Rev 649
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
23
#define Xl	-0.1		// microphones position
-
 
24
#define Xr	0.1
24
 
25
 
25
static char *device = "plughw:0,0";			/* playback device */
26
static char *device = "plughw:0,0";			/* playback device */
26
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 */
27
static unsigned int rate = 96000;			/* stream rate */
28
static unsigned int rate = 96000;			/* stream rate */
28
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 276... Line 277...
276
    chirp = calloc(2*period_size, sizeof(short));
277
    chirp = calloc(2*period_size, sizeof(short));
277
    signal = malloc(2*period_size * sizeof(short));
278
    signal = malloc(2*period_size * sizeof(short));
278
    echo_map = malloc(3*period_size*period_size * sizeof(float));   // Array to store two dimensional image of echos
279
    echo_map = malloc(3*period_size*period_size * sizeof(float));   // Array to store two dimensional image of echos
279
    if (echo_map == NULL) printf("Can't allocate enought memory");
280
    if (echo_map == NULL) printf("Can't allocate enought memory");
280
 
281
 
281
    k = SOUND_SPEED/rate;
282
    k = SOUND_SPEED/rate; // normalising constant
-
 
283
 
282
// generate ping pattern
284
// generate ping pattern
283
    chirp_size = linear_windowed_chirp(chirp);
285
    chirp_size = linear_windowed_chirp(chirp);
284
 
286
 
285
    frequency_bins = chirp_size / 2 + 1;
287
    frequency_bins = chirp_size / 2 + 1;
286
    df = (double) rate / (double) chirp_size;
288
    df = (double) rate / (double) chirp_size;
Line 372... Line 374...
372
	{
374
	{
373
		a=k*i;
375
		a=k*i;
374
		for(j=0;j < period_size; j+=10)
376
		for(j=0;j < period_size; j+=10)
375
		{
377
		{
376
			b=k*j;
378
			b=k*j;
377
			echo_map[m]=(a*a-b*b+APERTURE*APERTURE)/(2*APERTURE);
379
			echo_map[m]=(-a*a+b*b+Xl*Xl+Xr*Xr)/(2*Xl-2*Xr);
378
			echo_map[m+1]=sqrt((a-b-APERTURE)*(a+b-APERTURE)*(a-b+APERTURE)*(a+b+APERTURE))/(2*r);
380
			echo_map[m+1]=sqrt((a-b-Xl-Xr)*(a+b+Xl+Xr)*(a-b-Xl+Xr)*(a-b-Xl+Xr)*(a+b-Xl+Xr))/(-2*(Xl-Xr));
379
			echo_map[m+2]=correlationl[i]*correlationr[j];
381
			echo_map[m+2]=correlationl[i]*correlationr[j];
380
			m+=3;
382
			m+=3;
381
		}
383
		}
382
	}
384
	}
383
    printf("Searching echos\n");
385
    printf("Searching echos\n");
Line 416... Line 418...
416
    }
418
    }
417
    fclose(out);
419
    fclose(out);
418
 
420
 
419
    j=0;
421
    j=0;
420
    out=fopen("/tmp/plane_cut.txt","w"); // writes plane cut - e.g. density map to file
422
    out=fopen("/tmp/plane_cut.txt","w"); // writes plane cut - e.g. density map to file
421
    for (i=0;i < period_size*period_size; i++)
423
    for (i=0;i < period_size*period_size/100; i++)
422
    {
424
    {
423
	fprintf(out,"%3.3f %3.3f %3.3f\n", echo_map[j], echo_map[j+1], echo_map[j+2]);
425
	fprintf(out,"%3.3f %3.3f %3.3f\n", echo_map[j], echo_map[j+1], echo_map[j+2]);
424
	j+=3;
426
	j+=3;
425
    }
427
    }
426
    fclose(out);
428
    fclose(out);