Hi @Vasant,
After going through your comments, it is quite frustrating to say that design of a CIC filter is a nuanced topic, particularly when it comes to the placement of delays in the filter structure. So, it is my understanding that the confusion arises from different representations of the filter in various resources, which can lead to significant differences in output if not handled correctly. I did review your blog post and mathworks function shared by you in your comments, and if I would to describe fundamental operation of a CIC filter, it will be:
Integrators: These accumulate the input signal over time.
Combs: These subtract delayed versions of the signal to achieve the desired frequency response.
Let me address your query regarding the placement of the unit delay which can significantly affect the output of the filter. In the context of CIC filters, the two configurations can be summarized as mentioned by you:
Feedback Delay: The integrator equation is represented as: [ I[n] = I[n-1] + x[n] ]. Here, the current input (x[n]) is added to the previous output (I[n-1]). This configuration is common in many resources and can lead to a straightforward implementation.
Feedforward Delay: The integrator equation is modified to: [ I[n] = I[n-1] + x[n-1] ]. In this case, the previous input (x[n-1]) is used, which aligns with the MATLAB implementation. This approach can be more aligned with the theoretical underpinnings of the CIC filter design.
So, why the discrepancy?
The discrepancy you observed between your Python implementation and MATLAB's output can be attributed to the difference in delay placement. When you initially implemented the feedback delay, the output did not match MATLAB's because the two configurations fundamentally alter the filter's response.
You mentioned, which one to follow?
The choice between using a feedback or feedforward delay ultimately depends on the specific requirements of your application and the conventions you choose to follow. However, here are some of my logical considerations:
Consistency with Established Standards: If you are working in an environment where MATLAB's dsp.CICDecimator is the standard, it is advisable to follow the feedforward delay approach. This ensures compatibility and consistency with existing MATLAB-based designs.
Performance and Stability: The feedforward configuration may offer better numerical stability in certain scenarios, especially when dealing with high-order filters or large input signals.
Implementation Complexity: Depending on your programming environment, one configuration may be easier to implement than the other. If you find that the feedforward approach aligns better with your existing codebase, it may be prudent to adopt it.
So, in nutshell, while both configurations can be valid, the feedforward delay placement as per MATLAB's documentation is recommended for consistency and reliability. It is essential to ensure that your implementation aligns with the theoretical framework of the CIC filter to achieve the desired performance. By adopting the feedforward delay, you can ensure that your Python implementation matches MATLAB's output, thereby validating your design choices.
Hope this helps.