# cic_comp_design

Design of a compensation FIR filter for a CIC filter, using the frequency sampling technique.

## Séquence d'appel

`cfir = cic_comp_design(R,N,M,Fin,R2,Fcut,ntaps)`

## Paramètres

R :

CIC decimation ratio

N :

Number of CIC integrators / differentiators

M :

CIC design parameter

Fin :

Input frequency

R2:

Compensation filter decimation ratio

Fcut:

Cutoff frequency for the compensation FIR filter

ntaps:

Number of taps of the FIR filter

cfir:

Compensation FIR filter coefficients

## Description

This function will try to design a compensation filter for the specified CIC filter. The global decimation chain will be composed of two stages:

1. The first stage is the CIC filter, and decimate by the ratio .
2. The second stage is the compensation filter, and decimate by the ratio .
So, the global decimation ratio will be .

The compensation filter is generated through the frequency sampling technique. This function will do the FIR compensation design, plot the frequency responses, and output (output parameter `cfir`) the compensation filter coefficients.

## Exemple

 ```// Input signal frequency: Fin = 6.4 KHz // CIC decimation factor: R = 1/16 (freq at output of CIC: 400 Hz) // Compensation FIR decimation factor: R2 = 1/2 // Output signal frequency: 6400/(R*R2) = 200 Hz // Cut-off frequency for FIR filter: 80 Hz R=16, N=4, M=1, Fin=6400, Fcut=80, ntaps=60, R2=2; cfir = cic_comp_design(R,N,M,Fin,R2,Fcut,ntaps); // "cfir" is the array of coefficents of the FIR compensation filter.```

Impulse response of the FIR compensation filter

Global response of CIC + compensation filters (spectrum)