Doubt regarding CIC filter implementation.
![](https://www.embeddedrelated.com/new/images/defaultavatar.jpg)
I wrote a CIC filter design in Python using the below-given equations. I tried to check the design I have, comparing the output with an ideal Matlab CIC function. In Matlab, I used dsp.CICDecimator function.
My doubt is, based on all my research and reading, the working of CIC filter is based on the below equations. But for a set of 12 input values , let's say [0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1], the output I am getting from matlab ideal function and my python implementation of this equations are different.
Does anyone know what happens inside the dsp.CICDecimator function?
Am I missing out any crucial in the below equations?
If not matlab cic function, what else can I compare my design with?
The equations I used for implementation are:
Integrator stage
I[n] = I[n-1] + x[n]
Decimation:
Keeping every Rth sample and sending it to the comb stage.
For R =4 and input : 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13…………..
The values selected would be 1, 5, 9 ... so on
Comb Stage
C[n] = Id[n] - Id[n-D]
(EDIT 8/10/24)
Where:
x[n] is the input.
I[n] is the integrator output.
Id[n] is the decimator output after the decimation of the integrator output by a factor R.
C[n] is the Comb output.
D is the differential delay and have assumed it to value 1.
Diagram:
![](https://d23s79tivgl8me.cloudfront.net/user/profilepictures/142294.jpg)
The rate for the second part should bee 1/4 of the first part rate in this example.
![](https://www.embeddedrelated.com/new/images/defaultavatar.jpg)
After decimation, fewer samples are processed in the comb stage, as we have already reduced the sample rate by a factor of
RR. Therefore, I hope the comb filter is working at the 1/R rate of the first part, right? Should I incorporate any additional features for this?
![](https://d23s79tivgl8me.cloudfront.net/user/profilepictures/50640.jpg)
This looks correct. Be sure your implementation is in fixed point with the accumulator set to wrap on overflow/underflow. Also there should only be one overflow over the entire time span of the CIC which is given by (N-1)R.
![](https://d23s79tivgl8me.cloudfront.net/user/profilepictures/37480.jpg)
The diagram looks ok.
The equations are ok but will have to be cascaded.
Your comb equation of C[n] = I[n] - I[n-D] should take care of (R) and I assume you don't really mean (I) per se.
Write one stage code first then go for cascading. The initial conditions may mislead as well.
You may also check frequency response to an impulse or bandlimited input instead of targetting time domain macthing.
![](https://www.embeddedrelated.com/new/images/defaultavatar.jpg)
Thank you for the reply.
Yes, we have cascaded the output of each equation.
Have made the equation more clear now.
I[n] = I[n-1] + x[n] --> Decimation by factor R --> C[n] = Id[n] - Id[n-D]
where,
x[n] is the input.
I[n] is the integrator output.
Id[n] is the decimator output after the decimation of the integrator output by a factor R.
C[n] is the Comb output.
D is the differential delay and have assumed it to value 1.
Will check the freq response and will revert back.