Skip to main content
ATeli.1
Associate III
December 27, 2022
Question

Conversion to PDM to PCM using FIR and decimation

  • December 27, 2022
  • 1 reply
  • 1777 views

I am trying to decimate a PDM signal in order to obtain a PCM signal. Is this code correct?

void LowPassFilterWithDecimation(uint8_t *pdm1, uint8_t *pdm2, int32_t *pcm1, int32_t *pcm2, int pdm_buffer_size, int decimation_factor){
 char str[100];
 
 // initialize buffers
 for(uint16_t i = 0; i < pdm_buffer_size/decimation_factor; i++){
 // initialize raw microphones buffers
 pcm1[i] = 0;
 pcm2[i] = 0;
 }
 
 for(uint16_t i = 0; i < pdm_buffer_size; i += decimation_factor){
 for(uint8_t j = 0; j < NUM_TAPS; j++){
 
 pcm1[i/decimation_factor] += pdm1[i + j] * fir_coeff[j];
 pcm2[i/decimation_factor] += pdm2[i + j] * fir_coeff[j];
 
 // trasmit via uart
 sprintf(str, "%ld,%ld\r\n", pcm1[i/decimation_factor], pcm2[i/decimation_factor]);
 HAL_UART_Transmit(&huart2, (uint8_t*)str, strlen(str), 10);
 
 }
 }
}

This topic has been closed for replies.

1 reply

PatrickF
Technical Moderator
January 4, 2023

Hi @ATeli.1​ ,

Please provide which STM32 your are using/targeting ?

I'm not an audio expert, but I think using DFSDM (or MDF) present on some STM32 MCU or MPU will make such conversion much simpler and faster as DFSDM embed digital filters in HW.

Regards.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.NEW ! Sidekick STM32 AI agent, see here