Filter Design Toolbox 4.6
Using a Cascaded Integrator-Comb (CIC) Decimation Filter
This demonstration shows how to use the multirate CIC decimation filter in the Filter Design Toolbox™.
CIC filters are efficient, multiplierless structures which are used in high-decimation or interpolation systems. CIC filters are commonly used in digital down-converters (DDCs) and digital up-converters. See Implementing the Filter Chain of a Digital Down-Converter in HDL for an example of a CIC decimator used for GSM.
Contents
Getting Help
To obtain information about creating a CIC decimation filter, type "helpwin mfilt.cicdecim." For help on all multirate filters in the Filter Design Toolbox, type "helpwin mfilt"
Creating a CIC Decimation Filter
With the Fixed-Point Toolbox™ installed, you can create a default CIC Decimator with the following:
Hm = mfilt.cicdecim
Hm =
FilterStructure: 'Cascaded Integrator-Comb Decimator'
Arithmetic: 'fixed'
DifferentialDelay: 1
NumberOfSections: 2
DecimationFactor: 2
PersistentMemory: false
InputWordLength: 16
InputFracLength: 15
FilterInternals: 'FullPrecision'
The display of the object groups the properties together in a logical manner. Notice that only the writable properties are displayed. Unlike other multirate filters (MFILT) available in the Filter Design Toolbox, CIC filters do not allow different arithmetics, since these filters are inherently fixed-point filters.
set(Hm,'Arithmetic')
ans =
'fixed'
The get method always returns the complete list of property/value pairs.
get(Hm)
PersistentMemory: 0
NumSamplesProcessed: 0
FilterStructure: 'Cascaded Integrator-Comb Decimator'
States: [1x1 filtstates.cic]
DifferentialDelay: 1
NumberOfSections: 2
Arithmetic: 'fixed'
DecimationFactor: 2
InputOffset: 0
RoundMode: 'floor'
OverflowMode: 'wrap'
CastBeforeSum: 1
InputWordLength: 16
OutputWordLength: 18
FilterInternals: 'FullPrecision'
SectionWordLengths: [18 18 18 18]
InputFracLength: 15
SectionFracLengths: [15 15 15 15]
OutputFracLength: 15
Analyzing a CIC Decimator
Analysis of CIC filters is the same as any MFILT object available in the Filter Design Toolbox. The Filter Visualization Tool (FVTool) provides graphical access to all analyses.
Hm = mfilt.cicdecim(8,1,4); hfvt = fvtool(Hm); set(hfvt,'showreference','off','Color','white'); legend(hfvt, 'CIC Decimator: R=8, M=1, N=4');
Filter Internals
The FilterInternals property of the CIC decimation filter determines how to define the section specific precision used during either the accumulation of the data in the integrator sections or the subtraction of the data performed by the comb sections. This property can take one of four values:
set(Hm,'FilterInternals')
ans =
'FullPrecision'
'MinWordLengths'
'SpecifyWordLengths'
'SpecifyPrecision'
The 'FullPrecision' mode performs filtering with no loss of precision whatsoever. This mode is useful when retaining all bits is a possibility, or as a first trial to obtain the best possible results and create a baseline to refer to if bits need to be removed later. This mode is the default.
The minimum word length (MinWordLengths) is used to remove bits from intermediate sections of the filter when it is known that bits will also be removed at the output of the filter. The criteria used is that the addition of all quantization noise introduced by removing bits in the various sections of the filter does not exceed the quantization noise introduced by the removal of bits at the output. Therefore, the section word lengths are computed given the filter parameters R,M,N, and the input and output word lengths. See the reference cited below for more information on this mode.
The 'SpecifyWordLengths' mode allows for the specification of the number of bits to use in each section of the filter. The fraction length of each section is computed automatically in such a way that the output of the filter does not overflow. This mode provides more control than the minimum-wordlength mode since in the latter mode, the wordlength of each section is computed automatically.
The 'SpecifyPrecision' mode provides full control over all wordlengths and fraction lengths in the filter.
Decimator Design Example
We will reproduce the example from page 159 of the reference below. We will design a decimation filter to reduce the sampling rate from 6 MHz to 240 kHz with a passband of 30 kHz. The aliasing attenuation must be better than 60 dB. The number of bits in the input and output registers is 16.
D = 1; % Differential delay M = 25; % Decimation factor 6 MHz --> 240 kHz Fp = 30e3; % Fpass: 30 kHz Fs = 6e6; % Sampling rate 6 MHz Ast = 60; % Aliasing attenuation 60 dB f = fdesign.decimator(M,'CIC',D,Fp,Ast,Fs); Hm = design(f); set(hfvt,'Filters',Hm) legend 'off' Hm.InputWordLength = 16;
We can see from the magnitude response plot that the passband decay is less than 1 dB. To set the output wordlength, we change the filter internals to minimum-wordlengths. The resulting section wordlengths are computed by subtracting the LSBs to discard as in the reference.
Hm.FilterInternals = 'minwordlengths';
Hm.OutputWordLength = 16;
Hm.SectionWordLengths
ans =
34 29 26 22 21 20 19 18
For the case when the word lengths are completely specified (SpecifyWordLengths), either a scalar or a vector (of length 2*N) can be used. If the word lengths are defined as a scalar, the filter method will expand this scalar to a vector of length 2*N. If a vector is specified, it must be of length 2*N.
Hm.FilterInternals = 'SpecifyWordLengths';
Hm.SectionWordLengths = 34;
Hm.SectionWordLengths
ans =
34 34 34 34 34 34 34 34
States
The states property of CIC decimation filter contains an object, FILTSTATES.CIC. This object represents the initial conditions of the filter before filtering and the final conditions after filtering. The object has two properties, Integrator and Comb, corresponding to their respective portions of the filter.
% Filtering ones
x = fi(ones(1,10),true,16,0);
Hm.InputFracLength = 0;
y = filter(Hm,x);
Filter Implementation
The implementation of the CIC Decimator is a slightly modified structure from the one seen in the reference below. The difference lies in the location of the delays of the integrator portion of the filter. This implementation is optimized for pipelining on hardware such as an FPGA. The following Simulink® model provides a signal-flow graph of the structure:
Generating Simulink® Models
This structure can be created using the following command
realizemdl(Hm)
When the Signal Processing Blockset™ is installed, you can generate a CIC decimation block for the filter:
block(Hm);
Warning: The generated block has been renamed Filter1.
Generating HDL
When the Filter Design HDL Coder™ is installed, you can generate HDL code by using the generatehdl method.
Reference
Hogenauer, E. B., "An Economical Class of Digital Filters for Decimation and Interpolation", IEEE® Transactions on Acoustics, Speech, and Signal Processing, Vol. ASSP-29, No. 2, April 1981, pp. 155-162.
Store