207,11 → 207,12 |
int *L_signal, *R_signal; |
short *chirp, *signal; |
float *chirp_spect, *lecho_spect, *recho_spect; |
float x,y; |
float a,b; |
unsigned int i,j,m,n; |
unsigned int delayl[10],delayr[10]; //store delay of signifed correlation |
long int l,r; // store correlation at strict time |
double df; //frequency resolution |
double k; // sample numbers to distance normalising constant |
unsigned int frequency_bins; // number of output frequency bins |
|
double *inchirp; |
274,8 → 275,10 |
R_signal = malloc(period_size * sizeof(int)); |
chirp = calloc(2*period_size, sizeof(short)); |
signal = malloc(2*period_size * sizeof(short)); |
echo_map = malloc(3*period_size * sizeof(float)); // Array to store two dimensional image of echos |
echo_map = malloc(3*period_size*period_size * sizeof(float)); // Array to store two dimensional image of echos |
if (echo_map == NULL) printf("Can't allocate enought memory"); |
|
k = SOUND_SPEED/rate; |
// generate ping pattern |
chirp_size = linear_windowed_chirp(chirp); |
|
365,18 → 368,18 |
|
m=0; |
printf("Building echo map\n"); // compute map from left and right correlation data |
for (i=0;i < period_size; i++) |
for (i=0;i < period_size; i+=10) |
{ |
for(j=0;j < period_size; j++) |
a=k*i; |
for(j=0;j < period_size; j+=10) |
{ |
echo_map[m]=(i*i-j*j+APERTURE*APERTURE)/(2*APERTURE); |
echo_map[m+1]=sqrt(-(i-j-APERTURE)*(i+j-APERTURE)*(i-j+APERTURE)*(i+j+APERTURE))/(2*r); |
b=k*j; |
echo_map[m]=(a*a-b*b+APERTURE*APERTURE)/(2*APERTURE); |
echo_map[m+1]=sqrt((a-b-APERTURE)*(a+b-APERTURE)*(a-b+APERTURE)*(a+b+APERTURE))/(2*r); |
echo_map[m+2]=correlationl[i]*correlationr[j]; |
m+=3; |
} |
} |
|
|
printf("Searching echos\n"); |
r=0; |
l=0; |
409,17 → 412,18 |
out=fopen("/tmp/sonar.txt","w"); |
for (i=0; i <= (period_size - 1); i++) |
{ |
fprintf(out,"%2.3f %6d %6d %9ld %9ld\n",SOUND_SPEED * (float) i / rate,L_signal[i],R_signal[i],correlationl[i], correlationr[i]); |
fprintf(out,"%2.3f %6d %6d %9ld %9ld\n", (float)i*k, L_signal[i], R_signal[i], correlationl[i], correlationr[i]); |
} |
fclose(out); |
|
j=0; |
out=fopen("/tmp/plane_cut.txt","w"); // writes plane cut - e.g. density map to file |
for (i=0;i < period_size; i++) |
for (i=0;i < period_size*period_size; i++) |
{ |
fprintf(out,"%3.2f %3.2f %3.2f\n", echo_map[j], echo_map[j+1], echo_map[j+2]); |
fprintf(out,"%3.3f %3.3f %3.3f\n", echo_map[j], echo_map[j+1], echo_map[j+2]); |
j+=3; |
} |
fclose(out); |
|
out=fopen("/tmp/chirp.txt","w"); |
for (i=0; i <= (chirp_size - 1); i++) |