# FIR filter compensator when using a CIC decimation filter

When decimating a narrow-band signal with a cascaded integrator-comb (CIC) filter, which FIR filter is more suitable to compensate the CIC frecuency response?

• – endolith Sep 7 '11 at 20:26
• yes, that one... – Augusto Zebadúa Sep 8 '11 at 1:03

There is no single answer to your question: as with any filter-design problem, it depends upon your requirements. As described pretty well on the Wikipedia page, CIC (cascaded-integrator-comb) filters consist of a number of pairs of integrator and comb stages (hence the name). Each integrator-comb stage has an aggregate impulse response that is equivalent to a boxcar filter (i.e. one with a rectangular frequency response). A boxcar's frequency (magnitude) response has a shape resembling a sinc function, so the overall CIC structure is going to have a magnitude response that looks like a sinc function taken to some power $N$, where $N$ is the number of integrator-comb stages.

There aren't a whole lot of knobs for you to tweak based on any application-specific requirements, however. You can tweak the decimation/interpolation ratio of the CIC structure, the comb delay, and the number of stages, but you're still stuck with the sinc-like frequency response, which isn't particularly ideal, as it's not flat across the main lobe and has relatively high sidelobes. So, it's typical for a CIC to be followed by another filter that "cleans up" the overall response.

The rub: what you need from any compensating filter that you put after the CIC is going to be defined by your application. What's really important is the response of the overall cascade, which you would constrain based on your application's needs. There's no specific filter that is "most suitable."

• Where you wrote "one with a rectangular frequency response", don't you mean "one with a rectangular impulse response? – nibot Oct 12 '12 at 20:47
• Yes, you're right. Thanks for pointing out the mistake. – Jason R Oct 14 '12 at 18:42

There was a similar question, https://dsp.stackexchange.com/a/1551/306, and the following is a subset of the answer from the other post.

Generally, to compensate a CIC filter the inverse of the CIC filters response can be used to generate the compensation filter. The CIC has a response of 2

$$H(\omega) = \left| \frac{sin(\omega D/2)}{sin(\omega M/2)} \right|^N$$

Where D is the differentiate delay, M is the decimation rate, and N is the filter order (number of cascaded filters). The inverse can be specified as

$$H(\omega) = \left| \frac{sin(\omega M/2)}{sin(\omega D/2)} \right|^N$$

Once we have the frequency response of the compensation filter, we can simply choose the length of FIR filter that we desire. The length of the FIR is application specific. Obviously the longer the FIR filter the better compensation.

The following are plots of this straight forward compensation.  The following is the Python code to create the frequency responses and plots.

import numpy as np from numpy import sin, abs, pi import pylab

D = 1; M = 7; N = 3

Hfunc = lambda w : abs( (sin((w*M)/2)) / (sin((w*D)/2.)) )**N
HfuncC = lambda w : abs( (sin((w*D)/2.)) / (sin((w*M)/2.)) )**N

w = np.arange(1024) * pi/1024

G = (M*D)**N
H = np.array(map(Hfunc, w))
Hc = np.array(map(HfuncC, w))
# only use the inverse (compensation) roughly to the first null.
Hc[int(1024*pi/M/2):] = 1e-8
plot(w, 20*log10(H/G))
plot(w, 20*log10(Hc*G))
grid('on')


See, Altera, "Understanding CIC compensation filters", for other approaches and $sinc^{-1}$ approximation 1.

2 R. Lyons, "Understanding Digital Signal Processing", 2nd ed., Prentice Hall, Upper Saddle River, New Jersey, 2004

• You show the frequency response that's desired in the compensation filter... but how do you get filter coefficients that produce a filter that approximates this response? I think that's what the question is asking. – nibot Oct 12 '12 at 20:49

ISOP (Interpolated Second Order Polynomial) are often used for compensation of CIC passband droop.

The Matlab response of this filter can be shown using:

alpha = 0.01 ;
b     = [1, alpha, -alpha] ;
h     = mfilt.firsrc(1,1,b)
freqz( b )


Choosing the alpha for your requirements is the tricky part. Worst case preform brute force simulations, looping over 0 to 0.5 in 0.001 increments finding the alpha which results in the best droop compensation. Defining best droop compensation as minimal error at the edge of your passband.

For efficiency this filter is normally placed at the lower data rate, before the CIC for interpolation, and after the CIC for decimation.