Main Content

dsphdl.CICDecimator

Decimate signal using CIC filter

Since R2019b

Description

Thedsphdl.CICDecimatorSystem object™ decimates an input signal by using a cascaded integrator-comb (CIC) decimation filter. CIC filters are a class of linear phase finite impulse response (FIR) filters consisting of a comb part and an integrator part. The CIC decimation filter structure consists ofNsections of cascaded integrators, a rate change factor ofR, andNsections of cascaded comb filters. For more information about CIC decimation filters, seeAlgorithms.

The System object supports these combinations of input and output data.

  • Scalar input and scalar output — Support for fixed and variable decimation rates

  • Vector input and scalar output — Support for fixed decimation rates only

  • Vector input and vector output — Support for fixed decimation rates only

The System object provides an architecture suitable for HDL code generation and hardware deployment.

The System object supports real and complex fixed-point inputs.

To filter input data with an HDL-optimized CIC decimation filter, follow these steps:

  1. Create thedsphdl.CICDecimatorobject and set its properties.

  2. Call the object with arguments, as if it were a function.

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

Creation

Description

cicDecFilt= dsphdl.CICDecimatorcreates an HDL-optimized CIC decimation filter System object,cicDecFilt,默认的ties.

example

cicDecFilt= dsphdl.CICDecimator(Name,Value)creates the filter with properties set using one or more name-value arguments. Enclose each property name in single quotes.

Properties

expand all

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

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

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

Specify whether the System object operates with a fixed or variable decimation rate.

  • 'Property'— Use a fixed decimation rate specified by theDecimationFactorproperty.

  • 'Input port'— Use a variable decimation rate specified by theRinput argument.

For vector inputs, the System object does not support a variable decimation rate.

Specify the decimation factor as an integer from 1 to 2048. This value gives the rate at which the System object decimates the input.

Dependencies

To enable this property, set theDecimationSourceproperty to'Property'.

Specify the upper bound of the range of valid values for theR输入参数为一个从1到2048的整数。

Note

For vector inputs, the System object does not support variable decimation.

Dependencies

To enable this property, set theDecimationSourceproperty to'Input port'.

Specify the differential delay of the comb part of the filter as either1or2cycles.

Specify the number of sections in either the integrator or the comb part of the System object.

Set this property totrueto compensate for the output gain of the filter.

The latency of the System object varies depending on the type of input, the decimation you specify, the number of sections, and the value of this property. For more information on the latency of the System object, seeLatency.

Choose the data type of the filtered output data.

  • 'Full precision'— The output data type has a word length equal to the input word length plus gain bits.

  • 'Same word length as input'— The output data type has a word length equal to the input word length.

  • 'Minimum section word lengths'— The output data type uses the word length you specify in theOutputWordLengthproperty. When you choose this option, the System object applies a pruning algorithm internally. For more information about pruning, seeOutput Data Type.

Word length of the output, specified as an integer from 2 to 104.

Note

When this value is2,3,4,5, or6, the System object can overflow the output data.

Dependencies

To enable this property, set theOutputDataTypeproperty to'Minimum section word lengths'.

When you set this property totrue, the System object expects aresetinput argument.

Usage

Description

[dataOut,validOut] = cicDecFilt(dataIn,validIn)filters and decimates the input data using a fixed decimation factor only whenvalidInistrue.

[dataOut,validOut] = cicDecFilt(dataIn,validIn,R)filters the input data using the specified variable decimation factorR. TheDecimationSourceproperty must be set to'Input port'.

[dataOut,validOut] = cicDecFilt(dataIn,validIn,reset)filters the input data whenresetisfalseand clears filter internal states whenresetistrue. The System object expects theresetargument only when you set theResetInputPortproperty totrue.

[dataOut,validOut] = cicDecFilt(dataIn,validIn,R,reset)filters the input data whenresetisfalseand clears filter internal states whenresetistrue. The System object expects theresetargument only when you set theResetInputPortproperty totrue. TheDecimationSourceproperty must be set to'Input port'.

Input Arguments

expand all

Specify input data as a scalar or a column vector with a length from 1 to 64. The input data must be a signed integer or signed fixed point with a word length less than or equal to 32. TheDecimationFactorproperty must be an integer multiple of the input frame size.

Data Types:int8|int16|int32|fi
Complex Number Support:Yes

Control signal that indicates if the input data is valid. WhenvalidInis1(true), the object captures the values from thedataInargument. WhenvalidInis0(false), the object ignores the values from thedataInargument.

Data Types:logical

Specify the decimation rate.

TheRvalue must have the data typefi(0,12,0)它必须是一个整数的范围从1到theMaxDecimationFactorproperty value.

Dependencies

To enable this argument, set theDecimationSourceproperty to'Input port'.

Data Types:fi(0,12,0)

Control signal that clears internal states. Whenresetis1(true), the object stops the current calculation and clears internal states. When theresetis0(false) and the inputvalidis1(true), the object captures data for processing.

For more reset considerations, see theReset Signalsection on theHardware Control Signalspage.

Dependencies

To enable this argument, set theResetInputPortproperty totrue.

Data Types:logical

Output Arguments

expand all

CIC-decimated output data, returned as a scalar or a column vector with a length from 1 to 64.

TheOutputDataTypeproperty sets the data type of this argument. SeeOutput Data Type.

Data Types:int8|int16|int32|fi
Complex Number Support:Yes

Control signal that indicates if the output data is valid. WhenvalidOutis1(true), the object returns valid data from thedataOutargument. WhenvalidOutis0(false), values from thedataOutargument are not valid.

Data Types:logical

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 namedobj, use this syntax:

release(obj)

expand all

getLatency Latency of CIC decimation filter
step RunSystem objectalgorithm
release Release resources and allow changes toSystem objectproperty values and input characteristics
reset Reset internal states ofSystem object

Examples

collapse all

This example shows how to use adsphdl.CICDecimatorSystem object™ to filter and downsample data. This object supports scalar and vector inputs. In this example, two functions are provided to work with scalar and vector inputs separately. You can generate HDL code from these functions.

Generate Frames of Random Input Samples

Set up workspace variables for the object to use. The object supports fixed and variable decimation rates for scalar inputs and only a fixed decimation rate for vector inputs. The example runs theHDLCIC_maxR8function when you set the scalar variable totrueand runs theHDLCIC_vecfunction when you set the scalar variable tofalse. For scalar inputs, choose a range of the inputvarRValuevalues and set the decimation factor valueRto the maximum expected decimation factor. For vector inputs, the input data must be a column vector of size 1 to 64 andRmust be an integer multiple of the input frame size.

R = 8;% decimation factorM = 1;% differential delayN = 3;% number of sectionsscalar = true;% true for scalar; false for vectorifscalar varRValue = [2, 4, 5, 6, 7, 8]; vecSize = 1;elsevarRValue = R;%#okfac = (factor(R)); vecSize = fac(randi(length(fac),1,1));endnumFrames = length(varRValue); dataSamples = cell(1,numFrames); varRtemp = cell(1,numFrames); framesize = zeros(1,numFrames); refOutput = []; WL = 0;% Word lengthFL = 0;% Fraction length

Generate Reference Output fromdsp.CICDecimatorSystem Object

Generate frames of random input samples and apply the samples to thedsp.CICDecimatorSystem object. Later in this example, you use the output generated by the System object as reference data for comparison. The System object does not support a variable decimation rate, so you must create and release the object for each change in decimation factor value.

totalsamples = 0;fori = 1:numFrames framesize(i) = varRValue(i)*randi([5 20],1,1); dataSamples{i} = fi(randn(vecSize,framesize(i)),1,16,8); ref_cic = dsp.CICDecimator('DifferentialDelay',M,...'NumSections',N,...'DecimationFactor',varRValue(i)); refOutput = [refOutput,ref_cic(dataSamples{i}(:)).'];%#okrelease(ref_cic);end

Run Function Containingdsphdl.CICDecimatorSystem Object

Set the properties of the System object to match the input data parameters and run the function for your input type. These functions operate on a stream of data samples rather than a frame. You can generate HDL code from these functions.

The example uses theHDLCIC_maxR8function for a scalar input.

function[dataOut,validOut] = HDLCIC_maxR8(dataIn,validIn,R)%HDLCIC_maxR8% Performs CIC decimation with an input decimation factor up to 8.% dataIn is a scalar fixed-point value.% validIn is a logical scalar value.persistentcic8;ifisempty(cic8) cic8 = dsphdl.CICDecimator('DecimationSource','Input port',...'MaxDecimationFactor',8,...'DifferentialDelay',1,...'NumSections',3);end[dataOut,validOut] = cic8(dataIn,validIn,R);end

The example uses theHDLCIC_vecfunction for a vector input.

function[dataOut,validOut] = HDLCIC_vec(dataIn,validIn)%HDLCIC_vec% Performs CIC decimation with an input vector.% dataIn is a fixed-point vector.% validIn is a logical scalar value.persistentcicVec;ifisempty(cicVec) cicVec = dsphdl.CICDecimator('DecimationSource','Property',...'DecimationFactor',8,...'DifferentialDelay',1,...'NumSections',3);end[dataOut,validOut] = cicVec(dataIn,validIn);end

To flush the remaining data, run the object by inserting the required number of idle cycles after each frame using thelatencyvariable. For more information, seeLatency.

Initialize the output to a size large enough to accommodate the output data. The final size is smaller thantotalsamplesdue to decimation.

latency = floor((vecSize - 1)*(N/vecSize)) + 1 + N + (2+(vecSize+1)*N) + 9; dataOut = zeros(1,totalsamples+numFrames*latency); validOut = zeros(1,totalsamples+numFrames*latency); idx=0;forij = 1:numFramesifscalar% scalar input with variable decimationforii = 1:length(dataSamples{ij}) idx = idx+1; [dataOut(idx),validOut(idx)] = HDLCIC_maxR8(...dataSamples{ij}(ii),...true,...fi(varRValue(ij),0,12,0));endforii = 1:latency idx = idx+1; [dataOut(idx),validOut(idx)] = HDLCIC_maxR8(...fi(0,1,16,8),...false,...fi(varRValue(ij),0,12,0));endelse% vector input with fixed decimationforii = 1:size(dataSamples{ij},2)%#okidx = idx+1; [dataOut(idx),validOut(idx)] = HDLCIC_vec(...dataSamples{ij}(:,ii),...true);endforii = 1:latency idx = idx+1; [dataOut(idx),validOut(idx)] = HDLCIC_vec(...fi(zeros(vecSize,1),1,16,8),...false);endendend

Compare Function Output with Reference Data

Compare the function results against the output from thedsp.CICDecimatorobject.

cicOutput = dataOut(validOut==1); fprintf('\nCIC Decimator\n'); difference = (abs(cicOutput-refOutput(1:length(cicOutput)))>0); fprintf(['\nTotal number of samples differed between Behavioral '...'and HDL simulation: %d \n'],sum(difference));
CIC Decimator Total number of samples differed between Behavioral and HDL simulation: 0

The latency of thedsphdl.CICDecimatorSystem object™ varies depending on how many integrator and comb sections your filter has, the input vector size, and whether you enable gain correction. Use thegetLatencyfunction to find the latency of a particular filter configuration. The latency is the number of cycles between the first valid input and the first valid output, assuming the input is continuously valid.

Create adsphdl.CICDecimatorSystem object and request the latency. The default System object filter has two integrator and comb sections, and the gain correction is disabled.

hdlcic = dsphdl.CICDecimator
hdlcic = dsphdl.CICDecimator with properties: DecimationSource: 'Property' DecimationFactor: 2 DifferentialDelay: 1 NumSections: 2 GainCorrection: false Show all properties
L_def = getLatency(hdlcic)
L_def = 5

Modify the filter object so it has three integrator and comb sections. Check the resulting change in latency.

hdlcic.NumSections = 3; L_3sec = getLatency(hdlcic)
L_3sec = 6

Enable the gain correction on the filter object with vector input size 2. Check the resulting change in latency.

hdlcic.GainCorrection = true; vecSize = 2; L_wgain = getLatency(hdlcic,vecSize)
L_wgain = 25

Algorithms

expand all

References

[1] Hogenauer, E. “An Economical Class of Digital Filters for Decimation and Interpolation.”IEEE Transactions on Acoustics, Speech, and Signal Processing29, no. 2 (April 1981): 155–62. https://doi.org/10.1109/TASSP.1981.1163535.

Extended Capabilities

Version History

Introduced in R2019b

expand all