Audio chirp sonar...


hamster

Recommended Posts

I'm working on an audio chirp sonar (http://en.wikipedia.org/wiki/Chirp), and so far my laptop tests seem to look pretty hopeful (see image below).

 

post-29512-0-10025900-1399628180_thumb.j

 

The graph is the correlation of the middle 512 words a 1024 sample chirp (about 23ms), when the sample was played on a laptop while recording at the same time.

 

Here's the 'C' code to generate the chirp file (as out.pcm - play with "aplay -r 44100 -c1 -f S16 out.pcm" on Linux) and also process a 44100 stereo 16-bit stereo audio file (WAV format works), in case you want to have a play.

#include <math.h>#include <stdio.h> short chirp[1024];short data[1024*1024*10]; long long match(short *s, short *c, int l){  int i;  long long total = 0;  for(i = 0; i < l; i++) {    total += s[i]*c[i];  }  if(total < 0) return -total;  return total;} int main(int argc, char *argv[]){  int i, samples;  double f0 = 100.0;  double k  = 400.0;  FILE *f;  for(i =0; i < 1024; i++) {    double angle;    double t = i/1024.0;    angle = f0*t + k * 0.5 * t * t;    chirp[i] = (short)(sin(angle)*32767);  }   if(argc == 1) {    printf("Crating out.pcm\r\n");    f = fopen("out.pcm","wb");    fwrite(chirp,sizeof(short),1024,f);    fclose(f);    return 0;  }   f = fopen(argv[1],"rb");  if(f == NULL) {    printf("Unable to open file \r\n");    return 0;  }  for(i = 0;i < 10*1024*1024; i++) {    short samples[2];    if(fread(samples,sizeof(samples),1,f) != 1)      break;    data[i] = samples[0]/2 + samples[1]/2;  }  fclose(f);  printf("%i samples read\r\n",i);  samples = i;   for(i = 0; i < samples-512;i++)     printf("%4i  %lli\r\n",i,match(data+i,chirp+256,512));   return 0;}

It is a pretty good fit for FPGA - each sample requires 512 MACs, so to process a 44100 S/s stream needs about 22.5 MegaMACs (nice and easy for a single DSP block, but too much for an Arduino).

Link to comment
Share on other sites

Interesting!

This is definitely a job where an FPGA can provide "hardware acceleration".

Note that audio speakers are designed for a "pink" spectrum, not white. A linear chirp has equal low- and high frequency content, so it is possible to damage speakers (done that myself via some OFDM-via-audio experiment that wasn't particularly ear-friendly).

Carrier frequency offset can be a problem. Consumer devices aren't too strict about the audio rate. Not an issue if transmitter and receiver are on the same board / reference clock, though.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.