2

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
Irreducible
  • 296
  • 1
  • 12
Knut Inge
  • 3,384
  • 1
  • 8
  • 13
  • Add an edit section at the bottom of your question and move the code there. It will be easier to understand. – Ben Feb 23 '20 at 01:01
  • Non-recursive moving average = 100 additions per sample – Ben Feb 23 '20 at 19:01
  • Recursive moving average = 2 additions per sample – Ben Feb 23 '20 at 19:01
  • My »decimated moving average» above does <100 adds in total for a 100 sample input decimated by 5. That is 1 add per input sample? Seems that we have some misunderstanding over basic premises or terminology? – Knut Inge Feb 23 '20 at 22:31
  • No... How many additions do you need to output one sample? – Ben Feb 23 '20 at 22:31
  • My first output sample is: y(1) = (1/5) * (x(1) + x(2) + x(3) + x(4) + x(5)). The next output sample is y(2) = (1/5) * (x(6)+ x(7)+ x(8)+ x(9) + x(10)). I count four adds per output, one per input. – Knut Inge Feb 24 '20 at 07:58
  • 1
    Ok in that case, you don't have a moving- average filter – Ben Feb 24 '20 at 12:22
  • You have a moving average filter with decimation by 5 – Ben Feb 24 '20 at 12:22
  • A moving-average filter does not decimate, the input sampling rate is the same as the output sampling rate.

    In the code you posted, you filter AND downsample at the same time...

    – Ben Feb 24 '20 at 13:04
  • True, but it is a sensible thing to do when you want to do moving average and downsampling, it is intuitively easier to grasp than CIC and seems to demand less resouces? – Knut Inge Feb 24 '20 at 15:06
  • It takes more resources than a CIC filter...

    You only need 2 additions per sample for a CIC filter.

    – Ben Feb 24 '20 at 15:09
  • My code has 1 add per input sample for the decimated MA and 1+1/D add per input sample for the CIC. It may well be that I am misunderstanding the whole thing but it seems that our communication has reached a dead end. – Knut Inge Feb 24 '20 at 20:46
  • 1
    Say you average by 20 and downsample by 5.

    You'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

1 Answers1

4

It seems you mixed up CIC filters and recursive moving-average

A recursive moving-average uses a comb-filter and an accumulator.

$$ H(z) = \frac{1}{N}\frac{1-z^{-N}}{1-z^{-1}} $$

The numerator corresponds to a comb filter (i.e a delay line of N elements and 1 adder). The denominator corresponds to an accumulator. The 1/N factor is to get a moving-average, otherwise you'd have a moving-accumulator. You only need 2 additions, a delay line, an accumulator and a divider. With a non-recursive moving-average filter, you'd need N additions and you'd need a delay line anyway. A recursive moving-average is much less computionally expansive than a non-recursive moving-average filter.

Now the CIC filter combines the recursive moving-average filter with decimation and interpolation.

For a CIC decimation filter, you insert the rate transition block between the accumulator and the comb filter. Say you have a 16-sample moving average-filter (N=16) and you want to decimate by 8 (R = 8). You'd need a delay line of 16 elements. However, by inserting the decimation between the accumulator and the comb filter, you can reduce the number of elements in the delay line. You'd only need N/R elements, i.e. 2. You'd still need to subtract 2 numbers, however you would do it at sampling rate of fs/8.

I suggest you consult this site

https://www.researchgate.net/publication/228648728_Understanding_cascaded_integrator-comb_filters

Update: see this nice write-up by Richard Lyons- https://www.dsprelated.com/showarticle/1337.php

Dan Boschen
  • 50,942
  • 2
  • 57
  • 135
Ben
  • 3,765
  • 1
  • 10
  • 17