cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 and PDM2PCM filter (for PDM microphones)

tjaekel
Lead

I have some questions and remarks about the PDMFilter (used for PDM MICs).
I have it working fine on a Portenta H7. Almost all OK.

I have studied the UM2372 : STM32Cube PDM2PCM software library for the STM32F4/F7/H7 Series - User manual

Here are my questions:

1. Source Code:
Is there any chance to get the source code (GitHub) for this (new version of) filter implementation?

2. Filter implementation details:

OK, the current version is now using an IIR filter (OK, I understand maybe why: code size, speed, latency). The older version (not recommended and supported anymore), was based on FIR, I could still find here:
codec2_m4f/lib/PDM_filter at master · piratfm/codec2_m4f · GitHub

a) the IIR filter:
generates some artefacts (in spectrum, even documented in UM2372, e.g. a remarkable 3rd harmonics). I think to see that also other "side tones" are generated (OK).

The PDM2PCM filter is very sensitive for the right amplification setting (and with which amplitude the signal from PDM comes in). Obvious.
If you do something not really "right", e.g. too much amplification (gain) or a too strong signal, what happens (and I can "see" and hear):

  • the output signal starts clipping (it becomes a "rectangle")
  • and suddenly the filter starts with "self-oscillation": I assume, it starts already to generate "side tones" when it reaches a too high amplitude on output (IIR feeds it back)

All this is acceptable (and obvious), just: "maybe a 'better' " filter design is possible.

b) Please, may I get more details about the filter implementation:

  • Which order (how many taps) is this IIR filter? (what are the coefficients?)
  • Is it implemented by using floating point math (or based on ARM DSP with fix point)?
  • Is it using the HW FPU unit? (I do not think so, nothing mentioned to enable it)
  • Is it using Dithering (to handle Quantization Errors and rounding errors)?
  • Is there an AGC (I do not think so, but Windows via USB would add one - pay attention!)

Below some examples what I get (from a generated 1KHz PDM sine signal, fed into PDMFilter (not a real MIC signal, no MIC or a speaker involved, a "pure" PDM signal played from buffer - OK, it generates also "side tones").

So, even it works nice, I am thinking to implement my own PDMFilter (as FIR, with ARM DSP and Fix Point math, potentially using the HW FPU).
Or: does anybody has one already? (or if STM thinking to provide source code for one?)

PDMFilter_1a.png

PDMFilter_1b.png

PDMFilter_1c.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

I have now created my own FIR based PDM2PCM filter (based on ARM CMSIS DSP):
sounds better and makes a bit more sense, but potentially too slow (I hear discontinuities).

For implementing your own filter, here two helpful links:

https://www.keil.com/pack/doc/CMSIS/DSP/html/group__FIR__decimate.html 

http://t-filter.engineerjs.com/ 

Here some slides comparing the original (latest) STM PDM2PCM filter with my one:

PDMFilter_Compare_1.png

PDMFilter_Compare_2.png

PDMFilter_Compare_3.png

Conclusion:
Actually, the STM PDM2PCM filter is not bad (it has just still too much high frequency noise and distortion due to it). It sounds a bit sharp (harsh).

It might make sense to use this filter (in order to convert from PDM to PCM), but to add another low pass filter (with few taps) afterwards (in order to remove the still remaining high frequency noise).

My project (with my own filter) can be found here:

https://github.com/tjaekel/PortentaH7_WAcouSense 

View solution in original post

2 REPLIES 2
tjaekel
Lead

I found this great document: AN5795

https://www.st.com/resource/en/application_note/an5795-sound-capture-with-multifunction-digital-filter-on-stm32u5-series-stmicroelectronics.pdf

Exactly what I am looking for. For Portenta H7 (STM32H747) I had to implement in SW (as ARM CMSIS DSP). But for the STM32U5xx it is supported by HW. Very nice!

Luckily, I have a STM32U5A5 project and PCB working. So, I can give it a try on STM32U5.
What a cool MCU!

Question:
In AN5795 is mentioned, a comparison was done with an ARM DSP implementation.
Is there a chance to get the source code for SW implementation of the filter? Thank you.

I have now created my own FIR based PDM2PCM filter (based on ARM CMSIS DSP):
sounds better and makes a bit more sense, but potentially too slow (I hear discontinuities).

For implementing your own filter, here two helpful links:

https://www.keil.com/pack/doc/CMSIS/DSP/html/group__FIR__decimate.html 

http://t-filter.engineerjs.com/ 

Here some slides comparing the original (latest) STM PDM2PCM filter with my one:

PDMFilter_Compare_1.png

PDMFilter_Compare_2.png

PDMFilter_Compare_3.png

Conclusion:
Actually, the STM PDM2PCM filter is not bad (it has just still too much high frequency noise and distortion due to it). It sounds a bit sharp (harsh).

It might make sense to use this filter (in order to convert from PDM to PCM), but to add another low pass filter (with few taps) afterwards (in order to remove the still remaining high frequency noise).

My project (with my own filter) can be found here:

https://github.com/tjaekel/PortentaH7_WAcouSense