cancel
Showing results for 
Search instead for 
Did you mean: 

Conversion to PDM to PCM using FIR and decimation

ATeli.1
Associate III

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);
      
    }
  }
}

1 REPLY 1
PatrickF
ST Employee

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.