Subversion Repositories svnkaklik

Rev

Rev 563 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 563 Rev 564
Line 173... Line 173...
173
unsigned int linear_windowed_chirp(short *pole)
173
unsigned int linear_windowed_chirp(short *pole)
174
{
174
{
175
    unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
175
    unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
176
 
176
 
177
    static const float f0 = 5000;		//starting frequency
177
    static const float f0 = 5000;		//starting frequency
178
    static const float fmax = 13000;		//ending frequency
178
    static const float fmax = 7500;		//ending frequency
179
    static const float Tw = 0.0015;
179
    static const float Tw = 0.0015;
180
    static float k;
180
    static float k;
181
 
181
 
182
    unsigned int n=0;
182
    unsigned int n=0;
183
    double t;
183
    double t;
Line 312... Line 312...
312
        printf("Start error: %s\n", snd_strerror(err));
312
        printf("Start error: %s\n", snd_strerror(err));
313
        exit(EXIT_FAILURE);
313
        exit(EXIT_FAILURE);
314
    }
314
    }
315
    else printf("Waiting for transmitt all samples\n");
315
    else printf("Waiting for transmitt all samples\n");
316
//--------------
316
//--------------
-
 
317
 
317
    while ( snd_pcm_avail_update(capture_handle) < period_size)
318
    while ( snd_pcm_avail_update(capture_handle) < period_size)			// wait for one period of data
318
    {
319
    {
319
        usleep(1000);
320
        usleep(1000);
320
        printf(".");
321
        printf(".");
321
    }
322
    }
322
 
323
 
323
    err = snd_pcm_drop(playback_handle);
324
    err = snd_pcm_drop(playback_handle);		// stop audio stream
324
    err = snd_pcm_drain(capture_handle);
325
    err = snd_pcm_drain(capture_handle);
325
    if (err < 0)
326
    if (err < 0)
326
    {
327
    {
327
        printf("Stop error: %s\n", snd_strerror(err));
328
        printf("Stop error: %s\n", snd_strerror(err));
328
        exit(EXIT_FAILURE);
329
        exit(EXIT_FAILURE);
329
    }
330
    }
330
 
331
 
331
    err = snd_pcm_readi(capture_handle, signal, period_size);
332
    err = snd_pcm_readi(capture_handle, signal, period_size);		//read period from audio buffer
332
    if (err < 0)
333
    if (err < 0)
333
    {
334
    {
334
        printf("Read error: %s\n", snd_strerror(err));
335
        printf("Read error: %s\n", snd_strerror(err));
335
        exit(EXIT_FAILURE);
336
        exit(EXIT_FAILURE);
336
    }
337
    }
Line 372... Line 373...
372
            delayr[1] = n;
373
            delayr[1] = n;
373
            r = correlationr[n];
374
            r = correlationr[n];
374
        }
375
        }
375
    }
376
    }
376
 
377
 
-
 
378
    for(i=delayl[1]; i < delayl[1] + chirp_size; i++) inchirp[i-delayl[1]] = L_signal[i];
377
    
379
    fftw_execute(fft_plan_chirp);
-
 
380
    for(i=0; i < frequency_bins; i++) echo_spect[i] = sqrt(outchirp[i][0] * outchirp[i][0] + outchirp[i][1] * outchirp[i][1]);
378
 
381
 
379
    printf("Writing output file\n");
382
    printf("Writing output files\n");
380
    out=fopen("/tmp/sonar.txt","w");
383
    out=fopen("/tmp/sonar.txt","w");
381
    j=0;
-
 
382
    for (i=0; i <= (period_size - 1); i++)
384
    for (i=0; i <= (period_size - 1); i++)
383
    {
385
    {
384
        fprintf(out,"%6d %6d %6d %9ld %9ld\n",i,L_signal[i],R_signal[i],correlationl[i], correlationr[i]);
386
        fprintf(out,"%6d %6d %6d %9ld %9ld\n",i,L_signal[i],R_signal[i],correlationl[i], correlationr[i]);
385
        j+=2;
-
 
386
    }
387
    }
387
    fclose(out);
388
    fclose(out);
388
 
389
 
389
    out=fopen("/tmp/chirp.txt","w");
390
    out=fopen("/tmp/chirp.txt","w");
390
    j=0;
-
 
391
    for (i=0; i <= (chirp_size - 1); i++)
391
    for (i=0; i <= (chirp_size - 1); i++)
392
    {
392
    {
393
        fprintf(out,"%6d %6d %f\n", i, chirp[i], chirp_spect[i]);
393
        fprintf(out,"%6d %6d\n", i, chirp[i]);
-
 
394
    }
-
 
395
    fclose(out);
-
 
396
 
-
 
397
    out=fopen("/tmp/echo.txt","w");
-
 
398
    for(i=delayl[1]; i < delayl[1] + chirp_size; i++) fprintf(out,"%6d %6d\n", i-delayl[1], L_signal[i]);
394
        j+=2;
399
    fclose(out);
-
 
400
 
-
 
401
    out=fopen("/tmp/spektra.txt","w");
-
 
402
    for (i=0; i < frequency_bins; i++)
-
 
403
    {
-
 
404
        fprintf(out,"%4.3f %4.3f %4.3f\n", (i+0.5) * df, chirp_spect[i], echo_spect[i]);
395
    }
405
    }
396
    fclose(out);
406
    fclose(out);
397
 
407
 
398
    printf("Echo zacina na: %d vzorku.\n", delayl[1]);
408
    printf("Echo zacina na: %d vzorku.\n", delayl[1]);
399
    printf("Casove na: %f s\n", ((float)delayl[1]/rate));
409
    printf("Casove na: %f s\n", ((float)delayl[1]/rate));