Design of a MultiStage PDM to PCM Decimation Pipeline
 Introduction
 The Design Requirements
 The Canonical MultiStage Decimation Pipeline
 Pass Band Ripple, Stop Band Attenuation and MultiStage Decimation
 CIC Filter Configuration and Pass Band Ripple
 CIC Filter Configuration and AntiAliasing Performance
 Final CIC Filter Configuration
 Design of the HalfBand and Generic FIR Filters
 Coming Up
 References
Introduction
In the past 5 episodes of this series, I discussed sigmadelta converters, how to read the datasheet of a microphone, different types of filters, and how to come up with the right coefficients of these filters.
Finally, it’s time to bring all the pieces together and create a full signal processing pipeline to convert the output of a PDM microphone into standard PCM samples.
The Design Requirements
Let’s quickly repeat the overall design requirements that I came up with in a previous blog post:
 PDM input sample rate: 2.304MHz

PCM output sample rate: 48kHz
In other words, a decimation ratio of 48.
 Pass band: 0 to 6kHz
 Stop band: 10kHz
 Pass band ripple: 0.1dB
 Stop band attenuation: 89dB
The Canonical MultiStage Decimation Pipeline
There is an overwhelming amount of literature out there about the pipeline to decimate an incoming signal at very high sample rate down to something much lower. And while there are an almost infinite amount of subtle variations, the fundamentals can almost always be reduced to the following basic building blocks:
 a CIC filter at the front
 one or more halfband filters in the middle
 a generic FIR filter in the back
The reason for this arrangement is obvious when you consider typical design constraints such as clock speeds and resource usage.
 A CIC filter only requires adders and delay stages, but no multipliers. This makes them extremely area efficient.
 The lack of multipliers also makes it easier to run CIC filters at high clock speeds.
 A halfband filter requires only around 50% of the multiplications of an equivalent generic FIR filter. This reduction is at all times large enough to overcome the inefficiency of splitting a larger generic FIR filter into a cascaded halfband filter and a FIR filter that has half the order of the original one.
With the core pipeline in place, the next step is figuring out the exact filter parameters for each stage.
Pass Band Ripple, Stop Band Attenuation and MultiStage Decimation
The requirements call for an overall pass band ripple of 0.1dB and a stop band attenuation of 89dB.
When there’s only 1 filter, meeting that goal is a matter of specifying these numbers as the filter design parameter.
But what when multiple filters are cascaded?
Pass Band Ripple
In their 1975 paper “Optimum FIR Digital Filter Implementations for Decimation, Interpolation, and NarrowBand Filtering”, Crochiere and Rabiner write the following:
As it is desired that the overall pass band ripple for the composite of K stages be maintained within 1±δ, it is necesary to require more severe frequency constraints on the individual filters in the cascade. A convenient choice which will satisfy this requirement is to specify the pass band ripple constraints for each stage i to be within 1±δ/K.
In other words: if you split the filter into 3 stages, they suggest to split the joint passband ripple of 0.1dB into 3 smaller pass band ripples.
Unfortunately, this advise doesn’t work very well for our case: the referenced paper assumes that all stages are using similar filter types, with the ability to indepdently choose the boundaries for pass band and stop band ripple for each filter stage.
This is not the case for us: a CIC filter has very little flexibility wrt pass and stop band attenuation, and halfband filters have only 1 parameter, the filter order, to control the ripple of both pass band and stop band.
What we can take away, however, is the knowledge that we need to divide the overall pass band into smaller values and uses those as design parameter for the individual stages.
Stop Band Attenuation
The same paper has the following to say about the stop band:
In the stop band the ripple constraint for the composite filter must be δ and this constraint must be imposed on each of the individual lowpass filter as well, in order to suppress the effects of aliasing.
This is much easier: I calculated a stop band attenuation of 89dB. We can just to use that attenuation for each filter stage.
CIC Filter Configuration and Pass Band Ripple
Since they don’t require any multiplications at all, it’s desirable to shift as much as of the decimation to the frontend CIC filter.
One problem with CIC filters, however, is that the pass band ripple gets progressively worse with increasing frequency and with an increasing number of cascade stages. Without using a counter measure in the form of a compensation filter, the frequency response in the pass band can easily exceed the maximum ripple requirements of the overall filter specification.
Pass band ripple and decimation ratio
Our overall filter has a decimation ratio of 48, and thus 9 possible CIC decimation ratios: 2, 3, 4, 6, 8, 12, 16, 24, 48.
For a 5 stage configuration, these 9 options give the following magnitude frequency plots:
That tiny rectangle in the top left corner shows the frequency range from 0 to 24kHz, our final output bandwidth. Let’s zoom in on that:
The rectangle now shows the pass band: a frequency range from 0 to 6kHz and a maximum pass band ripple boundary of 0.1dB.
You can see how a decimation ratio of 16 and higher violates the maximum ripple requirements, and that’s before taking into account that the filters that follow the CIC stage need to get their share of the overall pass band ripple!
Pass band ripple and number of cascaded stages
In the graphs above, I use an example of 5 stages with variable decimation rate. I can do the same with a fixed decimation rate and a variable number of stages:
The result is more predictable, but similar: a higher number of stages increases the pass band ripple.
One way to solve this issue is to add a compensation filter with a gain in the pass band region that is the exactly opposite of the chosen CIC filter, thus resulting in a flat pass band behavior. But that’s something for a future blog post.
Pass band ripple table: decimation ratio vs number of stages
For simplicity, we will just need to limit decimation ratio and/or the number of stages such that the pass band ripple doesn’t exceed a certain maximum value. This maximum value is than the 0.1dB pass band ripple of the overall filter to leave something for for the filter stages that follow the CIC filter.
Let’s choose a maximum ripple of 0.05dB.
The table below lists all the combinations of decimation ratio and number of CIC stages, and their ripple. The entries in green are the ones that don’t violate the 0.05dB maximum:
1  2  3  4  5  6  

