I have been trying to wrap my head around CIC filters.
Say that I want to do filtered decimation by a factor D.
Option#1: boxcar filter. Each output sample is formed by taking the sum of D input samples, and multiplying/shifting to get a proper average. D-1 adds per output sample.
Option#2: 1-stage CIC filter with an accumulator running at the input rate, and a comb filter running at the output rate. D adds per output sample.
So what is the fuzz about? Does CIC only make sense for higher orders? If order N CIC is like convolving the rect() function N-1 times, that would be a B-spline, right? I have seen authors praising B-splines for their functional benefits. Being able to do them efficiently might be handy.
Thanks for any input Knut
Edit: pseudo matlab code showing the alternatives as I understand them.
N=100;
x = randn(N,1);
D = 5;
%% decimated moving average, ~100 adds
for k = 1:N/D
y(k) = (1/D)*(x(k*D) + x(k*D-1) + ... + x(k*D-D+1));
end
%% recursive moving average, ~200 adds
y(1) = x(1);
for k = 2:N
y(k) = x(k) + y(k-1);
end
for k = D:N
z(k) = y(k) - y(k-D);
end
z = z(1:D:end);
%% CIC, ~120 adds
y(1) = x(1);
for k = 2:N
y(k) = x(k) + y(k-1);
end
z = y(1:D:end);
for k = 2:N/D
w(k) = z(k) - z(k-1);
end
In the code you posted, you filter AND downsample at the same time...
– Ben Feb 24 '20 at 13:04You only need 2 additions per sample for a CIC filter.
– Ben Feb 24 '20 at 15:09You'd need 120 additions for the CIC filter, while you'd need 400 additions with your method. No one said that the averaging factor and the downsampling factor needs to be the same.
– Ben Feb 24 '20 at 21:03