Subversion Repositories svnkaklik

Compare Revisions

Regard whitespace Rev 622 → Rev 623

/programy/C/ix86/echo/SW/sonar/src/sonar.c
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);
 
/programy/C/ix86/echo/SW/spektra.gp
8,6 → 8,8
set xrange [0:250]
set autoscale y
set xlabel "sample"
set xtics 50
set ytics 20000
plot "/tmp/chirp.txt" using 1:2 with lines title 'chirp'
 
set size 0.45,0.2
15,7 → 17,8
set xrange [0:250]
set autoscale y
set xlabel "sample"
plot "/tmp/echo.txt" using 1:2 with lines title 'echo'
set ytics 5000
plot "/tmp/echo.txt" using 1:2 with lines title 'L echo', "" using 1:3 with lines title 'R echo'
 
set size 0.95,0.4
set origin 0,0.4
24,7 → 27,8
set autoscale y
set xlabel "frequency"
set xtics 1000
set mxtics 500
set ytics 100000
set mxtics 2
plot "/tmp/spektra.txt" using 1:2 with lines title 'chirp spectrum'
 
set size 0.95,0.4
32,6 → 36,7
set xrange [2500:25000]
#set yrange [0:1e9]
set autoscale y
plot "/tmp/spektra.txt" using 1:3 with lines title 'echo spectrum'
pause 1
set ytics 25000
plot "/tmp/spektra.txt" using 1:3 with lines title 'Left echo spectrum', "" using 1:4 with lines title 'Right echo spectrum'
pause 2
reread