I was working on an audio classification project but recording audio at 44.1kHz. I set up my Impulse appropriately and trained the model and deployed it as an Arduino library and started working with the Nano 33 BLE Sense example code.
It was failing to start the PDM and I couldn’t figure out why until I peeked at the source of the nRF52x PDM implementation: ArduinoCore-nRF528x-mbedos/PDM.cpp at master · arduino/ArduinoCore-nRF528x-mbedos · GitHub
// configure the sample rate and channels
switch (sampleRate) {
case 16000:
NRF_PDM->RATIO = ((PDM_RATIO_RATIO_Ratio80 << PDM_RATIO_RATIO_Pos) & PDM_RATIO_RATIO_Msk);
nrf_pdm_clock_set(NRF_PDM_FREQ_1280K);
break;
case 41667:
nrf_pdm_clock_set(NRF_PDM_FREQ_2667K);
break;
default:
return 0; // unsupported
}
So it seems like only 16000Hz and 41667Hz are supported. Not sure of the reasoning behind this but I was able to get through this just by manually setting the PDM.begin() function to sample at 41667Hz, while leaving the RAW_SAMPLE_COUNT at 44100. It’s not ideal but I think it’s close enough to work fine.
Also, this isn’t anything major but I noticed the Arduino example code for audio inferencing seems to assume 16kHz sampling regardless of EI_CLASSIFIER_FREQUENCY. This causes the Sample length display to be wrong. The actual implementation is still faithful to the set frequency from the Impulse Design phase so it’s not really a problem though.
// summary of inferencing settings (from model_metadata.h)
ei_printf("Inferencing settings:\n");
ei_printf("\tInterval: %.2f ms.\n", (float)EI_CLASSIFIER_INTERVAL_MS);
ei_printf("\tFrame size: %d\n", EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE);
ei_printf("\tSample length: %d ms.\n", EI_CLASSIFIER_RAW_SAMPLE_COUNT / 16);
Just sharing the experience in case anyone else encounters a similar situation or if anyone knows more about the PDM implementation logic.