# CIC design mini-toolbox

CIC filters are very useful in applications where one needs to change the sampling frequency in a big ratio, for instance for decimation (reduction of the sampling rate: oversampled acquisition systems, sigma-delta ADC) or interpolation (DAC).

The advantage of these filters is that they are particularly efficient in terms of complexity (no mulmultiplication, only integrators and comb filters are necessary), which enable them to be used even at very high sampling rate.

This SCILAB mini-toolbox enables you to evaluate (in terms of frequency response) CIC filters, to design what is called a compensation filter, and to simulate the CIC filtering on real signals.

## Installation

• If not already done, install SCILAB (free numerical computing software).
• Download the CIC design mini-toolbox, and unzip it.
• On the scilab console, type
``exec("...path to the toolbox...\loader.sce");``
• Now all the CIC design functions are available on the SCILAB console (see API section for the documentation).

## Usage examples

### Frequency response computing

From the three parameters R, N and M of a CIC filter (for more complete explanations on these notations and the internal working of a CIC filter, you can consult this small tutorial), one can compute the frequency response and the frequency aliasing at the output of the CIC filter by simply calling the following command:

``cic_analysis(R, N, M, Fin);``

The following diagrams are then plotted: CIC filter / before decimation: frequency response CIC filter / after decimation: frequency response and et frequency aliasing

### Design of a CIC compensation filter

In this example, we wish to decimate a signal according to the following specifications:

• Input signal frequency (Fint): 6,4 KHz
• CIC decimation factor (R): 1/16 (sampling frequency at the output of CIC filter: 400 Hz)
• Compensation filter decimation factor (R2): 2 (sampling frequency at the end of the chain: 200 Hz)
• Cut-off frequency for compensation filter: 80 Hz (the FIR compensation stage will work at 400 Hz)
• Number of taps for the compensation FIR filter: 60

With the mini-toolbox, this can be done with the following command:

``````R=16, N=5, M=1, Fin=6400, R2=2, Fcut=80, ntaps=60;
cfir = cic_comp_design(R,N,M,Fin,R2,Fcut,ntaps);
`````` FIR compensation filter (impulse response) Global filter (CIC and compensation FIR)

As you can see on the above figure, the compensation filter (red curve), working at 400 Hz, that is, after the decimation by 16 (CIC decimation ratio), show a periodical frequency response (aliasing every 400 Hz), which is normal. The global filter (CIC and compensation FIR) has the desired response.

### CIC filtering simulation

The CIC mini-toolbox enables both CIC decimation and interpolation simulation.

In this example, we simulate the decimation of a signal from the original sampling rate of 10 MHz to a sampling rate of 625 KHz (the complete source code of this example is available in the documentation of the `cic_process` function). Example of decimation by a CIC filter