2022-12-27 08:18 AM
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);
}
}
}
2023-01-04 08:43 AM
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.