cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate dB from the mems microphone data?

marchalloakbow
Associate II

Hello all.

I would like to ask how to calculate dB from a data recorded by a MEMS microphone.

I currently use the MP34DT04 on the SensorTile Kit. I checked the SensorTile can record sound with the microphone, and store a wav data file in MicroSD.

In the .wav file, there are chunk of data and, of course, there are sound level data. Then, I would like to calculate dB data from the sound level data. How can I calculate?

If the sound level data is 16 bit, the data would be in between -32768 and 32768. Is the digit can be mapped to full scale sensitivity? The sensitivitiy means the parameter in the datasheet. In the case of the MP34DT04, the sensitivity is in the range of -26dB to 120 dB.

I also wonder what the description in the page 6 of the datasheet means. It says "Duty cycle: min = 40% max = 60%". Is it related to the dB calculation?

Please take care yourself first, and looking forward to the answers. 

Thanks in advance. 

Masaru

1 ACCEPTED SOLUTION

Accepted Solutions
marchalloakbow
Associate II

Thank you Eleon, finally I can calculate dB from MEMS Mic. It's to calc 20*LOG10(%FS) and dBFS comes out.

Regards

Masaru

View solution in original post

8 REPLIES 8
Eleon BORLINI
ST Employee

Hi @marchalloakbow​ , please find below my answer to your question. I start focusing on you sentence:

>> In the case of the MP34DT04, the sensitivity is in the range of -26dB to 120 dB.

The two values (-26 and 120) refers to different acoustic levels (see also AN4426 app note):

  • 120 is in dBSPL, meaning that the value refers to 0dBSPL, equals to 20 uPascal, the minimum audible signal from the human ear. 120dBSPL is almost the noise of a close jackhammer, and is the acoustic signal at which the MP34DT04 microphone begins to saturate (equally, its THD is above 10% -fully distorted signal- or the output digital PDM contains almost all '1' bits);
  • -26 dBFS is the microphone sensitivity at 94dBSPL. the FS in the "dBFS expression" is the microphone full scale, i.e. 120dSPL (acoustically) or all'1' PDM. As you know, the conversion formula for the amplitude is dBFS = 20*log(FS). You can think about the analog microphones (MP23ABS1), which sensitivity is expressed in dBV (referring to 1V, which is not quantitatively but conceptually the FS of the microphone). I suggest you to check your .wav file with the free but powerful tool Audacity, which is provided of the dB conversion embedded feature.

Ps: the ducy cycle doesn't affect microphone output sensitivity, because it is only a clock parameter, that is almost 50% for all ST MEMS digital microphones.

Be safe! Regards

marchalloakbow
Associate II

Hi Mr.Eleon.

Thank you for your quick response.

Your reply showed that I had a misunderstanding. What I took it wrong is the difference in sensitivity of an analog and a digital microphones. So, I thought my question could be rewritten as:

"If the sound pressure level of a wav file is 16 bits, does the lowest value and the highest value correspond to -120 to 0 dBFS?"

Is this Yes or No?

Thanks to the AN4426, I understand dBFS like this. The microphone "MP34DT04" which I use has a maximum level of 120dBSPL and a 64dB SNR. Therefore, the residual noise line in dBSPL is 30 dB(=94 dB - 64dB). Expressing this line dB in dBFS results in -90 dB.

What I want to know is, whether the 16-bit sound pressure level in the wav file corresponds to dBFS or not.

Thanks in advance again.

Masaru.

Eleon BORLINI
ST Employee

Hi Mr. Masaru,

>>"If the sound pressure level of a wav file is 16 bits, does the lowest value and the highest value correspond to -120 to 0 dBFS?"

Basically yes, but in linear scale: the Full Scale will be when the data value is h7FFF (on 16 bits, in two's complement). This is theoretically equivalent to 0 dBFS. The lower values are basically the 20*log(%FS/FS), or equivalently re-scaled for the 0dBFS factor. Moreover, there shouldn't be further software scale factors in the acquisition chain. So the 16bit data is the linear value of the multibit PCM (pulse code modulation) obtained by the PDM (the microphone output) decimation. This decimation depends on the mic clock (usually about 2.4MHz) and the down-sampling factor (usually about x32), resulting in a word length, or acquisition frequency, of 75kHz.

>> Therefore, the residual noise line in dBSPL is 30 dB(=94 dB - 64dB)

You are right, this parameter is called Equivalent Noise Input (EIN)

Regards

marchalloakbow
Associate II

Hello Mr.Eleon.

Thank you for your explanation. Now I understand that the FS of the data is theoretically equal to 0dBFS. And, 

>>the 16bit data is the linear value of the multibit PCM (pulse code modulation) obtained by the PDM (the microphone output) decimation. 

this is what I would like to confirm. So I think my question almost has been answered.

But I could not get the meaning of the lower value explanation. the point I didn't get is 

>>The lower values are basically the 20*log(%FS/FS), or equivalently re-scaled for the 0dBFS factor.

In the sentence, what log(%FS/FS) means? 

I should refer to some study for further understanding. Is it possible for you to recommend me any application notes or articles which describes such detail?

Regards

Masaru

Hi Masaru, the %FS is basically the PCM value with respect to the Full Scale (in Audacity, Full Scale is between +-1 and the signal is a percentage of this full scale, a value <1, except from the spikes that are clipped to 1). I suggest you the Audio Precision website, especially the section dedicated to the PDM to PCM conversion and MEMS microphones, and of course the ST site resources on MEMS microphones (tech notes, presentations). Regards

marchalloakbow
Associate II

Thank you Eleon, finally I can calculate dB from MEMS Mic. It's to calc 20*LOG10(%FS) and dBFS comes out.

Regards

Masaru

Hi Masaru,

that of course... ;) I was focusing on a programming issue...

