Firing Lasers at Ghosts

Back in the day I always wanted to send the Ghost Hunters TV show a device and see it used on TV. I didn’t want compensation or credit, I just wanted to see something I made on a TV show. One of these devices I thought of was to be left unattended with audio/video equipment and would identify the source of sounds recorded by detecting them, working out their source and then aiming and firing lasers at them!

I mentioned this recently in a passing conversation and realized that this idea has sat in the Bone Yard for far too long so I dusted it off.  The first challenge was to determine the mathematics to triangulate (translaterate) the source of the signal from positioned microphones. I significantly underestimated the complexity of this. I would have bet anything that this was simple trigonometry problem but after actually thinking through it and studying other sources on approaches used commercially I realized it really was not. The problem in fact boils down finding the “best” intersection point between four 3D hyperbolic surfaces. This requires mathematics well beyond anything I was intending to program on a microcontroller, yikes!

I ultimately came up with a satisfactory way to solve this problem algorithmically and that was very satisfying. If you care to understand that approach, here it is, if not, skip on!

My intention here is to find a way to spatially separate 4 microphones, record the time at which each registers a sound and from this determine the originating source.  In order to do this I need to find a generalized formula for the location of the originating sound with respect to the microphones.

Let’s start with a single microphone that we will define as A with coordinates, Ax Ay and Az. Let’s set this microphone at the origin (0,0,0). Let’s set a second, B, at (1,0,0). Let’s set a third, C, at (1/2, sqrt(3)/2, 0). Finally let’s set a fourth, D, at (1/2, sqrt(3)/4, 1- sqrt(3)/4). These points define a tetrahedron where the distance between each vertice is 1.

regular-tetrahedron-and-face_0

Let’s define the unknown source of the target sound as point P and describe its position with respect to A, B, C and D.  Let us assume that the distance between P and each microphone are known values so that we can say if a P lies a distance AP from A then its possible position is described by a sphere about A with a radius AP.  If we do this for each of the points, the common intersection of these spheres is the point P.  Here are the equations for the three spheres based on the positions we have ascribed to points A, B and C earlier (we are going to hold D for a special case for later discussion):

2018-08-12 09_13_40-Untitled 1 - OpenOffice Math.png

Since  AP, BP and CP are known values we can solve for Px, Py and Pz.

The first two equations can be rearranged allowing them to be substituted and isolate Px as such:

2018-08-12 09_30_32-Untitled 1 - OpenOffice Math.png

Now knowing Px, the first and third equations can be rearranged allowing them to be substituted and isolate Py as such:

2018-08-12 09_41_10-Untitled 1 - OpenOffice Math

Finally, now knowing Px and Py, we can simply solve for Pz from the first equation:

2018-08-12 09_48_56-Untitled 1 - OpenOffice Math

But what are AP, BP and CP?

Well, this is where I took a more code-friendly algorithmic rather than analytic approach to solve this problem which is a nice way of saying that “I guess”!  (good guesses though!).   Since we know the time difference of arrival to the mics we can say something about the difference in the lengths of AP, BP, CP and DP.  If the sound is first detected at A and then a moment later at B we can use the time difference and the speed of sound to determine how much further away B is from P than A.  Perhaps we determine the time difference at B equates to 1m, the difference recorded at C is 2m and at D it is 3m.  We could then say:  AP=?, BP=AP+1, CP=AP+2, DP =AP+3.  This along with the formulas for Px, Py and Pz set us up to guess at AP and use DP to test the accuracy of the guess.  The code very quickly tries values for AP in 1cm increments from 0m to 10m.  These guesses for AP yield us BP and CP that can be plugged in to get us Px, Py and Pz we derived above.  Then I simply see how close the distance from D(Dx,Dy,Dz) to P(Px,Py,Pz) is that comes out of the equations is to DP based on the guess (DP=AP+3 in our example).  The guess that provided the solution that is closest is selected as the best match.  Remember, this solution satisfies the time difference of arrival for A, B and C which yields a position Px,Py,Pz from the equations that then when measured against D in terms of distance agrees with the time difference of arrival for D.

And so with the math resolved I designed and built the circuitry.  I encountered a number technical problems, too many to mention, but after a couple of weeks here is the rats nest I built:

20180819_130312.jpg

The conceptual architecture is as follows:

2018-08-12 18_44_18-Untitled 4 - OpenOffice Draw.png

The four mics are fed through an amplifier, initially one I built but landed on using mics with on-board amplifiers.  These signals are then fed into a comparator with a potentiometer to control the threshold for the signal to trip a detection.  The detection is latched in the RS latch monitored by pins setup as interrupts in the MCU.  All interaction between the 3.3v MCU and 5v ICs are done through a bidirectional level shifter.  The MCU controls 5v servos with 3.3v PWM pins and a simple signal diode for switching the lasers.

Here is a schematic of the circuitry:

Schematic_Ghost-Laser_Sheet-1_20180819114439.png

The MCU pseudocode is as follows:  I setup an interrupt for each of the latch pins that upon firing increment a detection counter and record the internal microsecond time.  The main loop inspects the detection counter, if greater than 0 it begins a timeout counter.  If the timeout is reached before all four mics have triggered it resets.  If though all four are triggered it subs out to calculate the location using the math/logic described earlier.  Next it subs out to calculate the servo positions to aim the servos at the source, move the servos and fire the laser before resetting and resuming the the main loop.  The reset incorporates logic to wait for quiet before proceeding.

Here is a link to the full source code: https://create.arduino.cc/editor/rosolam/4198d587-5399-48c7-9c56-4c20a84d8956/preview

And finally here is a video of it in action!   At the time of the video I only had one laser hooked up but it is designed to have two lasers such that they intersect at the source.

Last step is to get a custom printed PCB and make this a finished device.  First time I’ve ever done that so I suspect I have a bit to learn on proper traces, but this is how I layed it out and board is being manufactured in China now…

2018-08-21 09_38_19-EasyEDA - A Simple and Powerful Electronic Circuit Design Tool.png2018-08-21 09_40_55-EasyEDA - A Simple and Powerful Electronic Circuit Design Tool.png

Here are a couple more parting pics:

Close-up of the laser arm showing the two-servo assembly controlling yaw and pitch with the laser wrapped in electrical tape and jammed in the end. 20180819_130248

Here was was a VERY satisfying result early on that made me put my hands up in the air in silent victory showing the correlation between the speed of sound for a known distance, the calculation in microseconds in code (circled on left) and a triggered oscilloscope reading showing the timing of the latch circuits (circled in lower right) popping for the two mics (one blue, one red) in question !  zomg, so hawt!

Capture.PNG

Here is another good oscilloscope shot showing the mic response (blue) and the latch (orange) firing off just as that sound breaks the detection threshold:

20180806_123236.jpg

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.