Wednesday, February 10, 2010

Part 2-a: Developing A Gunshot Detection Interface

Now that you've had time to look over the general concepts of Project: Smoke & Hope, it's time to roll-up our sleeves and dig into the finer details. A good place to start (in my mind) is with detecting a gunshot, because without this, there is no project.

When I first started thinking about detecting a gunshot, the initial thing into my mind was a microphone of some sort. I didn't take long for me to rule this type of sensor out, because I anticipated too many complications. For instance:
  • It is easy for a human to make a noise loud enough to overpower a common microphone (cause clipping in audio).
  • Microphones are expensive. A nice microphone costs a lot and is a sensitive piece of equipment, usually because they are used to detect and replicate a wide range of frequencies.
  • I don't need to detect frequency. Since I am only looking for "very loud" sounds, I don't really care what frequency they occur at.
  • Signal Processing is intensive. Two issues here: (1) I don't have the equipment to accurately profile the acoustical characteristics of a gunshot, (2) there is a large amount of overhead for the hardware in order to constantly measure the amplitude of a sound wave.
My desired input would be a single line (or bit) input to my board, that I would treat as an interrupt signal (meaning that an active logic level would signify a gunshot). With this in mind, I went searching for a sensor that I could build into my own circuit. After about a week of research, I found what I needed.

Piezoelectric Transducers:
A piezoelectric Transducer (piezo for short) is a crystal with a very special property. When pressure is applied (distorting the physical shape), the crystal will produce a variance in electrical potential (voltage). In simplified terms, when you hit the crystal, it causes the voltage to increase. A particularly interesting feature of the piezo, is that this process works backwards. Meaning, if a voltage potential is applied to the crystal it will vibrate at some frequency. This is very useful, as it is the technology that drives my buzzer.

Here is a link the piezoelectric transducer I used.


Application:
In order to take advantage of this sensor, I spent some time developing an amplifying circuit. Below is a picture of a basic Current to Voltage Amplifier / Converter that I implemented using an LM358P.

After amplifying the signal, it was rather noisy and oscillated between 0V to 3.3V, depending on the dB level detected. From here, I needed to condition the signal to be much smoother (in order to have time to detect the shot).

In order to do this, I connected the output of the OpAmp to the gate of a MOSFET (Metal Oxide Semi-Conductor, Field Effect Transistor). The source and drain of the MOSFET are connected to 0V and 3.3V, respectively. With a pull-up resistor on the output (creating a faster changing, active low, signal) and a capacitor tied to ground (smooths out the signal) I was able to create a signal that went low and stayed their until the sound was gone. For a better idea of how this works, see the following schematic below:


The following 4 pictures show the signals we've been discussing in more detail. The yellow line is the signal coming out of the OpAmp and the blue line is the signal after the MOSFET (notice how the signal has been converted to active low logic).

LEFT: Shows a good example of the oscillating signal out of the OpAmp.
RIGHT: Shows the output from the MOSFET with no conditioning (i.e. before I added the capacitor).


LEFT: Shows the time it takes for the capacitor to charge back up after the sound has stopped.
RIGHT:Shows what two, successive, shots would look like.


*NOTE: These waveforms are the product of lab testing. As I am not able to discharge a firearm in lab, these waveforms were generated by sharply striking the piezo (in attempt to replicate a concussive gunshot sound wave).

There you go, we are caught up with this particular interface! I am still waiting to have time to go to the shooting range with a scope and test this out better. I must sign off for now, as my Design Specification is due Friday (Don't worry, I should have it posted by Sunday for your reading pleasure).

2 comments:

  1. Hi, Chris! James from ShotSpotter here. This is a cool project! If you check out our website, you'll see that we have sensors that do a lot of what you just described (and then some :-). Provided this isn't for commercial purposes, I think we'd be willing to share some same gunfire audio so you can save yourself the trouble of firing a gun in your lab (VERY BAD IDEA, as you have already figured out :-). My email is jbeldock [at] shotspotter.com; give me a shout.

    ReplyDelete
  2. Oooh, pretty pictures!
    Actually, I do "get it"! :)
    and, mom is proud.
    (ok, no more of that mushy stuff)
    Frankly, I think the "testing" part sounds most fun! Keep it up!

    ReplyDelete