-Eleon

FShah.1
Associate III

Hi, I am facing issue to interface STM32F446RE custom board with MP34DT05-A. This is the attached image of my schematics for mics. 

FShah1_0-1724773772485.png

I am using very simple code just to read the mics data and convert the PCM signals into dB levels.

static void MX_PDM2PCM_Init(void)

{

/*Enables and resets CRC-32 from STM32 HW */

__HAL_RCC_CRC_CLK_ENABLE();

CRC->CR = CRC_CR_RESET;

 

uint8_t index = 0;

for(index = 0; index < 1; index++)//for channel number #1

{

PDM_Filter_Handler[index].bit_order = PDM_FILTER_BIT_ORDER_LSB;

PDM_Filter_Handler[index].endianness = PDM_FILTER_ENDIANNESS_LE;//PDM_FILTER_ENDIANNESS_LE;

PDM_Filter_Handler[index].high_pass_tap = 2122358088;

PDM_Filter_Handler[index].out_ptr_channels = 1;

PDM_Filter_Handler[index].in_ptr_channels = 1;

PDM_Filter_Init((PDM_Filter_Handler_t *)(&PDM_Filter_Handler[index]));

 

PDM_Filter_Config[index].output_samples_number = 16;//16

PDM_Filter_Config[index].mic_gain = 24;//was 24

PDM_Filter_Config[index].decimation_factor = PDM_FILTER_DEC_FACTOR_64;

PDM_Filter_setConfig((PDM_Filter_Handler_t *)&PDM_Filter_Handler[index], &PDM_Filter_Config[index]);

}

 

}

void BSP_AUDIO_IN_TransferComplete_CallBack(void)

{

 

char audioData[50];

 

/* PDM to PCM data convert */

AUDIO_IN_PDMToPCM((uint16_t*)&InternalBuffer[INTERNAL_BUFF_SIZE/2], (uint16_t*)&RecBuf[0]);//0

 

for (int i=0; i<PCM_OUT_SIZE; i++){

sprintf(audioData, "%u\n", RecBuf[i]);

HAL_UART_Transmit(&huart1, (uint8_t *)audioData, strlen(audioData), HAL_MAX_DELAY);

}

 

}

 

uint8_t AUDIO_IN_PDMToPCM(uint16_t *PDMBuf, uint16_t *PCMBuf)

{

 

// uint16_t *PCMBuf[150];

uint16_t AppPDM[INTERNAL_BUFF_SIZE/2];

uint32_t ind = 0;

 

/* Set PDM data from LSB to MSB */

for(ind = 0; ind<INTERNAL_BUFF_SIZE/2; ind++)

{

AppPDM[ind] = HTONS(PDMBuf[ind]); //The macro HTONS(A) is used to convert a 16-bit unsigned integer

//from host byte order to network byte order.

}

 

 

for(ind = 0; ind < 1; ind++)//DEFAULT_AUDIO_IN_CHANNEL_NBR = 1 (means number of Mics)

{

/* PDM to PCM filter */

PDM_Filter((uint8_t*)&AppPDM[ind], (uint16_t*)&(PCMBuf[ind]), &PDM_Filter_Handler[ind]);

}

/* Duplicate samples since a single microphone is mounted on STM32F4-Discovery */

for(ind = 0; ind < PCM_OUT_SIZE; ind++)

{

PCMBuf[(ind<<1)+1] = PCMBuf[ind<<1];

}

 

/* Return AUDIO_OK when all operations are correctly done */

return HAL_OK;

}

 

I am using modified code from ST Discovery board example where the audio data is storing in buffer and playback using USB port.

 

Any help is highly appreciable. I am attaching received data file for your review. Any support is appreciable.