tags:

views:

302

answers:

3

I'm trying to build a gadget that detects pistol shots using Android. It's a part of a training aid for pistol shooters that tells how the shots are distributed in time and I use a HTC Tattoo for testing.

I use the MediaRecorder and its getMaxAmplitude method to get the highest amplitude during the last 1/100 s but it does not work as expected; speech gives me values from getMaxAmplitude in the range from 0 to about 25000 while the pistol shots (or shouting!) only reaches about 15000. With a sampling frequency of 8kHz there should be some samples with considerably high level.

Anyone who knows how these things work? Are there filters that are applied before registering the max amplitude. If so, is it hardware or software?

Thanks, /George

A: 

It seems there's an AGC (Automatic Gain Control) filter in place. You should also be able to identify the shot by its frequency characteristics. I would expect it to show up across most of the audible spectrum, but get a spectrum analyzer (there are a few on the app market, like SpectralView) and try identifying the event by its frequency "signature" and amplitude. If you clap your hands what do you get for max amplitude? You could also try covering the phone with something to muffle the sound like a few layers of cloth

Brad Hein
Shouting and clapping hands are also dampened so you're probably right about the AGC. But will it kick that quickly? The getMaxAmplitude seemed like a good shortcut to avoid doing the spectrum analysis... Thanks!
George
A: 

It seems like AGC is in the media recorder. When I use AudioRecord I can detect shots using the amplitude even though it sometimes reacts on sounds other than shots. This is not a problem since the shooter usually doesn't make any other noise while shooting. But I will do some FFT too to get it perfect :-)

George
A: 

Sounds like you figured out your agc problem. One further suggestion: I'm not sure the FFT is the right tool for the job. You might have better detection and lower CPU use with a sliding power estimator.

e.g. signal => square => moving average => peak detection

All of the above can be implemented very efficiently using fixed point math, which fits well with mobile android platforms.

You can find more info by searching for "Parseval's Theorem" and "CIC filter" (cascaded integrator comb)

Mark Borgerding