Subversion Repositories svnkaklik

Rev

Rev 662 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 662 Rev 663
Line 187... Line 187...
187
    chirp_samples = ceil(rate*Tw);	// compute size of ping sinal in samples
187
    chirp_samples = ceil(rate*Tw);	// compute size of ping sinal in samples
188
 
188
 
189
    for (n=0;n<=chirp_samples;n++)
189
    for (n=0;n<=chirp_samples;n++)
190
    {
190
    {
191
        t = (double) n / (double)rate;
191
        t = (double) n / (double)rate;
192
        pole[n] = (short) floor( (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))) ); // signal generation formula
192
        pole[n] = (short) floor( (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))) ); // ping signal generation formula
193
    }
193
    }
194
    return (chirp_samples);	// return count of samples in ping
194
    return (chirp_samples);	// return count of samples in ping
195
}
195
}
196
 
196
 
197
int main(int argc, char *argv[])
197
int main(int argc, char *argv[])
198
{
198
{
199
    snd_pcm_t *playback_handle, *capture_handle;
199
    snd_pcm_t *playback_handle, *capture_handle;		//variables for driver handlers
200
    int err;
200
    int err;
201
    snd_pcm_hw_params_t *hwparams;
201
    snd_pcm_hw_params_t *hwparams;		// hardware and software parameters arrays
202
    snd_pcm_sw_params_t *swparams;
202
    snd_pcm_sw_params_t *swparams;
203
 
203
 
204
    long int *correlationl, *correlationr;
204
    long int *correlationl, *correlationr;	// pointers to arrays where correlation will be stored
205
    float k;
205
    float k;
206
    int *L_signal, *R_signal;
206
    int *L_signal, *R_signal;	// array of captured data from left and right channel
207
    short *chirp, *signal;
207
    short *chirp, *signal;	// chirp and soundcard buffer output data
208
    unsigned int i,j,m,n;
208
    unsigned int i,j,m,n;
209
    unsigned int map_size; //number of points in echo map.
209
    unsigned int map_size; //number of points in echo map.
210
    long int l,r;  // store correlation at strict time
210
    long int l,r;  // store correlation at strict time
211
 
211
 
212
    FILE *out;		// dummy variable for file data output
212
    FILE *out;		// dummy variable for file data output
Line 294... Line 294...
294
        exit(EXIT_FAILURE);
294
        exit(EXIT_FAILURE);
295
    }
295
    }
296
    else printf("Transmitting all samples of chirp\n");
296
    else printf("Transmitting all samples of chirp\n");
297
//--------------
297
//--------------
298
 
298
 
299
    while ( snd_pcm_avail_update(capture_handle) < period_size)			// wait for one period of data
299
    while ( snd_pcm_avail_update(capture_handle) < period_size)			// wait until one period of data is transmitted
300
    {
300
    {
301
        usleep(1000);
301
        usleep(1000);
302
        printf(".");
302
        printf(".");
303
    }
303
    }
304
 
304
 
Line 338... Line 338...
338
        correlationl[n]=abs(l);
338
        correlationl[n]=abs(l);
339
        correlationr[n]=abs(r);
339
        correlationr[n]=abs(r);
340
    }
340
    }
341
 
341
 
342
    printf("Writing output files\n");
342
    printf("Writing output files\n");
343
    out=fopen("/tmp/sonar.txt","w");
343
    out=fopen("/tmp/sonar.txt","w");		// save captured and computed correlation data for both channels
344
    for (i=0; i <= (period_size - 1); i++)
344
    for (i=0; i <= (period_size - 1); i++)
345
    {
345
    {
346
        fprintf(out,"%2.3f %6d %6d %9ld %9ld\n",i*k, L_signal[i], R_signal[i], correlationl[i], correlationr[i]);
346
        fprintf(out,"%2.3f %6d %6d %9ld %9ld\n",i*k, L_signal[i], R_signal[i], correlationl[i], correlationr[i]);
347
    }
347
    }
348
    fclose(out);
348
    fclose(out);
349
 
349
 
350
    out=fopen("/tmp/chirp.txt","w");
350
    out=fopen("/tmp/chirp.txt","w");		// save chirp data to someone who want it
351
    for (i=0; i <= (chirp_size - 1); i++)
351
    for (i=0; i <= (chirp_size - 1); i++)
352
    {
352
    {
353
        fprintf(out,"%6d %6d\n", i, chirp[i]);
353
        fprintf(out,"%6d %6d\n", i, chirp[i]);
354
    }
354
    }
355
    fclose(out);
355
    fclose(out);
356
 
356
 
357
    printf("Job done.\n");
357
    printf("Job done.\n");
358
 
358
 
-
 
359
				//free all arrays 
359
    free(correlationl);
360
    free(correlationl);
360
    free(correlationr);
361
    free(correlationr);
361
    free(L_signal);
362
    free(L_signal);
362
    free(R_signal);
363
    free(R_signal);
363
    free(chirp);
364
    free(chirp);
364
    free(signal);
365
    free(signal);
365
 
366
 
366
    snd_pcm_close(playback_handle);
367
    snd_pcm_close(playback_handle);	// free driver handlers 
367
    snd_pcm_close(capture_handle);
368
    snd_pcm_close(capture_handle);
368
    return 0;
369
    return 0;
369
}
370
}
370
 
371