I have been trying to achieve this for a long time using the ITD method and have gone through various articles on the net.

I want to know if its possible to actually achieve sound localization using an arduino uno and two MEMS mics with a high gain (https://www.sparkfun.com/products/9868).

I have been trying this on matlab using the a=arduino() command. And readVoltage command but the main issue I face is that for a particular sound (clapping for instance) the time difference between the two mics is not always the same which results in different direction predictions. We managed to increase the low resolution of the arduino by removing unnecessary operations. Now we are able to get an array of size 750 for 10 secs giving a resolution of 0.01 secs. I am not sure if that is enough.

I basically have 3 arrays, one storing the sampling times, and the other two storing the amplitudes of the two analog inputs at that particular time in the first array. Now i look for a peak in one and then the corresponding near peak in the second one and then compute the time difference. After this I can compute the angle using the speed of sound and the distance between the mics.

Please let me know how I can make this work or where I am going wrong.

  • 1
    Calculate the minimum distance given your setup. What do you get? And what parameter determines this and the increment/resolution? Also check your memory requirements. Remember that Uno has a total of 2K SRAM (and that must hold stack, heap, global variables). – Mikael Patel May 6 '18 at 9:18
  • 1
    How far does sound travel (at normal room temperature and air pressure) in 0.01 sec and/or the time to perform an analogRead()? Software Engineering is also about "doing the numbers". – Mikael Patel May 6 '18 at 11:13
  • 1
    How about the distance between the microphones? It is the delta between the source and the microphones you want to measure to determine the angle? – Mikael Patel May 6 '18 at 14:28
  • 1
    Here is some info that might help you with the engineering: ese.wustl.edu/ContentFiles/Research/UndergraduateResearch/… Please remember that the Arduino has a max sample rate of approx. 9 K samples per second when collecting all samples on the Arduino before processing. – Mikael Patel May 6 '18 at 14:41
  • 1
    I'm voting to close this question as off-topic because the limitations of an Arduino mean that it is not a useful part of a practical solution to the problem. Further, an MCU board is entirely unnecessary here; instead of using an Arduino, you should just route your two microphones to the PC's stereo microphone inputs, and surely Matlab has some capability or plugin that can capture audio from there. If your PC doesn't have stereo mic inputs, get a suitable solution to that problem like a stereo USB audio ADC (beware the cheap ones are mono, and you can't use two for this). – Chris Stratton May 6 '18 at 16:40

Let's assume a microphone distance of 0.5m (which may be just small enough for you). Sound travels with about 300m/s in normal conditions. Let's also say, that you want at least a precision in the angle measurement of 15°.

As stated in the project Mikael linked, it is important that the distance to the sound source is big enough (so that the waves can be seen as planar). Then you have the following situation: enter image description here

We are interested in the difference in distance, that the waves have to travel to the two microphones. It can be calculated by delta s = d * sin(alpha). With 15° we get delta s = 0.13m. The time difference is calculated by delta t = delta s/v, where v is the speed of sound. We get delta t = 0.43ms which equates to 2.32kHz sampling frequency. Since we use two microphones that must be sampled sequentially, the sampling frequency must be doubled. In the end we have a sampling frequency of 4.64kHz. So your sampling time of 0.01s wouldn't be enough for that.

The largest time difference in this setup (with the sound source in line with the microphones) would be 1.6ms, so your sampling time would be too big even for this.

Regarding the transmission with a baudrate of say 115200 baud this shouldn't be a problem.

But the actual speed of your setup highly depends on your code, which you haven't shown. Maybe this forum post can help you going further.

| improve this answer | |
  • Yes, but using an Arduino to sample audio on behalf of a PC only introduces extra complexity while drastically reducing the quality and amount of information compared to the internal sound card. – Chris Stratton May 6 '18 at 16:45
  • @chrisl Thanks for the detailed well explained answer. I'll try the procedure in the link. Please tell me if using a better micro controller (like- the NRF52 series sparkfun.com/products/13990) help in getting a better resolution. – geek101 May 6 '18 at 18:50
  • also is there a way to speeden up readVoltage on Matlab somehow to get this working maybe to a less precision of 30-90 degrees and d=1-1.5m. – geek101 May 6 '18 at 18:52
  • I don't know anything about the matlab functions. But Chris is right, that it will be easier to achieve with a direct connection from microphone to PC. – chrisl May 6 '18 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.