2  0.0003  0.0006  0.0009  0.0012  0.0015  0.0018 
3  0.0008  0.0016  0.0024  0.0032  0.0039  0.0047 
4  0.0015  0.0030  0.0044  0.0059  0.0074  0.0089 
6  0.0034  0.0069  0.0103  0.0138  0.0172  0.0207 
8  0.0062  0.0124  0.0186  0.0248  0.0310  0.0372 
12  0.0141  0.0282  0.0423  0.0564  0.0705  0.0846 
16  0.0251  0.0502  0.0753  0.1004  0.1256  0.1507 
24  0.0568  0.1135  0.1703  0.2271  0.2839  0.3406 
48  0.2190  0.4381  0.6571  0.8761  1.0952  1.3142 
If pass band ripple were the only design criterium, the best choice would be a solution with the highest decimation ratio, because that reduces the decimation ratio of the downstream nonCIC filter blocks.
But pass band ripple is not the only consideration. There’s also the antialiasing performance requirement as specified by the stop band attenuation.
CIC Filter Configuration and AntiAliasing Performance
In this section of my blog post about CIC filters, I show how the frequency of the pass band determines the amount of aliasing of higher frequencies into the pass band after decimation: the closer the pass band frequency to the overall output bandwidth, the more stages are needed to achieve a certain antialiasing performance.
For example, at frequency of 2000Hz, the CIC filter below attenuates aliased frequencies by at least 92.4dB. If we were to reduce this frequency to 1000Hz, this attenuation would go up to ~115dB.
This attenuation number also depends on the number of CIC stages and the decimation ratio. The design requirement of our filter requires a stop band attenuation of 89dB. Just like with the pass band ripple, we need a table that shows which CIC parameters have sufficient attenuation at the stop band frequency of 10kHz:
1  2  3  4  5  6  

2  37.3  74.6  112.0  149.3  186.6  223.9 
3  36.0  72.0  108.0  144.0  180.0  216.0 
4  34.2  68.4  102.6  136.8  171.0  205.2 
6  31.1  62.2  93.3  124.4  155.5  186.6 
8  28.7  57.4  86.1  114.8  143.5  172.2 
12  25.2  50.3  75.5  100.6  125.8  150.9 
16  22.6  45.2  67.7  90.3  112.9  135.5 
24  18.8  37.7  56.5  75.3  94.2  113.0 
48  12.2  24.4  36.6  48.8  61.0  73.2 
From all the green entries above, it’s best to choose those with the lowest number of CIC stages: a higher number of stages increases the width of the accumulation and delay registers, which also increases the time delay through the adders.
Final CIC Filter Configuration
Let’s combine these 2 tables to find the CIC parameters that satisfy both pass band and stop band requirements:
1  2  3  4  5  6  

2  0.0003 37.3 
0.0006 74.6 
0.0009 112.0 
0.0012 149.3 
0.0015 186.6 
0.0018 223.9 
3  0.0008 36.0 
0.0016 72.0 
0.0024 108.0 
0.0032 144.0 
0.0039 180.0 
0.0047 216.0 
4  0.0015 34.2 
0.0030 68.4 
0.0044 102.6 
0.0059 136.8 
0.0074 171.0 
0.0089 205.2 
6  0.0034 31.1 
0.0069 62.2 
0.0103 93.3 
0.0138 124.4 
0.0172 155.5 
0.0207 186.6 
8  0.0062 28.7 
0.0124 57.4 
0.0186 86.1 
0.0248 114.8 
0.0310 143.5 
0.0372 172.2 
12  0.0141 25.2 
0.0282 50.3 
0.0423 75.5 
0.0564 100.6 
0.0705 125.8 
0.0846 150.9 
16  0.0251 22.6 
0.0502 45.2 
0.0753 67.7 
0.1004 90.3 
0.1256 112.9 
0.1507 135.5 
24  0.0568 18.8 
0.1135 37.7 
0.1703 56.5 
0.2271 75.3 
0.2839 94.2 
0.3406 113.0 
48  0.2190 12.2 
0.4381 24.4 
0.6571 36.6 
0.8761 48.8 
1.0952 61.0 
1.3142 73.2 
From all the green cells above, the best solutions are those with the lowest number of CIC stages and highest decimation ratio:

