What type of data is producing by mic_energy?

I’m trying to have the mic_energy file within the hal package and convert the data into decibel levels of the sound data it’s reading.

This is the part of the code that I’m looking at (https://github.com/matrix-io/matrix-creator-hal/blob/master/demos/mic_energy.cpp) for lines 46-59:

while (true) {
mics.Read(); /* Reading 8-mics buffer from de FPGA */
instantE = 0;
for (uint32_t s = 0; s < mics.NumberOfSamples(); s++) {
instantE = instantE + (mics.At(s, 0)) * (mics.At(s, 0));

localAverage[j % 20] = instantE;
avgEnergy = 0;
for (auto& data : localAverage) {
  avgEnergy = (avgEnergy + data);

avgEnergy = avgEnergy / 20;

I’m not sure what sort of data is being read by the microphones or what type of data is producing. I have to covert those data into dB.

Hi @rameelhashmi ,

I Googled around a bit and it seems you should be able to convert to dB from the buffer of relative mic samples using a method like in this thread which explains a simple calculation and the idea behind it. Our buffer samples are int_16 types so the same logic should apply.

I’m not sure if you need real-time conversion to dB but if you drag wav/raw files created using MATRIX HAL or ALSA into Audacity, it will usually be able to give you a dB graph that you can use for comparison at the very least.

I’ll continue to look into it and see if I can find any helpful information but let me know if the thread helps!