[Back to Home Page]


Sonic ranging and locating - small scale
An experiment in locating a sound source using multiple sensors and "speed of sound" triangulation. - 19th April 2013.

The experiment

This is a simple experiment using two identical sound sensors (electret microphones) to test how easy it is to find the position of a sound on a very small scale (like on a keyboard sized platform) using sonic triangulation based on the speed of sound.

Ideally, this could be used to make something like a keyboard where there is a flat plate engraved with "buttons" surrounded by some cheap microphones, and based on sonic time of flight the PIC knows which "button" you tapped on the plate.

Above you can see the test setup which is just a piece of clear plastic with two cheap electret microphones glued to it. The mic's are identical, taken from a bag of 10 mic's.

The two mic's were powered from regulated +5v DC via two 10k resistors. The output of the two mic's was sent directly (no amplification) to a dual-trace 'scope, with yellow and green traces.

The plastic bar only serves to hold the mic's in a secure position, and is sonically decoupled from the wooden table by two pieces of soft grey foam.

Theory 1 (failed)

Well my first theory was that I could tap with my fingernail at different points along the plastic bar, and the position would be able to be calculated from the time of arrival of sound at the two mic's.

This was a failure. The mic's pick up sound via two paths, some transmitted through the plastic, some transmitted through the air. The speed of sound is different through each path. The two paths conflict and cause sound phase differences as well as speed of sound time delay differences, so it's not easy to get a good positional reading!

With different sound sensors, ones that ONLY pick up the sound transmitted through the plastic bar, this should be workable. But since I don't have any sensors like that handy, it was time to play with theory 2... :)

Theory 2 (success)

My second theory was that it should be very easy to get good sonic events at the two microphones if the "fingernail tap" was on a nearby surface, like the wooden benchtop. As the mic's are mounted on soft foam they are sonically decoupled from the table so they only pick up the sound that travels through the air.

Excellent! Now the two received sound waveforms are in phase, and are only displaced in time by the sonic time of flight (distance between the sound source and each sensor).

So if the position "A" on the table is tapped with a fingernail, it makes a sonic pulse which is received through the air by both microphones. Because there are two different distances there will be a time difference from when they each receive the sound.

The difference in the received sound timings is caused by the distance "X" (seen below in pink), which is the DIFFERENCE between the two distances. The smaller distance (blue) cannot be detected and is negated in testing.

This is all normal triangulation time of flight theory, you can google for more info if you like. My goal here was to see how well this worked on a very small (keyboard sized) scale, and to see how cheaply and simply it could be implemented using hobby level materials.

I tapped point "A" and recorded the result on the 'scope, see below;

The sonic pulse produces a nice downward energy pulse at each microphone. Signal strength was great, the pulse was between about 200-500 mV even with no amplification. It would be very easy to amplify this 20-50 times with a single opamp for each mic, and the outputs would drive two PIC digital inputs directly.

The sonic time of flight difference "X" is clearly visible, at about 350 uS. That matches my measured distance "X" reasonably well. Yay! :)

Next I tapped the point "B" on the benchtop, and recorded the result;

Looks good. Again the fingernail "tap" causes an initial pressure pulse which comes out of the mic's as a solid downward pulse of electrical energy and again the time difference between microphones matches the distance "X" quite well.

What I found interesting was that after the initial plosive pulse of sound, the two waveforms become quite different. This is likely from the mic's picking up reflected sounds from the environment. For example the flat front of the 'scope was only about 300 mm away and facing toward the experiment. However it does look like the initial pulse (which is of high energy, and occurs before any reflections) is reliable to use for a simple detection system!

Then I tapped the point "C" on the benchtop;

As expected, there is practically no difference in the two distances that the sound travels, so the plosive pulses are now arriving at the same time at both mic's. Looks like proof of concept.

And the final proof is in the last two tap tests, seen below. Points "D" and "E" both behave exactly as expected, and mirror the results of tests "A" and "B" but of course now the green mic picks up the pulse first;

How well would this work?

Even the small cheap PICs are capable of detecting the difference in time between two digital inputs down to a few uS.

My five "workbench tap buttons" had a spacing of 50 mm between them, which gave at least 150uS difference between buttons. If we assume a similar setup with 150uS per 50mm that means "PC keyboard" sized buttons of 18mm would give about 54uS difference between each button. And 54uS is a LOT of time to a microcontroller!

I believe it would be workable even with a small cheap PIC to reliably detect buttons that size. With two mic's this could be workable for a single row of buttons like a Xylophone or Piano style keyboard. And with 3 or 4 mic's it could be workable for something like a Keypad or even a Typewriter keyboard.

Implementing it on a cheap PIC

Using the PIC's internal comparators?
If you don't mind tapping reasonably hard on the surface, this seems quite workable even without input opamps. Many PICs have 2 comparators built in, so they could be biased with trimpots to have a threshold just below the mic DC output, and the comparators would trigger easily on the 200-500 mV downward pulse (see 'scope images above).

