204,7 → 204,7 |
long int *correlationl, *correlationr; |
int *L_signal, *R_signal; |
short *chirp, *signal; |
float *chirp_spect, *echo_spect; |
float *chirp_spect, *lecho_spect, *recho_spect; |
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 |
278,7 → 278,8 |
frequency_bins = chirp_size / 2 + 1; |
df = (double) rate / (double) chirp_size; |
chirp_spect = malloc(frequency_bins * sizeof(float)); |
echo_spect = malloc(frequency_bins * sizeof(float)); |
lecho_spect = malloc(frequency_bins * sizeof(float)); |
recho_spect = malloc(frequency_bins * sizeof(float)); |
|
inchirp = fftw_malloc(sizeof(double) * chirp_size); // allocate input array for FFT |
outchirp = fftw_malloc(sizeof(fftw_complex) * frequency_bins); |
377,8 → 378,12 |
|
for(i=delayl[1]; i < delayl[1] + chirp_size; i++) inchirp[i-delayl[1]] = L_signal[i]; |
fftw_execute(fft_plan_chirp); |
for(i=0; i < frequency_bins; i++) echo_spect[i] = sqrt(outchirp[i][0] * outchirp[i][0] + outchirp[i][1] * outchirp[i][1]); |
for(i=0; i < frequency_bins; i++) lecho_spect[i] = sqrt(outchirp[i][0] * outchirp[i][0] + outchirp[i][1] * outchirp[i][1]); |
|
for(i=delayr[1]; i < delayr[1] + chirp_size; i++) inchirp[i-delayr[1]] = R_signal[i]; |
fftw_execute(fft_plan_chirp); |
for(i=0; i < frequency_bins; i++) recho_spect[i] = sqrt(outchirp[i][0] * outchirp[i][0] + outchirp[i][1] * outchirp[i][1]); |
|
printf("Writing output files\n"); |
out=fopen("/tmp/sonar.txt","w"); |
for (i=0; i <= (period_size - 1); i++) |
395,13 → 400,13 |
fclose(out); |
|
out=fopen("/tmp/echo.txt","w"); |
for(i=delayl[1]; i < delayl[1] + chirp_size; i++) fprintf(out,"%6d %6d\n", i-delayl[1], L_signal[i]); |
for(i=0; i < chirp_size; i++) fprintf(out,"%6d %6d %6d\n", i, L_signal[i + delayl[1]], R_signal[i + delayr[1]]); |
fclose(out); |
|
out=fopen("/tmp/spektra.txt","w"); |
for (i=0; i < frequency_bins; i++) |
{ |
fprintf(out,"%4.3f %4.3f %4.3f\n", (i+0.5) * df, chirp_spect[i], echo_spect[i]); |
fprintf(out,"%4.3f %4.3f %4.3f %4.3f\n", (i+0.5) * df, chirp_spect[i], lecho_spect[i], recho_spect[i]); |
} |
fclose(out); |
|