Subversion Repositories svnkaklik

Compare Revisions

Ignore whitespace Rev 538 → Rev 539

/programy/C/ix86/sound/plot.gn
1,6 → 1,6
!./sonar
set xrange [0:4000]
set yrange [-30000:30000]
plot "./output.txt" using 1:($2/2) with lines title 'chirp' , "" using 1:($3*10-10000) with lines title 'echo' ,"" using 1:($4/5000+10000) with lines title 'Correlation'
plot "./output.txt" using 1:($2/2) with lines title 'chirp' , "" using 1:($3*5-10000) with lines title 'echo' ,"" using 1:($4/5000+10000) with lines title 'Correlation'
pause 1
reread
/programy/C/ix86/sound/sonar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/programy/C/ix86/sound/sonar.c
169,6 → 169,8
unsigned int period;
};
 
 
////// SIGNAL GENERATION STUFF
/*int linear_chirp(int *pole, int delka_pole){ // vygeneruje linearni chirp a vzorky ulozi do pole
 
static const float f0 = 0.0001;
184,12 → 186,12
}*/
 
// vygeneruje linearni chirp a vzorky ulozi do pole
unsigned int linear_windowed_chirp(unsigned int *pole, unsigned int delka_pole)
{
unsigned int linear_windowed_chirp(unsigned int *pole, unsigned int delka_pole,unsigned int offset)
{
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
 
static const float f0 = 3000;
static const float fmax = 5000;
static const float f0 = 1000;
static const float fmax = 10000;
static const float Tw = 0.002;
static float k;
 
202,9 → 204,9
 
for(n=0;n<=perioda;n++){
t = (double) n/ (double)rate;
pole[n] = (short) round ( (0.35875 - 0.48829*cos(2*M_PI*t*1/Tw) + 0.14128*cos(2*M_PI*2*t*1/Tw) - 0.01168*cos(2*M_PI*3*t*1/Tw))*maxval*sin(2*M_PI*(t)*(f0+(k/2)*(t))) );
pole[n+offset] = (short) round ( (0.35875 - 0.48829*cos(2*M_PI*t*1/Tw) + 0.14128*cos(2*M_PI*2*t*1/Tw) - 0.01168*cos(2*M_PI*3*t*1/Tw))*maxval*sin(2*M_PI*(t)*(f0+(k/2)*(t))) );
}
return perioda;
return (perioda+offset);
}
 
// generate sine samples and store
219,9 → 221,20
pole[n] = (short) round(maxval*sin(2*M_PI*t));
}
}
//// generate simple sine ping
unsigned int sine_ping(unsigned int *pole, unsigned int delka_pole,unsigned int offset, double frequency)
{
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
unsigned int n;
double t;
 
for(n=0;n < delka_pole;n++){
t = frequency * (double) n/ (double)rate;
pole[n] = (short) round(maxval*sin(2*M_PI*t));
}
}
 
 
/////////// CALL BACK STUFF ///////////////////
static void async_playback_callback(snd_async_handler_t *ahandler)
{
snd_pcm_t *handle = snd_async_handler_get_pcm(ahandler);
329,8 → 342,10
exit(EXIT_FAILURE);
}
 
chirp_size=linear_windowed_chirp(chirp,1000000);
/// generate ping pattern
 
chirp_size=linear_windowed_chirp(chirp,1000000, 300);
 
/// register playback callback
err = snd_async_add_pcm_handler(&phandler, playback_handle, async_playback_callback, &data); // fill by dummy &data
if (err < 0) {