Search code examples
androidmicrophonedecibel

Getting decibel from an Android microphone


I have been searching for quite some time now, and I haven't been able to find a way to actually get an SPL/db value from a microphone on Android.

The few threads and articles that I have found that discussed it treated it like something so obvious that anyone should be able to do it, and were more concerned with getting their conversion algorithms correct.

Does anyone know how to do this?


Solution

  • You would have to first disable any automatic level control. I assume you either know, or know where to look to find out how to record samples from the microphone without ALC.

    From then on, its basically all about the calibration and log magnitude. Essentially you will multiply or convolve by a frequency-dependent calibration and then take 10 * the log magnitude over all or some of the frequency range.

    Then you'd have to take some calibration measurements, for example frequency sweeping a lab source of controlled, known spl and recording the resulting amplitude vs frequency (which if you sweep slowly is essentially the same as amplitude vs. time) or you'd hit it with a wideband pseudo impulse (such as an electric spark, starter pistol, whatever) that you are also measuring across frequency with good lab equipment in a radiation-symmetric position, or as a last resort you use some known physical property of the source to estimate the SPL and just hope it's flat enough across frequencies of interest.

    You then have two choices for how to apply the correction.

    One option is to invert the transfer function, calculate the time domain impulse response, and then use that as a digital filter by convolving it with an input signal to apply a frequency-flatness-correction. You can then take the log magnitude of the result per unit time to determine wideband spl.

    Or you can do an FFT on the input data to generate a frequency spectrum, and multiply that by the inverse of your frequency response, and take the log magnitude of whatever (sum of) bin(s) is interesting.

    Unfortunately, there's little reason to assume more than crude consistency from device to device, even of the same model.