/programy/C/ix86/echo/SW/plot.gn |
---|
5,17 → 5,21 |
set size 1,0.2 |
set origin 0,0.8 |
set xrange [0:400] |
plot "/tmp/sonar.txt" using 1:($2/2) with lines title 'chirp' |
set xrange [0:150] |
set autoscale y |
plot "/tmp/chirp.txt" using 1:2 with lines title 'chirp' |
set size 1,0.4 |
set origin 0,0.4 |
set xrange [0:3000] |
plot "" using 1:($3) with lines title 'L echo', "" using 1:($4) with lines title 'R echo' |
set autoscale y |
plot "/tmp/sonar.txt" using 1:2 with lines title 'L echo', "" using 1:3 with lines title 'R echo' |
set size 1,0.4 |
set origin 0,0.0 |
set xrange [0:3000] |
#set yrange [-200000:200000] |
set autoscale y |
plot "" using 1:($5/1000) with lines title 'L correlation', "" using 1:($6/1000) with lines title 'R correlation' |
set yrange [0:1e9] |
#set autoscale y |
plot "/tmp/sonar.txt" using 1:4 with lines title 'L correlation', "" using 1:5 with lines title 'R correlation' |
pause 1 |
reread |
/programy/C/ix86/echo/SW/sonar/Makefile |
---|
101,7 → 101,7 |
INSTALL_SCRIPT = ${INSTALL} |
INSTALL_STRIP_PROGRAM = $(install_sh) -c -s |
LD = /usr/bin/ld -m elf_x86_64 |
LDFLAGS = -lasound |
LDFLAGS = -lasound -lfftw3 |
LIBOBJS = |
LIBS = |
LIBTOOL = $(SHELL) $(top_builddir)/libtool |
/programy/C/ix86/echo/SW/sonar/README |
---|
0,0 → 1,0 |
Small sonar demo aplication which uses soundcard as air interface. |
/programy/C/ix86/echo/SW/sonar/config.log |
---|
73,7 → 73,7 |
gcc: '-V' option must have argument |
configure:2846: $? = 1 |
configure:2869: checking for C compiler default output file name |
configure:2891: gcc -lasound conftest.c >&5 |
configure:2891: gcc -lasound -lfftw3 conftest.c >&5 |
configure:2895: $? = 0 |
configure:2933: result: a.out |
configure:2952: checking whether the C compiler works |
83,7 → 83,7 |
configure:2992: checking whether we are cross compiling |
configure:2994: result: no |
configure:2997: checking for suffix of executables |
configure:3004: gcc -o conftest -lasound conftest.c >&5 |
configure:3004: gcc -o conftest -lasound -lfftw3 conftest.c >&5 |
configure:3008: $? = 0 |
configure:3034: result: |
configure:3040: checking for suffix of object files |
159,7 → 159,7 |
configure:5363: $? = 0 |
configure:5367: /usr/bin/nm -B conftest.o \| sed -n -e 's/^.*[ ]\([ABCDGIRSTW][ABCDGIRSTW]*\)[ ][ ]*\([_A-Za-z][_A-Za-z0-9]*\)$/\1 \2 \2/p' \> conftest.nm |
configure:5370: $? = 0 |
configure:5424: gcc -o conftest -g -O2 -lasound conftest.c conftstm.o >&5 |
configure:5424: gcc -o conftest -g -O2 -lasound -lfftw3 conftest.c conftstm.o >&5 |
configure:5427: $? = 0 |
configure:5465: result: ok |
configure:5561: gcc -c -g -O2 conftest.c >&5 |
201,7 → 201,7 |
configure:6564: checking for ANSI C header files |
configure:6594: gcc -c -g -O2 conftest.c >&5 |
configure:6601: $? = 0 |
configure:6700: gcc -o conftest -g -O2 -lasound conftest.c >&5 |
configure:6700: gcc -o conftest -g -O2 -lasound -lfftw3 conftest.c >&5 |
configure:6704: $? = 0 |
configure:6710: ./conftest |
configure:6714: $? = 0 |
276,7 → 276,7 |
configure:9071: $? = 0 |
configure:9083: result: no |
configure:9247: checking dynamic linker characteristics |
configure:9690: gcc -o conftest -g -O2 -lasound -Wl,-rpath -Wl,/foo conftest.c >&5 |
configure:9690: gcc -o conftest -g -O2 -lasound -lfftw3 -Wl,-rpath -Wl,/foo conftest.c >&5 |
configure:9697: $? = 0 |
configure:9942: result: GNU/Linux ld.so |
configure:10044: checking how to hardcode library paths into programs |
309,6 → 309,7 |
config.status:982: creating Makefile |
config.status:982: creating src/Makefile |
config.status:982: creating config.h |
config.status:1204: config.h is unchanged |
config.status:1256: executing depfiles commands |
config.status:1256: executing libtool commands |
327,7 → 328,7 |
ac_cv_env_CPP_set= |
ac_cv_env_CPP_value= |
ac_cv_env_LDFLAGS_set=set |
ac_cv_env_LDFLAGS_value=-lasound |
ac_cv_env_LDFLAGS_value='-lasound -lfftw3' |
ac_cv_env_LIBS_set= |
ac_cv_env_LIBS_value= |
ac_cv_env_build_alias_set= |
421,7 → 422,7 |
INSTALL_SCRIPT='${INSTALL}' |
INSTALL_STRIP_PROGRAM='$(install_sh) -c -s' |
LD='/usr/bin/ld -m elf_x86_64' |
LDFLAGS='-lasound' |
LDFLAGS='-lasound -lfftw3' |
LIBOBJS='' |
LIBS='' |
LIBTOOL='$(SHELL) $(top_builddir)/libtool' |
/programy/C/ix86/echo/SW/sonar/config.status |
---|
357,7 → 357,7 |
ac_cs_version="\ |
config.status |
configured by /home/kaklik/projects/programy/C/ix86/echo/SW/sonar/configure, generated by GNU Autoconf 2.63, |
with options \"'LDFLAGS=-lasound'\" |
with options \"'LDFLAGS=-lasound -lfftw3'\" |
Copyright (C) 2008 Free Software Foundation, Inc. |
This config.status script is free software; the Free Software Foundation |
439,7 → 439,7 |
fi |
if $ac_cs_recheck; then |
set X '/bin/bash' '/home/kaklik/projects/programy/C/ix86/echo/SW/sonar/configure' 'LDFLAGS=-lasound' $ac_configure_extra_args --no-create --no-recursion |
set X '/bin/bash' '/home/kaklik/projects/programy/C/ix86/echo/SW/sonar/configure' 'LDFLAGS=-lasound -lfftw3' $ac_configure_extra_args --no-create --no-recursion |
shift |
$as_echo "running CONFIG_SHELL=/bin/bash $*" >&6 |
CONFIG_SHELL='/bin/bash' |
762,7 → 762,7 |
S["EXEEXT"]="" |
S["ac_ct_CC"]="gcc" |
S["CPPFLAGS"]="" |
S["LDFLAGS"]="-lasound" |
S["LDFLAGS"]="-lasound -lfftw3" |
S["CFLAGS"]="-g -O2" |
S["CC"]="gcc" |
S["am__untar"]="${AMTAR} xf -" |
/programy/C/ix86/echo/SW/sonar/sonar.kdevelop |
---|
14,8 → 14,8 |
<projectname>sonar</projectname> |
<projectdirectory>.</projectdirectory> |
<absoluteprojectpath>false</absoluteprojectpath> |
<description/> |
<defaultencoding/> |
<description></description> |
<defaultencoding></defaultencoding> |
<versioncontrol>kdevsubversion</versioncontrol> |
</general> |
<kdevautoproject> |
26,8 → 26,8 |
<run> |
<mainprogram>/home/kaklik/projects/programy/C/ix86/echo/SW/sonar/debug</mainprogram> |
<terminal>true</terminal> |
<programargs/> |
<globaldebugarguments/> |
<programargs></programargs> |
<globaldebugarguments></globaldebugarguments> |
<globalcwd>/home/kaklik/projects/programy/C/ix86/echo/SW/sonar</globalcwd> |
<useglobalprogram>false</useglobalprogram> |
<autocompile>false</autocompile> |
62,20 → 62,20 |
</debug> |
<default> |
<envvars/> |
<configargs/> |
<builddir/> |
<topsourcedir/> |
<cppflags/> |
<ldflags>-lasound</ldflags> |
<configargs></configargs> |
<builddir></builddir> |
<topsourcedir></topsourcedir> |
<cppflags></cppflags> |
<ldflags>-lasound -lfftw3</ldflags> |
<ccompiler>kdevgccoptions</ccompiler> |
<cxxcompiler>kdevgppoptions</cxxcompiler> |
<f77compiler>kdevg77options</f77compiler> |
<ccompilerbinary/> |
<cxxcompilerbinary/> |
<f77compilerbinary/> |
<cflags/> |
<cxxflags/> |
<f77flags/> |
<ccompilerbinary></ccompilerbinary> |
<cxxcompilerbinary></cxxcompilerbinary> |
<f77compilerbinary></f77compilerbinary> |
<cflags></cflags> |
<cxxflags></cxxflags> |
<f77flags></f77flags> |
</default> |
</configurations> |
<make> |
87,7 → 87,7 |
<runmultiplejobs>false</runmultiplejobs> |
<numberofjobs>1</numberofjobs> |
<dontact>false</dontact> |
<makebin/> |
<makebin></makebin> |
<prio>0</prio> |
</make> |
</kdevautoproject> |
216,7 → 216,7 |
<includePaths>.;</includePaths> |
</codecompletion> |
<creategettersetter> |
<prefixGet/> |
<prefixGet></prefixGet> |
<prefixSet>set</prefixSet> |
<prefixVariable>m_,_</prefixVariable> |
<parameterName>theValue</parameterName> |
237,11 → 237,11 |
</cppsupportpart> |
<kdevdebugger> |
<general> |
<gdbpath/> |
<gdbpath></gdbpath> |
<dbgshell>libtool</dbgshell> |
<configGdbScript/> |
<runShellScript/> |
<runGdbScript/> |
<configGdbScript></configGdbScript> |
<runShellScript></runShellScript> |
<runGdbScript></runGdbScript> |
<breakonloadinglibs>true</breakonloadinglibs> |
<separatetty>false</separatetty> |
<floatingtoolbar>false</floatingtoolbar> |
/programy/C/ix86/echo/SW/sonar/src/.deps/sonar.Po |
---|
36,7 → 36,7 |
/usr/include/alsa/seq_midi_event.h /usr/include/sys/time.h \ |
/usr/include/math.h /usr/include/bits/huge_val.h \ |
/usr/include/bits/mathdef.h /usr/include/bits/mathcalls.h \ |
/usr/include/bits/mathinline.h |
/usr/include/bits/mathinline.h /usr/include/fftw3.h |
/usr/include/stdio.h: |
193,3 → 193,5 |
/usr/include/bits/mathcalls.h: |
/usr/include/bits/mathinline.h: |
/usr/include/fftw3.h: |
/programy/C/ix86/echo/SW/sonar/src/Makefile |
---|
98,7 → 98,7 |
INSTALL_SCRIPT = ${INSTALL} |
INSTALL_STRIP_PROGRAM = $(install_sh) -c -s |
LD = /usr/bin/ld -m elf_x86_64 |
LDFLAGS = -lasound |
LDFLAGS = -lasound -lfftw3 |
LIBOBJS = |
LIBS = |
LIBTOOL = $(SHELL) $(top_builddir)/libtool |
/programy/C/ix86/echo/SW/sonar/src/sonar |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/programy/C/ix86/echo/SW/sonar/src/sonar.c |
---|
16,6 → 16,7 |
#include <alsa/asoundlib.h> |
#include <sys/time.h> |
#include <math.h> |
#include <fftw3.h> |
#define SOUND_SPEED 340.0 // sound speed in air in metrs per second |
#define MAX_RANGE 10.0 // maximal working radius in meters |
143,7 → 144,7 |
printf("Unable to determine current swparams for playback: %s\n", snd_strerror(err)); |
return err; |
} |
// start the transfer when the buffer is almost full: never fou our case |
// start the transfer when the buffer is almost full: never fou our case |
err = snd_pcm_sw_params_set_start_threshold(handle, swparams, 2 * buffer_size); |
if (err < 0) |
{ |
203,10 → 204,17 |
long int *correlationl, *correlationr; |
int *L_signal, *R_signal; |
short *chirp, *signal; |
float *chirp_spect, *echo_spect; |
unsigned int i,j,m,n; |
unsigned int delay[10]; //store delay of signifed correlation |
unsigned int delayl[10],delayr[10]; //store delay of signifed correlation |
long int l,r; // store correlation at strict time |
double df; //frequency resolution |
unsigned int frequency_bins; // number of output frequency bins |
double *inchirp; |
fftw_complex *outchirp; |
fftw_plan fft_plan_chirp; |
FILE *out; |
snd_pcm_hw_params_alloca(&hwparams); |
250,12 → 258,12 |
exit(EXIT_FAILURE); |
} |
/* err = snd_pcm_link( capture_handle, playback_handle); //link capture and playback together |
if (err < 0) |
{ |
printf("Device linking error: %s\n", snd_strerror(err)); |
exit(EXIT_FAILURE); |
}*/ |
/* err = snd_pcm_link( capture_handle, playback_handle); //link capture and playback together |
if (err < 0) |
{ |
printf("Device linking error: %s\n", snd_strerror(err)); |
exit(EXIT_FAILURE); |
}*/ |
correlationl = malloc(period_size * sizeof(long int)); //array to store correlation curve |
correlationr = malloc(period_size * sizeof(long int)); //array to store correlation curve |
267,6 → 275,22 |
// generate ping pattern |
chirp_size = linear_windowed_chirp(chirp); |
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)); |
inchirp = fftw_malloc(sizeof(double) * chirp_size); // allocate input array for FFT |
outchirp = fftw_malloc(sizeof(fftw_complex) * frequency_bins); |
fft_plan_chirp = fftw_plan_dft_r2c_1d(chirp_size, inchirp, outchirp, FFTW_ESTIMATE); |
printf("compute chirp spectrum\n"); |
for(i=0; i < chirp_size; i++) inchirp[i] = chirp[i]; |
fftw_execute(fft_plan_chirp); |
for(i=0; i < frequency_bins; i++) chirp_spect[i] = sqrt( outchirp[i][0] * outchirp[i][0] + outchirp[i][1] * outchirp[i][1] ); |
// write chirp data to souncard buffer |
err = snd_pcm_writei(playback_handle, chirp, period_size); |
if (err < 0) |
{ |
290,7 → 314,6 |
} |
else printf("Waiting for transmitt all samples\n"); |
//-------------- |
while ( snd_pcm_avail_update(capture_handle) < period_size) |
{ |
usleep(1000); |
325,13 → 348,13 |
{ |
l=0; |
r=0; |
for (m=0;m < chirp_size;m++) |
for ( m = 0; m < chirp_size;m++) |
{ |
l += chirp[m]*L_signal[m+n]; // correlate with left channel |
r += chirp[m]*R_signal[m+n]; // correlate with right channel |
} |
correlationl[n]=l; |
correlationr[n]=r; |
correlationl[n]=abs(l); |
correlationr[n]=abs(r); |
} |
printf("Searching echos\n"); |
341,30 → 364,48 |
{ |
if (l < correlationl[n]) |
{ |
delay[1] = n; |
delayl[1] = n; |
l = correlationl[n]; |
} |
if (r < correlationr[n]) |
{ |
delay[2] = n; |
delayr[1] = n; |
r = correlationr[n]; |
} |
} |
printf("Writing output file\n"); |
out=fopen("/tmp/sonar.txt","w"); |
j=0; |
for (i=0; i <= (period_size -1); i++) |
for (i=0; i <= (period_size - 1); i++) |
{ |
fprintf(out,"%6d %6d %6d %6d %9ld %9ld\n",i,chirp[i],L_signal[i],R_signal[i],correlationl[i], correlationr[i]); |
fprintf(out,"%6d %6d %6d %9ld %9ld\n",i,L_signal[i],R_signal[i],correlationl[i], correlationr[i]); |
j+=2; |
} |
fclose(out); |
printf("Echo zacina na: %d vzorku.\n", delay[1]); |
printf("Casove na: %f s\n", ((float)delay[1]/rate)); |
printf("vzdalenost: %f m\n", (SOUND_SPEED*(float)delay[1]/rate)); |
out=fopen("/tmp/chirp.txt","w"); |
j=0; |
for (i=0; i <= (chirp_size - 1); i++) |
{ |
fprintf(out,"%6d %6d %f\n", i, chirp[i], chirp_spect[i]); |
j+=2; |
} |
fclose(out); |
printf("Echo zacina na: %d vzorku.\n", delayl[1]); |
printf("Casove na: %f s\n", ((float)delayl[1]/rate)); |
printf("vzdalenost: %f m\n", (SOUND_SPEED*(float)delayl[1]/rate)); |
free(correlationl); |
free(correlationr); |
free(L_signal); |
free(R_signal); |
free(chirp); |
free(signal); |
snd_pcm_close(playback_handle); |
snd_pcm_close(capture_handle); |
return 0; |