6x decimation ratio with 3 stages
This option requires 3 halfband filters to decimate by 8 and 1 generic FIR filter to satisfy final passband and stopband attenuation.

8x decimation ratio with 4 stages
This requires the remaining 6x decimation ratio to be done with 1 halfband filter to decimate by 2x, followed by some generic FIR configuraton for the final 3x decimation.
There are 2 options for this generic FIR configuraiton:
 1 generic FIR filter to decimate by 3x followed by 1 generic FIR filter for the final passband and stopband attenuation
 1 generic FIR filter that immediately applies the final passband and stopband attenuation
It is not at all obvious which of the 3 options above is most optimal in terms of number of multiplications! The best way forward is to just try all 3 and see what comes out as optimal.
However, a closer look at the table above shows that the CIC configuration with 12x decimation ratio and 4 stages comes very close to passing the overall requirements, with a pass band ripple of 0.056dB, only 0.06dB higher than your 0.05dB limit.
And the thing is: that 0.05dB was chosen rather arbitrarily. We can just as arbitrarily increase that limit a bit, make this case pass, and end up with a overall filter architecture that might very well be better than the 3 earlier ones:

12x decimation ratio with 4 stages
This requires 2 halfband filters to decimate by 4 and 1 generic FIR filter for the final passband and stopband requirements.
Design of the HalfBand and Generic FIR Filters
Once the properties of the CIC filter has been decided, the halfband and generic FIR filter design is mostly a matter of just filling in the numbers and running the ParksMcClellan/Remez algorithm to come up with the exact filter coefficients.
The table below shows the resul for all 4 filter architecture candidates:
CIC Config  HB1 mul/s  HB2 mul/s  HB3 mul/s  Decim FIR mul/s  Final FIR mul/s  Total mul/s 

Decim:6 Stages:3 
4 x 192k = 768k  6 x 96k = 576k  10 x 48k = 480k  47 x 48k = 2256k  4080k  
Decim:8 Stages:4 
6 x 144k = 864k  21 x 48k = 1008k  51 x 48k = 2448k  4320k  
Decim:8 Stages:4 
6 x 144k = 864k  141 x 48k = 6768k  7632k  
Decim:12 Stages:4 
6 x 96k = 576k  10 x 48k = 480k  51 x 48k = 2448k  3504k 
It turns out that the solution with 12 stages is indeed the optimal one.
The naive singlestage FIR filter that I used as initial stake in the ground required 106M mul/s. This number has been reduced to 3.5M multiplications per second, an improvement of more than 30x!
Here are some conclusions based on the table above:
 whenever possible, try to use halfband filters for all decimation operations. Using a generic FIR filter as decimation stage has a significant cost.
 if you have to use a generic FIR filter for decimation (e.g. because the overall decimation ratio doesn’t have a factor of 2), don’t merge it with the final FIR filter
 play around with the pass band ripple portion that’s assigned to the CIC filter to find the optimal solution
This drawing shows all the operations of the final pipeline:
And here are the magnitude frequency plot and impluse response of all the filter components:
Coming Up
The architecture of decimation pipeline is now complete, but there are still things to come:
 convert theory to practise, implement everything to RTL, and run things on an FPGA
 check if a CIC compensation filter would reduce the number of multiplications even more
References
My Blog Posts in this Series
 An Intuitive Look at Moving Average and CIC Filters
 PDM Microphones and SigmaDelta A/D Conversion
 Designing Generic FIR Filters with pyFDA and NumPy
 From Microphone Datasheet to Filter Design Specification
 HalfBand Filters, a Workhorse of Decimation Filters
 Design of a MultiStage PDM to PCM Decimation Pipeline
Code
 NumPy Code used to create plots and graphs of this blog post.
Decimation

Optimum FIR Digital Filter Implementations for Decimation, Interpolation, and NarrowBand Filtering
Paper that discusses how to size cascaded filter to optimized for FIR filter complexity.

Seamlessly Interfacing MEMS Microphones with Blackfin Processors
Analog Devices application note. C code can be found here

XMOS Microphone array library
https://www.xmos.ai/download/lib_mic_array%5buserguide%5d(3.0.1rc1).pdf
Lots of technical info about PDM to PCM decimation.