Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to record in to matlab using two microphones simultaneously?

  1. Jun 8, 2012 #1
    I’m working on a project to make a sound source locator. My theory is to detect the sound using two microphone located at a known distance and find out the time delay to make out the direction of the sound.
    I am using matlab to take input from the microphone.
    To take input from two microphones, I used two laptops.
    I need the recording to start automatically, so I used Internet time synchronisation in both the laptops and then wrote a code in matlab to start the recording at a specified time.
    But the problem is that, the internet time synch is not accurate enough. I need something like millisecond precision.
    That’s not happening with internet time synch.
    Any solutions to any part of the problem?
  2. jcsd
  3. Jun 8, 2012 #2


    User Avatar
    Science Advisor

    Hey sudevschiz and welcome to the forums.

    The one thing I can recommend is to check what network protocol you are using and also don't use the internet if you don't have to: use a LAN cable and connect it directly to both computers (you will need to use a special LAN cable and not the same one you use for connecting to a router for example).

    So use a LAN cable and look into something like UDP over the reliable TCP/IP if you need more speed since the LAN will provide a high degree of reliability which means UDP should be good to use.
  4. Jun 9, 2012 #3


    User Avatar
    Science Advisor
    Gold Member

    A regular PC running windows won't be accurate to better than a few ms at best (1 ms if you are lucky). If you need to sync to 1 ms you need a real-time OS, OR a hardware solution of some sort. There are professional solutions for "distributed" recording but they are very expensive.

    This would be an easy problem to solve if the computers can be connected to cables (just record a common sync signal and use that to sync the signals in post-processing)?
    If not, you need some sort of external hardware.

  5. Jun 9, 2012 #4
    I found somewhere in the internet that it's possible to make another laptop in a network with the time of my laptop by announcing myself as the time server.

    Anybody has any idea about that?

    Or should I think about jumping in to the next step and working with a micro controller which can take multiple inputs from two microphone?

    Do you think a micro controller can provide me the accuracy required?
    If yes, which one?

    Is it a good idea to move on to the hardware level without confirming the theory I have?
    Last edited: Jun 9, 2012
  6. Jun 11, 2012 #5


    User Avatar
    Science Advisor
    Gold Member

    You need to figure out exactly what you want to do.

    Using a microcontroller would be difficult, and it would not necessarily solve the main problem which is that it is difficult (but not impossible) to accurately sync over a standard network.
    You might as well just install a real-time OS on your two laptops.

    There are already frameworks for accurate syncing over networks, in particular IEEE Standard 1588 which -I believe- should let you sync two events with microsecond accuracy if you use real-time targets and an external 1MHz oscillator as a reference (at least this is what Labview claims to be able to do which uses said framework).

    But again, this would be an easy problem to solve if you could just connect your two laptops using a cable ( a standard coax-cable would on). Then you could just use a common sync signal (which could even be generated by the soundcard on one of the laptops). You could then do a stereo-recording, with the mic connected to e.g. the left channel and the sync signal to the right.
    Aligning the signals in post-processing would be easy.
  7. Jun 23, 2012 #6
    I used to work at Autec in the Bahamas and we used hydrophones all over TOTO, on the bottom in patterns and hanging vertically. They picked up pings from torpedo's and such and the old computers of the day had no trouble tracking them in real time, well real time minus the time of flight of the sound but all the signals of all those hydrophones were digitized and sent over microwave to the main site where a computer with all the power of a commodore 64 generated 3D information as to the location of the torpedo being tracked and then plotted on 3 separate plot boards, XY in one, like looking down at the top of a fishtank, then XZ, like looking at one side and YZ looking at the other side, you could figure out just where the torpedo was very quickly.

    I imagine things have gotten a whole lot faster now with modern computers and such and probably much higher bandwidth links, maybe even fiber optic by now.

    Why can't you have a variable delay in one sound track and carefully adjust that to sync sound sources? For instance, you can use one of those child's toy clickers to send out a pulse that would bounce off walls and such and one click propagation would arrive at a mic before the other depending on where the mics were placed. Send me an email to dnphoton@ptd.net as I have a similar project but with different aims, maybe we could help each other. Name here is Don.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook