dsp.CICDecimator - Decimate signal using cascaded integrator-comb (CIC) filter - MATLAB (original) (raw)

Decimate signal using cascaded integrator-comb (CIC) filter

Description

The dsp.CICDecimator System object™ decimates an input signal using a cascaded integrator-comb (CIC) decimation filter. The CIC decimation filter structure consists of N sections of cascaded integrators, followed by a rate change by a factor of R, followed by N sections of cascaded comb filters. For details, see Algorithms. The NumSections property specifies N, the number of sections in the CIC filter. The DecimationFactor property specifies R, the decimation factor. The getFixedPointInfo function returns the word lengths and fraction lengths of the fixed-point sections and the output for the dsp.CICDecimator System object.

Note

This object requires a Fixed-Point Designer™ license.

To decimate a signal using a CIC filter:

  1. Create the dsp.CICDecimator object and set its properties.
  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Creation

Syntax

Description

`cicDecim` = dsp.CICDecimator creates a CIC decimation System object that applies a CIC decimation filter to the input signal.

example

`cicDecim` = dsp.CICDecimator(`R`,`M`,`N`) creates a CIC decimation object with the DecimationFactor property set to R, the DifferentialDelay property set toM, and the NumSections property set toN.

example

`cicDecim` = dsp.CICDecimator(`Name=Value`) sets properties using one or more name-value arguments. For example, to specify the decimation factor as 8, setDecimationFactor to 8.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and therelease function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, seeSystem Design in MATLAB Using System Objects.

Factor by which the input signal is decimated, specified as a positive integer.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Differential delay value used in each of the comb sections of the filter, specified as a positive integer. For details, see Algorithms. If the differential delay is a built-in integer data type, the decimation factor must be the same integer data type or double. For example, if the differential delay is anint8, then the decimation factor must be an int8 or double.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Number of integrator and comb sections of the CIC filter, specified as a positive integer. This number indicates the number of sections in either the comb part or the integrator part of the filter. The total number of sections in the CIC filter is twice the number of sections given by this property.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Fixed-point property designations, specified as one of the following:

Fixed-point word lengths to use for each filter section, specified as a scalar or a row vector of integers. The word length must be greater than or equal to 2. If you specify a scalar, the value applies to all the sections of the filter. If you specify a vector, the vector must be of length 2 × NumSections.

Example: 32

Example: [32 32 32 32]

Dependencies

This property applies when you set theFixedPointDataType property to"Specify word lengths" or "Specify word and fraction lengths".

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Fixed-point fraction lengths to use for each filter section, specified as a scalar or a row vector of integers. The fraction length can be negative, 0, or positive. If you specify a scalar, the value applies to all the sections of the filter. If you specify a vector, the vector must be of length 2 × NumSections.

Example: -2

Example: [-2 0 5 8]

Dependencies

This property applies when you set theFixedPointDataType property to"Specify word and fraction lengths".

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Fixed-point word length to use for the filter output, specified as a scalar integer greater than or equal to 2.

Dependencies

This property applies when you set theFixedPointDataType property to"Minimum section word lengths","Specify word lengths", or "Specify word and fraction lengths".

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Fixed-point fraction length to use for the filter output, specified as a scalar integer.

Dependencies

This property applies when you setFixedPointDataType property to"Specify word and fraction lengths".

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Usage

Syntax

Description

[cicDecimOut](#mw%5F1dd53507-4c1a-4b9d-897e-dafe5692a981) = cicDecim([input](#d126e257292)) decimates the input using a CIC decimator.

example

Input Arguments

expand all

Data input, specified as a vector or matrix. The number of rows in the input must be a multiple of the DecimationFactor. If the input is ofsingle or double data type, property settings related to the fixed-point data types are ignored.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes

Output Arguments

expand all

Decimated output, returned as a vector or a matrix. The output frame size equals (1 ∕ DecimationFactor) × input frame size. The complexity of the output data matches that of the input data. If the input is single or double, the output data type matches the input data type.

If the input is of built-in integer data type or of fixed-point data type, the output word length and fraction length depend on the fixed-point data type setting you choose through the FixedPointDataType property.

Full precision

When the FixedPointDataType is set to"Full precision", the following relationship applies:

where,

The _WL_input and_FL_input are inherited from the data input you pass to the object algorithm. For built-in integer inputs, the fraction length is 0.

Minimum section word lengths

When the FixedPointDataType property is set to "Minimum section word lengths", the output word length is the value you specify in the OutputWordLength property. The output fraction length,_FL_output, is given by:

Specify word and fraction lengths

When the FixedPointDataType property is set to "Specify word and fraction lengths", the output word length and fraction length are the values you specify in the OutputWordLength and OutputFractionLength properties.

Specify word lengths

When the FixedPointDataType property is set to "Specify word lengths", the output word length is the value you specify in theOutputWordLength property. The output fraction length,_FL_output, is given by:

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

expand all

impz Impulse response of discrete-time filter System object
freqz Frequency response of discrete-time filter System object
freqzmr Compute DTFT approximation of impulse response of multirate or single-rate filter
phasez Phase response of discrete-time filter System object (unwrapped)
filterAnalyzer Analyze filters with Filter Analyzer app
gain Gain of CIC filter System object
getFixedPointInfo Get fixed-point word and fraction lengths
info Information about filter System object
outputDelay Determine output delay of single-rate or multirate filter
step Run System object algorithm
release Release resources and allow changes to System object property values and input characteristics
reset Reset internal states of System object

For a list of filter analysis methods this object supports, typedsp.CICDecimator.helpFilterAnalysis in the MATLAB® command prompt. For the corresponding function reference pages, see Analysis Functions for Filter System Objects.

Examples

collapse all

Create a dsp.CICDecimator System object™ with DecimationFactor set to 4. Decimate a signal from 44.1 kHz to 11.025 kHz.

cicdec = dsp.CICDecimator(4);
cicdec.FixedPointDataType = "Minimum section word lengths"; cicdec.OutputWordLength = 16;

Create a fixed-point sinusoidal input signal of 1024 samples, with a sampling frequency of 44.1e3 Hz.

Fs = 44.1e3;
% 0.0232 sec signal n = (0:1023)';
x = fi(sin(2pi1e3/Fs*n),true,16,15);

Create a dsp.SignalSource object.

src = dsp.SignalSource(x,64);

Decimate the output with 16 samples per frame.

y = zeros(16,16); for ii = 1:16 y(ii,:) = cicdec(src());
end

Plot the first frame of the original and decimated signals. Output latency is 2 samples.

D = cicdec.DecimationFactor; diffDelay = cicdec.DifferentialDelay; NumSect = cicdec.NumSections; gainCIC = ... (D*diffDelay)^NumSect; stem(n(1:56)/Fs,double(x(4:59))) hold on;
stem(n(1:14)/(Fs/D),double(y(1,3:end))/gainCIC,... "r","filled") xlabel("Time (sec)") ylabel("Signal Amplitude") legend("Original signal",... "Decimated signal",... "Location","north") hold off;

Figure contains an axes object. The axes object with xlabel Time (sec), ylabel Signal Amplitude contains 2 objects of type stem. These objects represent Original signal, Decimated signal.

Using the info method in "long" format, obtain the word lengths and fraction lengths of the fixed-point filter sections and the filter output.

ans = 16×56 char array 'Discrete-Time FIR Multirate Filter (real) ' '----------------------------------------- ' 'Filter Structure : Cascaded Integrator-Comb Decimator' 'Decimation Factor : 4 ' 'Differential Delay : 1 ' 'Number of Sections : 2 ' 'Stable : Yes ' 'Linear Phase : Yes (Type 1) ' ' ' ' ' 'Implementation Cost ' 'Number of Multipliers : 0 ' 'Number of Adders : 4 ' 'Number of States : 4 ' 'Multiplications per Input Sample : 0 ' 'Additions per Input Sample : 2.5 '

Using the getFixedPointInfo function, you can determine the word lengths and fraction lengths of the fixed-point sections and the output of the dsp.CICDecimator and dsp.CICInterpolator System objects. The data types of the filter sections and the output depend on the FixedPointDataType property of the filter System object™.

Full precision

Create a dsp.CICDecimator object. The default value of the NumSections property is 2. This value indicates that there are two integrator and comb sections. The WLs and FLs vectors returned by the getFixedPointInfo function contain five elements each. The first two elements represent the two integrator sections. The third and fourth elements represent the two comb sections. The last element represents the filter output.

cicD = dsp.CICDecimator with properties:

  DecimationFactor: 2
 DifferentialDelay: 1
       NumSections: 2
FixedPointDataType: 'Full precision'

By default, the FixedPointDataType property of the object is set to "Full precision". Calling the getFixedPointInfo function on this object with the input numeric type, nt, yields the following word length and fraction length vectors.

nt = numerictype(1,16,15)

nt =

      DataTypeMode: Fixed-point: binary point scaling
        Signedness: Signed
        WordLength: 16
    FractionLength: 15

[WLs,FLs] = getFixedPointInfo(cicD,nt) %#ok

For details on how the word lengths and fraction lengths are computed, see the description for Output Arguments.

If you lock the cicD object by passing an input to its algorithm, you do not need to pass the nt argument to the getFixedPointInfo function.

input = int64(randn(8,1))

input = 8×1 int64 column vector

1
2

-2 1 0 -1 0 0

output = 0 1 3 0

      DataTypeMode: Fixed-point: binary point scaling
        Signedness: Signed
        WordLength: 66
    FractionLength: 0

[WLs,FLs] = getFixedPointInfo(cicD) %#ok

The output and section word lengths are the sum of input word length, 64 in this case, and the number of sections, 2. The output and section fraction lengths are 0 since the input is a built-in integer.

Minimum section word lengths

Release the object and change the FixedPointDataType property to "Minimum section word lengths". Determine the section and output fixed-point information when the input is fixed-point data, fi(randn(8,2),1,24,15).

release(cicD); cicD.FixedPointDataType = "Minimum section word lengths"

cicD = dsp.CICDecimator with properties:

  DecimationFactor: 2
 DifferentialDelay: 1
       NumSections: 2
FixedPointDataType: 'Minimum section word lengths'
  OutputWordLength: 32

inputF = fi(randn(8,2),1,24,15)

inputF = 3.5784 -0.1241 2.7694 1.4897 -1.3499 1.4090 3.0349 1.4172 0.7254 0.6715 -0.0630 -1.2075 0.7148 0.7172 -0.2050 1.6302

      DataTypeMode: Fixed-point: binary point scaling
        Signedness: Signed
        WordLength: 24
    FractionLength: 15

[WLs, FLs] = getFixedPointInfo(cicD,numerictype(inputF)) %#ok

Specify word and fraction lengths

Change the FixedPointDataType property to "Specify word and fraction lengths". Determine the fixed-point information using the getFixedPointInfo function.

cicD.FixedPointDataType = "Specify word and fraction lengths"

cicD = dsp.CICDecimator with properties:

      DecimationFactor: 2
     DifferentialDelay: 1
           NumSections: 2
    FixedPointDataType: 'Specify word and fraction lengths'
    SectionWordLengths: 16
SectionFractionLengths: 0
      OutputWordLength: 32
  OutputFractionLength: 0

[WLs, FLs] = getFixedPointInfo(cicD,numerictype(inputF)) %#ok

The section and output word lengths and fraction lengths are assigned as per the respective fixed-point properties of the cicD object. These values are not determined by the input numeric type. To confirm, call the getFixedPointInfo function without passing the numerictype input argument.

[WLs, FLs] = getFixedPointInfo(cicD) %#ok

Specify word lengths

To specify the word lengths of the filter section and output, set the FixedPointDataType property to "Specify word lengths".

cicD.FixedPointDataType = "Specify word lengths"

cicD = dsp.CICDecimator with properties:

  DecimationFactor: 2
 DifferentialDelay: 1
       NumSections: 2
FixedPointDataType: 'Specify word lengths'
SectionWordLengths: 16
  OutputWordLength: 32

The getFixedPointInfo function requires the input numeric type because that information is used to compute the section and word fraction lengths.

[WLs, FLs] = getFixedPointInfo(cicD,numerictype(inputF))

For more details on how the function computes the word and fraction lengths, see the description for Output Arguments.

More About

expand all

CIC filters are an optimized class of linear phase FIR filters composed of a comb part and an integrator part.

The CIC decimation filter is conceptually given by a single rate CIC filter, H(z) which is a lowpass anti-imaging filter, followed by a downsampler. The CIC decimation filter decreases the sample rate of an input signal by an integer factor using a cascaded integrator-comb (CIC) filter.

Generic CIC decimation filter containing the single rate CIC filter followed by a downsampler

In a more efficient implementation, the single rate CIC filter H(z) is factorized this way:

where,

In the overall multirate realization, the algorithm applies the noble identity for decimation and moves the rate change factor, R, to follow after the N sections of the cascaded integrators. The transfer function of the resulting filter is given by the following equation:

For a block diagram that shows the multirate implementation, see Algorithms.

The fixed-point signal diagram shows the data types that thedsp.CICDecimator object uses for fixed-point signals.

where,

The value of NumSections in this diagram is 2.

Algorithms

expand all

The CIC decimation filter in More About is realized as a cascade of N sections of the integrators followed by a rate change factor of R, followed by N sections of comb filters.

This diagram shows two sections of cascaded integrators and two sections of cascaded comb filters. The unit delay in the integrator portion of the CIC filter can be located in either the feedforward or the feedback path. These two configurations yield identical filter frequency response. However, the numerical outputs from these two configurations are different due to the latency. This block puts the unit delay in the feedforward path of the integrator because it is a preferred configuration for HDL implementation.

References

[1] Hogenauer, E.B. "An Economical Class of Digital Filters for Decimation and Interpolation." IEEE Transactions on Acoustics, Speech and Signal Processing. Volume 29, Number 2, 1981, 155–162.

[2] Meyer-Baese, U. Digital Signal Processing with Field Programmable Gate Arrays. New York: Springer, 2001.

[3] Harris, Fredric J.Multirate Signal Processing for Communication Systems. Indianapolis, IN: Prentice Hall PTR, 2004.

Extended Capabilities

expand all

For workflow and limitations, see HDL Code Generation for System Objects (HDL Coder).

Note

For a hardware-optimized CIC decimator algorithm that supports HDL code generation, use the dsphdl.CICDecimator (DSP HDL Toolbox) System object. This object has hardware-friendly valid and reset control signals, and models exact hardware latency behavior. The object supports HDL code generation with HDL Coder™ tools.

Version History

Introduced in R2012a

expand all

Starting in R2025a, the Filter Design HDL Coder™ product is discontinued. So, this object no longer supports HDL code generation by using the generatehdl function. The object still supports code generation using HDL Coder tools.

See Also

Functions

Objects

Blocks

Topics