Pages

Tuesday, January 22, 2013

Arduino MicLoc or an Acoustic Location System

(update: MicLoc is further documented here)

I always liked the general concept of signal triangulation. I always wanted to write some software related to this. Maybe even design some hardware. We see it countless times in movies as a standard way to catch the bad guys. So as I studied through the various techniques of triangulation, trilateration, multilateration, I came across with Acoustic Location. Acoustic location methods use sound to determine the distance and direction of something and sounded perfect (pun intended) for my intents, which will became clearer later on.

In order for this to work I needed least 3 input sources which I strategically placed in my backyard. (you can see the rain protection mechanism in the photo)

If you have a stereo mic line in your PC, you already have 2 input channels, but you can't have 3 mics in 2 channels... So I went on and designed a multiplexing circuit with a 555 timer, a JK flip-flop and a 4066 digital switch (which I had readily available) to connect up to 4 mics sharing the mic input. If you sample at 44.1khz from the soundboard, divide bandwidth by 2, you get around 22 samples per millisecond. The speed of sound is around 334mm/ms so the setup should give some results... but it was a big FAIL!
That's because switching from theory to practice is a nasty business. The switching circuit introduced way too much noise to be useable and I ended up loosing too many samples to have any kind of decent precision.
So I went on to plan B...

Arduino MicLoc

Arduino has some cool features, one of them being the ADC, which allow us to sample analog signals from some source. I wanted to sample the microphones output at a pretty high sampling rate, so I started to investigate the limits of the ADC.
The ADC clock is 16 MHz divided by a prescale factor. The prescale default value is set to 128 (16MHz/128 = 125 KHz) in wiring.c. A conversion takes 13 ADC clocks, so the sampling rate is about 125KHz/13 or 9600 Hz. But you can mess around with the prescale factor, which allows you to sample at a much higher rate, which is essential to proper sound location. The setup is not complicated, despite all the wires. I have 3 microphones connected to 3 2N3904 based amplifier and feed into 3 analog channels (A0,A1,A2) on the arduino nano. A temperature sensor was also added.

The arduino samples each of the channels in turn and if the value (i.e. sound intensity) is above a certain threshold it records it. If the 3 mic are above the threshold within a certain time frame, the arduino write them out to the serial port. I wrote a daemon the is listening for this data to come in from the serial line, and then does its magic, using some fancy math with  the speed of sound, temperature, time difference between the samples, mic position and sample rate. After that, it spits out the most probable geographic position of the sound source in kml, which I directly connected as a network source to Google Earth and ended up with a realtime passive acoustic locating system.


You can see the mic positions on the satellite image, on the left. The Shot 1,2 and 3 are the actual location where I shot a BB gun and the red icons is where the Arduino MicLoc estimated the location of the shots. 
I was surprised with the accuracy of this project, given that I worked on in for a weekend and extra cheap materials I used. I believe a sub meter precision shouldn't be very hard to achieve, adding some more mics, better quality amplifiers and a little software tunning.

So why MicLoc? I was pretty sure the local hunters are hunting too close to my house. I just wanted to actually see where they were shooting, in realtime!
Oh, and because MicLoc is cool.

