2020-04-06 02:14 AM
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
Solved! Go to Solution.
2021-02-18 01:38 AM
Thank you Eleon, finally I can calculate dB from MEMS Mic. It's to calc 20*LOG10(%FS) and dBFS comes out.
Regards
Masaru
2020-04-06 03:41 AM
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):
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
2020-04-06 11:43 PM
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.
2020-04-07 02:52 AM
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
2020-04-08 11:00 PM
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
2020-04-10 02:49 AM
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
2021-02-18 01:38 AM
Thank you Eleon, finally I can calculate dB from MEMS Mic. It's to calc 20*LOG10(%FS) and dBFS comes out.
Regards
Masaru
2021-02-18 02:16 AM
Hi Masaru,
that of course... ;) I was focusing on a programming issue...
-Eleon
2024-08-27 08:55 AM
Hi, I am facing issue to interface STM32F446RE custom board with MP34DT05-A. This is the attached image of my schematics for mics.
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.