Using an opamp for each microphone.
If wanting to detect quiet/gentle taps on the surface it would be best to use an opamp for each mic. Gentle taps make a pulse of 100-200 mV, so an opamp with a gain of about 50 or more would be biased just off, and a pulse would cause its output to move through a digital transition, ie from 5v to 0v. That could be detected on any PIC digital input pin, like the pins that have the "interrupt on pin change" feature.

Two mic's can be done with any dual opamp IC, or if using 3 or 4 mic's you could use two dual opamp IC's or a quad opamp IC.

The initial pulse energy seemed to be around 1.5 kHz on a wood surface and >2 kHz on a harder plastic surface (depends what material you choose for your keypad). A high pass filter before the opamp would eliminate most of the room noise, wind noise, mains hum and even the bulk of speech energy which is only a few hundred Hz.

Where to mount the microphones?

Assuming that you use cheap electret microphones like mine (and not some type of special contact-only mic) there is some chance of the mic picking up room noise or other random noise through the air.

So I tested tapping UNDERNEATH the workbench (mic's still on top), and the results were promising!

It should be possible to put the mic's under the surface, within a sealed area, and then "tap" on the top of the surface. That will eliminate a lot of problem airborne noise and still be quite sensitive to the main tap pulse. My workbench was 16mm thick wood and lost some sensitivity with through-tapping, but I think a properly set up plastic surface of say 3-6mm thickness would transmit sound through much better, especially if it was rubber mounted at its edges.

Getting around the nasty triangulation math

The math for finding a position along a single line with two microphones is not so bad, but if using triangulation on 3 or 4 mic's it gets pretty nasty, especially for a little 8-bit PIC micro with no floating point!

However, since the buttons and microphones are in fixed known locations, it should be possible to avoid triangulation math altogether and just use some simple timing comparisons.

If you look at the results from my line of 5 buttons, there are some very simple timing results;
Button A = +350uS
Button B = +200uS
Button C = 0uS
Button D = -200uS
Button E = -350uS

So the PIC does one simple signed calc; Xtime = (mic2time - mic1time) and then can determine which button is pressed from a few simple comparisons, just testing that one variable.

For a two dimensional array of buttons, with 3 or 4 mic's, you could simply use a lookup table to hold the values for comparison testing. It would still be fast and efficient checking two time readings against different buttons in a lookup table, and not require any floating point triangulation math.

Further simplification?

If the "tap buttons" are in a simple 2D array, some assumptions can be made. Below on the simple 2D keypad you can see from the pink lines that in the X axis, the middle column buttons (2,5,8,0) will always give very similar X timings (an X value of close to zero) because the middle buttons will always be an equal distance to each of the top mic's.

It should be easy to detect left column buttons (1,4,7,*) from the obvious -X timing (closer to the left mic), and right column buttons from the +X timing, and middle column timings will be close to an X timing of zero;

Likewise the Y timing differences follow a simple rule. The top six buttons will always return a -Y timing, and the bottom 6 buttons will always be a +Y timing. Also, the very top and bottom rows will have much greater Y timing differential than the middle two rows.

These type of simple rules might allow decoding of the 12 "keys" from a simple tree of comparisons, and could reduce (or even eliminate) the need for a lookup table.

Useful applications?

Well I'm not sure about useful applications, but there could be a lot of fun type applications;

Musical instruments.
Things like Xylophone and Piano type keyboards should be very easy to implement with just two microphones, and could offer benefits over traditional key contacts, like continuously variable position, and also offer amplitude as well as position if the average volume from the mic's is also decoded. Obviously this could allow totally new shapes and designs in electronic musical instruments.

Data entry keyboards.
If appearance is more important than usability, things like transparent glass keyboards etc could be made. Of course they would require "taps" on the keys, and only one key at a time could be tapped. It might be useful for a glamour keyboard in a hotel or restaurant etc.

Artistic control surfaces.
Because this can be used on any shaped surface made from any hard material, it could be used for artistic projects, things like fixed displays, walls, windows, or even wearable interactive art.

Fun security activation.
This could easily decode when someone knocks on different areas of a house door for example. So could be used for pattern knocks or secret knocks. As a more serious use it could make something like a vandal proof or weather proof keypad with the mic's safely behind the sealed hard keypad.

Interactive screens or coffee tables.
It might be a bit crude and rough to "tap" on a video screen, but some possibilites are there... Maybe with a glass plate over the screen? People like to make coffee tables with LED lighting systems inside, so this could allow a coffee table to become interactive by tapping anywhere on its surface.

Games or exercise equipment.
Needing to "tap" a surface might even be an advantage in some type of physical game, like a reaction time game on a large surface. Or some type of interactive exercise game.

Future improvements?

It would be great to experiment with material vibration sensors, so the sensors could be placed inside the material and still reliably decode the position the material was tapped. Those sensors would also be reasonably immune from room noise.

Maybe electret mic's could be glued inside the material in some way, or modified/disassembled to make them into contact mic's?

That could be worth doing as a future experiment. :)

- end -

[Back to Home Page]