This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Get amplitude (dB) from PDM

Hi,

for my sound application, I want to get the amplitude, or dB, of the PDM samples.

Are there any existing function implemented? If not, how can I code it on my own?

I already read about PDM. Is it true, that I only need to count the ones in a row? (as shown in the picture in devzone.nordicsemi.com/.../)

Thanks!

  • Hi David,

    are you using, or planning to use, the nRF52 PDM peripheral functionality? (It is possible to sample a PDM signal using for example SPI or I2S, but this is not the typical approach)

    When using the PDM peripheral, the nRF52 will in hardware convert the 1-bit PDM samples to 16-bit PCM. Your firmware will never see the original PDM signal, only the resulting 16-bit PCM. Calculating the amplitude of a PCM signal is more straight-forward.

    As the resulting PCM is a digital signal with a range of [-32767, 32767] (16-bit signed values) you would typically use decibel relative to full scale (dBFS) for the amplitude: amplitude = 20 * log10(abs(sample) / 32767) dBFS

    To answer your specific question: No, I don't believe you can determine the amplitude by counting the ones in the PDM signal. At the very least you would have to count the number and width of pulses. However, note that PDM is a sigma-delta modulated signal which includes a lot of high frequency quantization noise. Estimating the amplitude from this signal without low-pass filtering means you will include this noise in the estimate, which is probably not desirable.

    Audun

  • Hi! yeah, I'm using the nRF52 PDM peripheral (I use a thingy:52 device) and a customized FW (original). There I get a PDM buffer provided (here)

    So I have to convert the PDM signal to PCM and use this one for further use?

  • Thanks for the details! In this code you have the PCM available directly. There is no need to consider that the audio was originally in PDM format.

    In drv_mic.c, m_audio_buffer_handler() is executed in interrupt context. To avoid blocking the interrupt with time-consuming audio processing, the audio buffer (p_buffer) is passed on to m_audio_process() via app_scheduler.

    I recommend doing your amplitude calculations in m_audio_process(). The pdm_buf_t typed variable in m_audio_process() does contain PCM, although the naming could have been more clear.

  • Oh, now it is all clear. The naming of the variables are kind of confusing. Thank you very much for the information.

Related