# What are the step by step actions taken in order to convert PDM data to PCM data?

I would like to convert PDM (Pulse Density Modulation) microphone data into PCM (Pulse Code Modulation) data. I understand that there are 2 steps in this process.

1. application of a low pass filter on the PDM data stream of binary pulses
2. decimation process to reduce the sample rate to the desired PCM data rate
3. encode the values between 0 and 1 into words of eg 16-bit?

Can someone expand on how these 2 steps are implemented (eg pseudo-code)? Or, is it that the main steps are different in order to produce PCM words of the signal intensity over time?

For 1. (if correct) what type of filter is applied and how is it implemented?

For 2. when 'downsampling', is it correct to pass through the data collecting only every Nth sample to get the required bit rate (eg 48KHz) from a faster sample rate (eg 1MHz)? Do we also apply a low pass filter after downsampling (same filter as 1. or different filter)?

For 3. are the words produced from the floating point values between 0 and 1 found in the previous steps?

• Your 3 makes no sense – after low-pass filtering, the signal can't be binary anymore, and even moreso after decimation. Commented Feb 27, 2023 at 21:08
• @MarcusMüller, would the value not be between 1 and 0? so that 0.5 maps to ~32,000?
– Vass
Commented Feb 27, 2023 at 21:29
• @MarcusMüller , i think that the OP means that the value will be between 0 and 1 after LPF. So this PDM maps 0% duty cycle to 0 (instead of -1) and 100% duty cycle to 1. Commented Feb 27, 2023 at 21:30
• So Vass, can you confirm that the data is inherently uni-polar, not bipolar (which might be from -1 to +1)? Commented Feb 27, 2023 at 21:31
• @robertbristow-johnson, yes that is correct, between zero and +1 (not -1 to +1)
– Vass
Commented Feb 27, 2023 at 21:40

Here is good intro into the topic. https://www.youtube.com/watch?v=5lH-tQw0tlU

The exact details will depend on the specific microphone, processor and application requirements. Many processors these days do have libraries or direct hardware support for PDM to PCM conversion. It's also a good idea to carefully read the data sheet of the microphone that you are using.

For 1. (if correct) what type of filter is applied and how is it implemented?

It's an FIR lowpass filter. Since the input is binary the filtering operation is simply a conditional sum of the filter coefficients. This can easily be done in fixed points and there are no multiplications required.

The design of the filter depends on your specific hardware and application requirements.

For 2. when 'downsampling', is it correct to pass through the data collecting only every Nth sample to get the required bit rate (eg 48KHz) from a faster sample rate (eg 1MHz)?

Sort of. You only calculate the lowpass filter for the samples you actually need. So you run the lowpass filters at the decimated rated advancing the input stream by the decimation factor each time.

Do we also apply a low pass filter after downsampling (same filter as 1. or different filter)?

No. You need a high pass filter to get rid of the DC offset.

For 3. are the words produced from the floating point values between 0 and 1 found in the previous steps?

The output of the process is in the same format as your FIR coefficients are. This will typically be 16-bit, 24-bit or 32-bit integers. You can convert them to whatever format your application needs. You could certainly do this in floating point but there is no benefit and likely to require more resources.

• run the lowpass filters at the decimated rated advancing the input stream by the decimation factor each time. how does that work, can you please expand with the steps taken? "You could certainly do this in floating point but there is no benefit and likely to require more resources." is it not easier to manipulate the data once in floating point for eg FFT?
– Vass
Commented Feb 28, 2023 at 2:00
• You don't need an FFT for PDM to PCM conversion. Fixed vs floating depends on what you want to do with the PCM data after the conversion. Floating is easier but also more expensive. Commented Feb 28, 2023 at 5:39
• on the device that directly interaces with the PDM stream, it's kind of likely that a fixed-point FFT would be easier and faster than a floating point FFT, unless it's a dedicated DSP chip. The algorithm class "FFT" has very little to do with whether your numbers are fixed or floating point – it's just that on PC-style hardware, the floating point units and FP SIMD instructions are typically as good, if not more powerful, than the fixed point ones. But your PC's CPU typically has no input to which you could directly connect a PDM microphone. You need that PDM to be converted by something else. Commented Feb 28, 2023 at 9:36
• (and from personal experience I can tell you that the operation "copy samples from a USB or network packet into my signal processing architecture" is about as fast as "take a bunch of fixed-point samples from an arbitrary packet and write them to my signal processing input buffer, converting it to floating point on the way" in practice. You can saturate your memory interfaces that way.) Commented Feb 28, 2023 at 9:40