|
| 1 | +# CIC (Cascaded Integrator-Comb) Filter |
| 2 | + |
| 3 | +## Overview & Motivation |
| 4 | + |
| 5 | +Decimation and interpolation in digital signal processing typically require a lowpass anti-aliasing filter before the rate change. Standard FIR filters require multiplications proportional to their order. The CIC filter achieves a highly efficient lowpass response using only additions and subtractions, making it ideal for resource-constrained embedded systems where multipliers are expensive or unavailable. |
| 6 | + |
| 7 | +CIC filters are used in sigma-delta ADC interfaces, software-defined radio front-ends, and any application that must drastically reduce the sample rate of a high-frequency signal stream before further processing. |
| 8 | + |
| 9 | +## Mathematical Theory |
| 10 | + |
| 11 | +### Core Definitions |
| 12 | + |
| 13 | +A CIC decimator of order $N$ with decimation ratio $R$ and differential delay $M$ is defined by its $z$-domain transfer function: |
| 14 | + |
| 15 | +$$H(z) = \left( \frac{1 - z^{-RM}}{1 - z^{-1}} \right)^N$$ |
| 16 | + |
| 17 | +The numerator factor $1 - z^{-RM}$ is the $z$-transform of the comb (differencing) stage. The denominator $\frac{1}{1 - z^{-1}}$ is the accumulator (integrator) stage. |
| 18 | + |
| 19 | +### Structure |
| 20 | + |
| 21 | +The filter consists of two cascaded sections: |
| 22 | + |
| 23 | +**Integrator section** (running at the high input rate $f_s$): $N$ stages of first-order IIR accumulators, |
| 24 | + |
| 25 | +$$y_k[n] = y_k[n-1] + y_{k-1}[n], \quad k = 1, \ldots, N$$ |
| 26 | + |
| 27 | +**Comb section** (running at the low output rate $f_s / R$): $N$ stages of differencing with delay $M$, |
| 28 | + |
| 29 | +$$y_k[m] = y_{k-1}[m] - y_{k-1}[m - M], \quad k = 1, \ldots, N$$ |
| 30 | + |
| 31 | +### DC Gain |
| 32 | + |
| 33 | +The unnormalized DC gain of the filter is: |
| 34 | + |
| 35 | +$$G = (R \cdot M)^N$$ |
| 36 | + |
| 37 | +All outputs are divided by $G$ to normalize the DC gain to unity for a constant input. |
| 38 | + |
| 39 | +### Frequency Response |
| 40 | + |
| 41 | +The magnitude response in the baseband is approximately: |
| 42 | + |
| 43 | +$$|H(f)| = \left| \frac{\sin(\pi f M R / f_s)}{R \sin(\pi f / f_s)} \right|^N$$ |
| 44 | + |
| 45 | +This is a sinc-like response that suppresses high-frequency content before the rate change. |
| 46 | + |
| 47 | +## Complexity Analysis |
| 48 | + |
| 49 | +| Case | Time per input sample | Space | Notes | |
| 50 | +|---------|-----------------------|----------------|----------------------------------------------------| |
| 51 | +| Best | $O(N)$ | $O(N \cdot M)$ | $N$ integrator ops; comb only at decimation points | |
| 52 | +| Average | $O(N)$ | $O(N \cdot M)$ | Same | |
| 53 | +| Worst | $O(N)$ | $O(N \cdot M)$ | Comb adds $N$ differencing ops at rate $f_s/R$ | |
| 54 | + |
| 55 | +The integrator section executes $N$ additions per input sample. The comb section executes $N$ subtractions once every $R$ input samples. There are no multiplications in the signal path. |
| 56 | + |
| 57 | +## Step-by-Step Walkthrough |
| 58 | + |
| 59 | +Consider $N=2$, $R=4$, $M=1$, input impulse $x[0]=1$, $x[n]=0$ for $n>0$. |
| 60 | + |
| 61 | +**Integrator section at $n=0,1,2,3$:** |
| 62 | + |
| 63 | +| $n$ | Input | Integrator 1 | Integrator 2 | |
| 64 | +|-----|-------|--------------|--------------| |
| 65 | +| 0 | 1 | 1 | 1 | |
| 66 | +| 1 | 0 | 1 | 2 | |
| 67 | +| 2 | 0 | 1 | 3 | |
| 68 | +| 3 | 0 | 1 | 4 | |
| 69 | + |
| 70 | +**Comb section at decimated sample $m=0$ (triggered at $n=3$):** |
| 71 | + |
| 72 | +- Comb 1 input: 4; delay buffer held 0; output: $4 - 0 = 4$; buffer updated to 4 |
| 73 | +- Comb 2 input: 4; delay buffer held 0; output: $4 - 0 = 4$; buffer updated to 4 |
| 74 | +- Normalized output: $4 / 16 = 0.25$ |
| 75 | + |
| 76 | +**At $m=1$ (triggered at $n=7$):** |
| 77 | + |
| 78 | +- Integrator 2 output: 8 (accumulated four more 1s from integrator 1) |
| 79 | +- Comb 1: $8 - 4 = 4$; Comb 2: $4 - 4 = 0$; Normalized output: $0.0$ |
| 80 | + |
| 81 | +## Pitfalls & Edge Cases |
| 82 | + |
| 83 | +**Integer overflow in fixed-point implementations**: in fixed-point arithmetic, the integrators accumulate without bound between comb operations. Registers must be wide enough to hold $(R \cdot M)^N$ times the maximum input value. This implementation uses floating-point, which avoids this issue. |
| 84 | + |
| 85 | +**Initial transient**: the filter takes several R-length blocks to settle to steady-state behavior for a constant input. DC normalization is exact only after the delay pipeline is fully flushed. |
| 86 | + |
| 87 | +**Passband droop**: the sinc-shaped response causes attenuation even near DC as the input frequency increases. Compensation filters or a larger $R$ reduce in-band droop. |
| 88 | + |
| 89 | +**Aliasing from high-order terms**: if the input signal has energy above $f_s / (2R)$, aliased components will appear at the output. A simple prefilter can reduce this. |
| 90 | + |
| 91 | +## Variants & Generalizations |
| 92 | + |
| 93 | +**Interpolating CIC**: the comb section runs at the low rate and the integrators at the high rate, acting as an upsampler. The architecture mirrors the decimator with sections swapped. |
| 94 | + |
| 95 | +**Pruned CIC**: removes multiplier-free adder stages that contribute negligibly to the response, reducing hardware at the cost of response shape. |
| 96 | + |
| 97 | +**Compensation filter**: a short linear-phase FIR appended at the low rate corrects passband droop without reintroducing multipliers in the high-rate path. |
| 98 | + |
| 99 | +**Variable-rate CIC**: by making $R$ a runtime parameter, one filter structure supports multiple decimation ratios, useful in SDR front-ends. |
| 100 | + |
| 101 | +## Applications |
| 102 | + |
| 103 | +- Sigma-delta ADC decimation: the high oversampling rate (e.g., 256x) is reduced to Nyquist rate by a CIC stage before a compensation FIR. |
| 104 | +- Software-defined radio: narrowband channels are extracted from a wideband stream by decimating with a CIC before channelization. |
| 105 | +- Audio sample-rate conversion: high-to-low rate conversion with anti-aliasing, followed by a polyphase FIR for droop correction. |
| 106 | +- Sensor interfaces: smoothing and downsampling of high-rate MEMS sensor data with minimal compute budget. |
| 107 | + |
| 108 | +## Connections to Other Algorithms |
| 109 | + |
| 110 | +A CIC filter of order $N=1$, $M=1$ is equivalent to a boxcar (rectangular window) FIR of length $R$, identical to a Moving Average filter operating on non-overlapping blocks. The Moving Average filter in this library is the continuous-output counterpart. |
| 111 | + |
| 112 | +Higher-order CICs approximate a Gaussian response as $N \to \infty$, connecting them to the Gaussian filter family in theory. |
| 113 | + |
| 114 | +The CIC is a special case of the more general Hogenauer filter structure, which can be pruned to reduce word widths at each stage. |
| 115 | + |
| 116 | +## References & Further Reading |
| 117 | + |
| 118 | +- E. B. Hogenauer, "An economical class of digital filters for decimation and interpolation," IEEE Transactions on Acoustics, Speech, and Signal Processing, vol. 29, no. 2, pp. 155-162, April 1981. |
| 119 | +- R. E. Crochiere and L. R. Rabiner, "Multirate Digital Signal Processing," Prentice-Hall, 1983. Chapter 3. |
| 120 | +- F. J. Harris, "Multirate Signal Processing for Communication Systems," Prentice-Hall, 2004. |
0 commit comments