29 comments:

  1. I agree, very cool. Being able to determine surroundings and location of events. If you do any further experimentation, please keep publishing.

    ReplyDelete
  2. You should develop it further to address the Rhino poachers in the Kruger Park, South Africa and else where. Should sample the frequency of gun shots to detect the poachers

    ReplyDelete
  3. Ali Bossi, that's a very nice idea. I'll think about that and how such a system could be deployed in a low cost approach.

    ReplyDelete
  4. Mt bom!
    Parabéns pelo projecto.

    ReplyDelete
  5. Any chance you'll release your code and findings as open source, I've tried something like this before and was epic fail.

    Interested to see how you have made the amp and if you had any problem with the distance of the cable for the MICs.

    ReplyDelete
  6. Very nice job. I hope you'll be releasing your code and more details. My users group has been working on something similar but with a ping pong table. I think you have the benefit of longer distances but I'd really like to see your code and know more about the microphones you're using.

    ReplyDelete
  7. Nice project!
    A tip to increase precision of the locations is to arrange the sensors in an equilateral triangle. Unless you know where the signal is supposed to com from, then it is best to put the sensors perpendicular to that location.
    Also bigger is better, more separation of the sensors decreases numeric and measurement errors and noise.
    Maybe you all ready knew.

    ReplyDelete
  8. Really great work and good idea!

    ReplyDelete
  9. Are you going to release any of the details so those of us that are very curious can look at it?

    ReplyDelete
  10. Nice !
    Could you give the software as GPL open source software, for example on sourceforge.net ?

    ReplyDelete
  11. I would love to here more about the math behind the triangulation

    ReplyDelete
  12. I really want to know the END OF THE STORY!

    Did you successfully find hunters that were too close to your house?!

    ReplyDelete
  13. Yes so very interested in this project. I would love to use it to locate deer poachers in our area. Could you please let us see your code? I realize it's your hard work but let us sing your praises!!
    Let us know please.

    ReplyDelete
  14. I am curious too what the software and schematics look like ! Cool...

    ReplyDelete
  15. Very cool what you did. I saw a demo of ShotSpotter (www.shotspotter.com) which costs at least $300,000 US for a 2.1 square mile town. Their systems can tell the difference between calibre of weapon used and distinguish between fireworks, gunfire or other loud noise. However, many can't afford $300,000+ and your system could certainly fill that void.

    ReplyDelete
  16. Kripthor, this is a very cool project. We have developed and designed a complete gunshot detection and localisation product from scratch (fully arduino based) to address the current poaching problem here in South Africa. The entire system does the detection and gunshot signature verification and also the localisation within 10 meters of the sound source over a 500m range. We are currently rolling out a Proof of Concept in one of the private game reserves in the Greater Kruger National Park area and it is already showing some success.

    ReplyDelete
    Replies
    1. That's awesome. Where can I read more about it?

      Delete
    2. Kripthor, Currently we only have a facebook page running, look for Echo GDL

      Delete
  17. There is a need for an acoustic triangulation system to operate at short distances (1,4m), to locate for removal coqui frogs here in Hawaii where they are an invasive alien specie. I am not an electronics person but it seems it should be possible. Are there any projects out there that could do this? Or thoughts on the possibilities? The frog calls are very loud but confusing to locate as there can be several in an area and they hide in vegetation . Presently, I am working with my ears but three must be better way.

    ReplyDelete
    Replies
    1. Check out this paper:

      http://wildlifeacoustics.com/images/pdfs/2012MEEArraysOF.pdf

      Wildlife Acoustics is the company producing the hardware. One analysis approach is described in this paper:

      http://www.cs.mun.ca/~dwilson/david/Publications_files/Wilson%20et%20al%202014%20Bioacoustics.pdf'

      But as this blog points out, there are many solutions

      Delete
  18. Pardon the misspelling and missing characters in my previous comment. For some reason, editing in this page seems problematic.

    ReplyDelete
  19. Release some details so that we can build our own? Please??!

    ReplyDelete
  20. Hi folks!
    Due to several requests and incentives I decided to revisit MicLoc and I'm currently working on another prototype. This time, however, I will be documenting the process and releasing all software and hardware plans. You can follow the project here: http://ruralhacker.blogspot.pt/p/micloc.html

    My thanks to everyone that showed interest/commented/suggested upgrades!

    ReplyDelete
  21. Agilestorelocator.com is the professional in wordpress plugin and store locator wordpress. Here is also options available for the Location finder WordPress.

    ReplyDelete
  22. does it just do signal thresholding? a gunshot detector as an early warning would be a very cool project -- it could be used in american schools. wouldn't even need triangulation but having multiple devices to verify the sound (and cut out car backfires, clapping, etc.) would be useful. if the audio signal could be transmitted from the source to a raspberry pi (or PC), the pi could do the analysis (FFT, etc.). any thoughts? the nordic nRF24LE1 can do 1 or 2Mbps at 2.4Ghz. the range isn't great at that data rate. WiFi is better and the ESP8266 costs $3, has a uP faster than an arduino, with more RAM & flash. it can be a wifi client AND a server.

    thoughts?

    ReplyDelete
  23. I’m a technical computing student from the University of Applied Sciences in Amsterdam. For my internship I started a new project. What I want to do is to localize a sound source and let a drone fly to it. For this I want to use a room (5 by 6 meters) and to place 4 microphones in every corner of the room, since you wrote that the accuracy was way better if you place the microphones far away from each other. With TDOA (Time Difference Of Arrival) I want to calculate where the sound came from and determine a location for the drone. Do you think that this idea is possible to obtain and is your solution usable for my project? Do you maybe have any suggestions for me?

    ReplyDelete
  24. He is no scam, I tested him and he delivered a good job, he helped me settle bank loans, helped my son to increase his grades at high school final year and he also gave him automatic scholarship into college, all i had to do was to settle the bills for tools on the job and gave him the necessary information and he did the rest, I  was hopeless before not knowing what to do but thanks to brillianthckers800@gmail.com I am now a happy man free from troubles, sharing this is how I can show gratitude for all he has done for me and my family.

    ReplyDelete