Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 10 of 10

Thread: Point Triangulation from Sound with high accuracy

  1. #1
    Junior Member
    Join Date
    May 2020
    Posts
    7

    Point Triangulation from Sound with high accuracy

    I am in the middle of a project where I am trying to triangulate the source of a noise. I am going to use a teensy 4 for this project. I do not care about audio quality, I just need quick response to a noise over a certain threshold. I will use the teensy 4 to log the time difference between each microphone picking up the noise. I likely will not need interrupts as the maximum time between mics responding is about 1ms, so sampling should be fine. The first microphone to detect a noise will start a time and then when all the microphones "hear" the noise or a 1-2ms passes, the times will get passed to my raspberry pi to process the information.

    The overall mic-mic distance is relatively small ranging from about 280-400mm apart. Due to this, I need very high accuracy.

    I am planning on using 4 LT1721 comparators (10 ns delay) along with 4 electret microphones for the triangulation.

    I have read up a bit on electret mics and op amps and I have found that a high slew rate might be what I am looking for to reduce delay. Are there any other parameters that I should be interested in. I am capable of creating my own circuit, but for now would prefer to buy a mic/OpAmp combo.

    Along with this, what would be the recommended way to store data as to not lose time? I have read up on creating a buffers, but I am not sure how much data the teensy can store and the rate at which I will be sampling could turn into a lot of data if the memory of the Teensy 4 is very low.

    From my understanding with a 600Mhz processor, the max I could sample is at 300Mmz. Using 4 mics and comparators that would put me at 75Mhz. I believe this would be much faster than the on board ADC could handle.

    I am new to Teensy and new to audio sampling in general so any information is very helpful.

  2. #2
    Hi Tootsie:

    I am a bad coder and not an expert in microcontrollers at all, but I did a sound source ranging device based on a Teensy 3.2 some years ago.

    Firstly, I think you cannot assume a sampling rate based on the CPU frequency of the Teensy 4 alone. I may be wrong but I think that the max sampling rate at 12 bit resolution is 1.4 Mhz for that board.

    On the Teensy 3.2, using the excellent Pedvide's ADC library I was able to get over 500 ksamples/sec at 8 bit resolution on four signals (1+ Mhz per channel). I used 4 electret mikes from Sparkfun on a square array and was able to get half a cm resolution at 1 mt distance.
    At that sample rate I was limited to a max distance between mikes of 30-40 cm if I remember correctly, but I learnt that besides a faster sampling rate a bigger distance from each microphone would dramatically enhance the ranging measurement. In both cases you will need a bigger buffer though.
    I read the ADCs directly into a buffer, normalized the four signals, filtered out everything below a certain treshold, and then crosscorrelated them to get the time difference of arrival. I used a multilateration algorithm to get the ranging solution.

    Hope this helps, Juan

  3. #3
    Junior Member
    Join Date
    May 2020
    Posts
    7
    Hi Juan,

    Thanks for the response. Is there anyway you would be able to share the code you wrote for that? It is seemingly very close to what I would be doing and I am also a bad coder.

    If not, was the teensy 3.2 able to deal with the memory or did you have to add an sd card?


    I am worried about creating a buffer because it might be minutes before a signal is seen. After the signal is seen by the first mic, then it will quickly be seen by the next ones.
    I am only triangulating on a planar face, and also used multilateration equations. I have 4 mics but only really need 3 for the math, should I use the first mic that hears the noise as an interrupt and then use the data from the other 3? Or is there a way that I am not thinking about to make sure the data does not overflow.

    Also, does anyone know the bit depth of the Teensy 4 ADCs? I cannot find it on the website. Also I would assume that using both on board ADCs in parrallel would allow me to sample faster as well. I just downloaded the Pedvide library and am looking through it now.

  4. #4
    I am sorry to say that my code got lost with one of my old laptops... and the hardware I used was also repurposed.

    Everything was done using a single Teensy 3.2, no additional memory or sd cards were used. I was also putting the sound source on the mikes plane for the sake of simplification. I know that you only need 3 microphones, but if you use two channels like I did (connecting two mikes per ADC channel as you mention), the fourth microphone is free in terms of signal processing I guess.

    Teensy 4 should be even better at it. First, try to see what the maximum sampling rate per channel is. I just read that Pedvide's ADC library is now compatible with Teensy 4. Use it.
    Then, decide the size of the microphone array, measure the maximum distance between the mikes and set the buffer size in accordance to the number of samples it will take until it reaches the last microphone. You should take a headroom of four to six times this figure to set the buffer size and you should be safe.
    In order to get better results take into account the speed of sound at your altitude. In my case, living close to a mountain range (1000 mts) I had to correct that figure a bit.

    Regards, Juan
    PS: I think I will order some Teensy 4s and some piezo mikes to try it myself again

  5. #5
    Junior Member
    Join Date
    May 2020
    Posts
    7
    Ah too bad, but thanks for the information it will be very helpful. All of this makes sense. The one thing I still would like to figure out is how to start sampling. If I used all 4 microphones, how would I make sure that each microphone saved the data in the buffer at the time I wanted it to read.

    For instance, it might be a minute or more before any noise is made. I would not want to be saving data for that full minute, just when the first microphone "hears" the noise, then start recording to the buffers. I just wouldn't want to lose data do to not recording. Would I just look for voltage changes and when a certain threshold is hit, start recording?

  6. #6
    I think I used continuous analog read as Pedvide himself suggested, so you don't have to worry about triggering (hope you don't run on batteries).

    ===Quote===

    Start a continuous measurement on both ADCs using pins A2, and A3 (for example) in the setup already.
    In the loop:
    - store the values value1,value2.
    - start a normal measurement on pins A11, A10 and get the value
    - start a continuous measurement again on pins A2, A3.
    - process data.

    ---End Quote---

    You should find the details browsing through Pedvide's ADC library docs and examples as I did, hope this helps

    regards, Juan

  7. #7
    Senior Member
    Join Date
    Dec 2014
    Posts
    291
    You shouldn't use comparators or interrupts at all. Just use the ADC input(s) and sample the audio. Hook the microphones to the sound-in circuitry and use the Audio library to sample it.
    You should know the exact distance between the microphones, because you can't get an accurate direction sideways unless you know this. (propagation is about 1 ft per millisecond)
    Finally, the way to find sound is to do an autoconvolution between the two channels, to find the phase difference, and the phase delay you find between the two channels of audio, will tell you the bearing towards the sound source.

  8. #8
    Senior Member
    Join Date
    Oct 2015
    Location
    Vermont, USA
    Posts
    230
    Agreed, audio library.

    Also, consider using the teensy audio shield.

    Also, if you've never done it before, don't underestimate the challenge of learning the signal processing to actually detect your signals and to measure the time delay (the filtering and cross correlation).

    If you're just trying to make a simple demo for a class or whatever, you could assume that you're only direction-finding to super loud sounds that have a super sharp onset (like a strong handclap). In that case, you could just set a loudness threshold and measure the sample # (which is time) when the threshold is crossed from quiet-to-loud. The threshold-crossing time should be diff for the two mics, which should relate to the diff the the sound's travel time, which should scale with the diff in travel distance.

  9. #9
    Junior Member
    Join Date
    May 2020
    Posts
    7
    After lots of research, I've come to the same conclusion you both have for using the ADC and cross correlating each signal. I took a relatively extensive signal processing engineering class 6 years or so ago in collage so I am at least familiar with the ideas of everything going on.

    As of right now I take in the audio in all 4 microphones. When the sound crosses a noise threshold sampling begins to fill a buffer on all 4 microphones. When this is done, I normalize, then cross correlate the microphone that first heard the noise with the other 3 microphones. This gives the delay of all 3 microphones which corresponds to a time.

    I am now looking to filter the noise in order for the cross correlation to be more accurate. Below is the frequency response of the signal during the time frame of which I would be sampling. I was thinking that putting a band pass filter on the microphones from 210-310hz would help when cross correlating the two signals.
    Click image for larger version. 

Name:	wavepad_5NTJJYWXe2.png 
Views:	0 
Size:	34.2 KB 
ID:	20251

    Also I was thinking there could be a way to convolve each the signals with the original signal and then cross correlate to make this even better.


    I ordered the audio shield and will take a look at how that can help me as well.

  10. #10
    Senior Member
    Join Date
    Dec 2014
    Posts
    291
    When the sound crosses a noise threshold sampling begins to fill a buffer on all 4 microphones.
    It may be better to just run the sampling all the time, and when the noise crosses the threshold, wait for a small amount of time, and copy the data you need out of the buffer. That way, you get a copy of the data that happened before the threshold, and you don't need to wait for the ADC to spin up.

    I was thinking that putting a band pass filter on the microphones from 210-310hz would help when cross correlating the two signals.
    Which specific frequency band you pay attention to depends entirely on your specific application. If you think 210-310 works for you, then have at it!

    I was thinking there could be a way to convolve each the signals with the original signal and then cross correlate to make this even better.
    Isn't that what cross correlation does in the first place? Convolve with a shifting window, and figure out which phase gives the highest result?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •