PDA

View Full Version : How to detect sound direction?



Kamikaze47
- 23rd November 2008, 12:27
Has anyone used PBP and 2 or more microphones to detect the direction that a loud sound comes from?

If not, any ideas?

I'm thinking of starting with 2 microphones connected to ADCs and using that to measure the time difference between a sound over a certain threshold being detected in each microphone.

But im not sure how accurate the timing will be. I'm thinking I may have to use 2 PICs, because as far as i know, you can only select one ADC channel at once.

Ioannis
- 23rd November 2008, 12:37
And if two different sounds come wih slightly different time, from 2 different locations?

You have to identify the sounds first. If they are tha same, then try to locate them. But in my opinion this is not so easy. Humans can detect the direction in any of the x-y-z axis because of the ear construction and not only of time difference. It is more complicated than it sounds! Literally!

Ioannis

Kamikaze47
- 23rd November 2008, 12:44
Yeah, I realise that its difficult, and I wouldn't expect anything I come up with to be perfect.

Thinking about it more, 2 microphones wont do the trick. I think with 3 microphones in a triangle and a bit of creative code it would be possible to make something that could crudely pinpoint the directions of loud noises.

Ryan7777
- 4th December 2008, 17:05
You would need an amp of some sort of course, opamp, whatever. Then feed that into a schmitt trigger to get a nice square wave and then detect which mic triggers first and how long it takes to get the second trigger. that might give you a rough direction, but sound waves move pretty fast and arent always super directional, and there are tons of stuff that can affect them.
But I did build a lightning detector that used the flash of light to trigger my digital SLR. I used a fast photodiode and an pic with an ADC so i could set a threshold to handle ambient light. So speed may not be that big an issue anyway

rswain
- 11th December 2008, 00:28
You can do what you want to do, but don't think this is going to be an easy project for the weekend. You'll need to convert to square waves, use the internal comparator, use as high a clock speed as possible, 2 PICs, comms between the PICs, and OPAMPs externally for a start. Yes, you need 3 mics (or 4 might be easier). Or, just deal with the left-right ambiguity if you can (much simpler if you know which 180 degrees of the originating signal). You're probably not going to be happy with the results in the end. You're trying to accomplish Time Difference of Arrival (TDOA) with a ~40 MHz (10 really) PIC. Get really comfortable with PBP and interrupts. Read up on "zero crossing detection" as well. It isn't because of the speed of sound, but the looong waves and abiguity in the zero crossings that will make this rough. You'll have to get good with the internal counters also.Brush up on your trigonometry too. PBP isn't strong in that area. In the end, you're going to have most of the chip working toward the goal and still not be happy with the result. YOU'RE GOING TO LEARN A TON TRYING!! I don't mean to sound like this is impossible, but you're biting off a REALLY big chunk of work. Great idea, but hard (and advanced) to implement! Even experienced programmers struggle with TDOA and higher power processors than PICs.

Another possible way to do it if you're not worried about accuracy so much is to set up 8 mics in a wide as possible circle (omni mics pointing up) and external circuits to amplify and convert to square waves at zero crossings, and then use port B (interrupt on change). At least you can tell the basic direction of arrival (45 degrees-ish) instead of all the work of true TDOA. As others said, this is going to be hard to do if you have interfering sounds at all. How would you want to display the information? LEDs in a compass rose? To the LCD? Serial data out?

Post your code when you're done! Good luck.

Kamikaze47
- 11th December 2008, 18:02
I realise that this isnt a quick and easy project, but since i'm struggling to come up with ideas of what to make next, I figured ill give it a try.

I have had some experience with the things rswain mentioned including interrupts, counters, comparators and some basic zero-crossing detection. The fun bit is going to be getting all of those things to work together to produce a result.

I feel pretty confident about the coding side of things (or at least as confident as you can be when trying to tackle a tricky problem). Where my knowledge is going to let me down is the analogue electronics side. As soon as things are digital im fairly comfortable.

Does anyone have ideas on how best to amplify the mic signals and convert them to square waves? I think this is where I will struggle the most.

Kamikaze47
- 11th December 2008, 19:11
This is what i'm thinking at the moment, but as I said, analogue electronics isnt my strong point so I could be way off track.

Opamp and schmitt trigger configured for threshold detection:

http://www.iinet.net.au/~steven/files/circuit.jpg

brid0030
- 13th December 2008, 04:53
What if, instead of using time of arrival to determine where a sound comes from, you use directional microphones. Or you use some sort of muffling cone to reduce the sound energy that reaches the mike from behind. Then you could measure sound intensity from all of the mikes and compare loudness to get a direction. Its not as sophisticated as the timing approach, but it might be easier to implement given the simple situation you describe with a single loud noise. Maybe you need decibel meters and not microphones. Sounds cool. Good luck.