Contenuto principale

realizeModel

R2026b

Create Simulink block equivalent of CIC rate conversion and FIR filter objects

Since R2024a

Description

realizeModel(sysObj) generates a Simulink® library block equivalent of the dsp.CICDecimator, dsp.CICInterpolator, and dsp.FIRFilter objects. The properties and values of these objects define the parameters of the resulting block.

Depending on the input filter object, realizeModel generates one of the following:

  • A CIC Decimation block or an equivalent subsystem built from elementary operations for a dsp.CICDecimator object. This option requires a Fixed-Point Designer™ license.

  • A CIC Interpolation block or an equivalent subsystem built from elementary operations for a dsp.CICInterpolator object. This option requires a Fixed-Point Designer license.

  • A Discrete FIR Filter (Simulink) block or an equivalent subsystem built from elementary operations for a dsp.FIRFilter object. This option requires a Fixed-Point Designer license. (since R2026b)

example

realizeModel(sysObj,Name=Value) generates a Simulink library block for the input filter object with additional options specified by one or more name-value arguments.

The value of the UseLibraryBlocks argument determines how the function implements the realized block. The value of this argument is true by default, so the function generates the library block equivalent of the object with default settings. If you set the UseLibraryBlocks argument to false, the function generates a subsystem equivalent using the Add (Simulink), Delay (Simulink), Gain (Simulink), and Data Type Conversion (Simulink) blocks. To model rate conversion operations, the function uses the Downsample and Upsample blocks.

Use the name-value arguments to control how the function generates the equivalent Simulink implementation. You can use these arguments to customize the block name, destination, and even optimize the block structure.

example

Examples

collapse all

Create a dsp.CICDecimator object with custom fixed-point settings.

cicDecim = dsp.CICDecimator(5,2,3,...
    FixedPointDataType="Specify word lengths",...
    SectionWordLengths=18*ones(1,6))
cicDecim = 
  dsp.CICDecimator with properties:

      DecimationFactor: 5
     DifferentialDelay: 2
           NumSections: 3
    FixedPointDataType: 'Specify word lengths'
    SectionWordLengths: [18 18 18 18 18 18]
      OutputWordLength: 32

Realize the equivalent library block by using the realizeModel function. Because the value of the UseLibraryBlocks argument is true by default, the function creates a block named Filter and adds it to a new Simulink model.

realizeModel(cicDecim)

CICDecimator Simulink library block with In and Out ports

When you click this block, you can see that the equivalent implementation uses a Data Type Conversion block and a CIC Decimation block.

library_implementation.png

Call the realizeModel function again and set the UseLibraryBlocks argument to false.

The function generates a new subsystem block named Filter1 and adds this block to the existing model. To change the block name, set BlockName to a custom name.

realizeModel(cicDecim,UseLibraryBlocks=false,BlockName="Subsystem")

When you click this block, you can see that the equivalent implementation contains a series of Add, Delay, and Data Type Conversion blocks. To implement the rate conversion, the model uses a Downsample block.

subsystem_implementation.png

Create a dsp.CICInterpolator object with custom fixed-point settings.

cicInterp = dsp.CICInterpolator(5,6,2,...
    FixedPointDataType="Specify word lengths",...
    SectionWordLengths=[20 22 18 16])
cicInterp = 
  dsp.CICInterpolator with properties:

    InterpolationFactor: 5
      DifferentialDelay: 6
            NumSections: 2
     FixedPointDataType: 'Specify word lengths'
     SectionWordLengths: [20 22 18 16]
       OutputWordLength: 32

Realize the equivalent library block by using the realizeModel function. Use the Destination name-value argument to place this block in an existing model. Then, specify the block name, input processing type, and the rate options.

new_system("cicInterpolationModel")
realizeModel(cicInterp,Destination="cicInterpolationModel",...
    UseLibraryBlocks=true,BlockName='CIC Interpolator Subsystem',...
    InputProcessing="Sample based",RateOptions="multirate");

cicInterpolationModel model containing the CIC Interpolator Subsystem block

Click the CIC Interpolator Subsystem block.

cicInterpolation_subsystem.png

Open the CIC Interpolation block dialog box. The block dialog box is populated according to the settings of the dsp.CICInterpolator object and the realizeModel function.

blockdialog.png

The Input Quantizer block casts the input data to the fixdt(1,16,15) data type by default. You can customize this data type by passing a custom fixed-point input signal to the dsp.CICInterpolator object.

Create fixed-point data with a word length of 21 and a fraction length of 12. Pass this data to the dsp.CICInterpolator object.

u = fi(ones(5,1),1,21,12);
y = cicInterp(u);

Now, realize the model again. Specify a new name to this block.

realizeModel(cicInterp,Destination="cicInterpolationModel",...
    UseLibraryBlocks=true,BlockName='Custom Input Type',...
    InputProcessing="Sample based",RateOptions="multirate")

cicInterpolationModel model containing the CIC Interpolator Subsystem and Custom Input Type blocks

Click the Custom Input Type > Input Quantizer block. You can see that this block now casts the input data to fixdt(1,21,12), which is the data type of the input data.

Since R2026b

Create a fixed-point Simulink® block equivalent of a dsp.FIRFilter object with filter coefficients mapped to an input port. Mapping coefficients to an input port enables you to update the filter coefficients at run time during simulation.

Design a 30th-order lowpass FIR filter with a normalized cutoff frequency of 0.4 and create a dsp.FIRFilter object.

firFilt = designLowpassFIR(FilterOrder=30,...
    CutoffFrequency=0.4,SystemObject=true)
firFilt = 
  dsp.FIRFilter with properties:

            Structure: 'Direct form'
      NumeratorSource: 'Property'
            Numerator: [-1.2498e-18 -0.0020 -0.0017 0.0026 0.0064 -4.8429e-18 -0.0134 -0.0115 0.0157 0.0345 -1.2029e-17 -0.0643 -0.0570 0.0900 0.3003 0.4008 0.3003 0.0900 -0.0570 -0.0643 -1.2029e-17 0.0345 0.0157 -0.0115 -0.0134 … ] (1×31 double)
    InitialConditions: 0

  Show all properties

Set the coefficients data type of the object to "custom". Optionally, specify the CustomCoefficientsDataType.

firFilt.CoefficientsDataType = "Custom";

Create a new Simulink model to hold the realized block.

new_system("firTunableCoeffModel")

Realize the filter as a fixed-point Simulink block with coefficients mapped to an input port. Set the CoefficientNames argument to specify the name of the coefficient port variable in the model workspace.

realizeModel(firFilt,...
    Destination="firTunableCoeffModel",...
    Arithmetic="fixed",...
    MapCoefficientsToPorts=true,...
    CoefficientNames={'MyCoeffs'})

Open the model to see the realized block. The block has an input port named MyCoeffs that accepts filter coefficients at run time.

load_system("firTunableCoeffModel")
simulinkScreenshot("firTunableCoeffModel/FIRFilter")

Figure Screenshot: firTunableCoeffModel/FIRFilter contains an axes object. The hidden axes object contains an object of type image.

Input Arguments

collapse all

Input filter System object™, specified as one of these:

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: c = dsp.CICDecimator; realizeModel(c,UseLibraryBlocks=false,Optimize=true);

Implementation of the realized model, specified as one of these options:

  • true –– The function generates a library block equivalent of the input filter object.

  • false –– The function generates a subsystem equivalent of the input filter object. The function implements the filter object using the Add (Simulink), Delay (Simulink), Gain (Simulink), and Data Type Conversion (Simulink) blocks. To model the rate conversion operations, the function uses the Downsample and Upsample blocks.

Data Types: logical

Target Simulink model to which the function adds the realized block, specified as one of these options:

  • "current" –– Add the block to your current Simulink model.

  • "new" –– Add the block to a new Simulink model.

  • Character vector or string scalar –– Add the block to the specified model or subsystem that already exists.

Data Types: char | string

Name of the block that the realizeModel function creates, specified as a character vector or a string scalar.

Depending on the input filter object, realizeModel names the block as one of the following:

If a block with this name already exists in the specified destination, the function updates the name to FIRFilter#, CICInterpolator#, or CICDecimator#.

Data Types: char | string

Option to overwrite existing block, specified as one of these options:

  • false –– Create a new block.

  • true –– Overwrite an existing block with the same name.

Data Types: logical

Since R2026b

Filter arithmetic of the realized block, specified as one of these:

  • "single"

  • "double"

  • "fixed"

If you do not specify the Arithmetic property, and if the input filter object is locked with data of a specific arithmetic type, the realizeModel function uses the arithmetic of this data.

If you do not specify the Arithmetic property, and if the input filter object is not locked with any data, the realizeModel function uses the double arithmetic.

Dependencies

This property applies only if the input filter object is a dsp.FIRFilter object.

Data Types: char | string

Since R2026b

Option to map filter coefficients to block ports, specified as one of these:

  • false — Do not create coefficient input ports.

  • true — Create coefficient input ports, enabling you to update the filter coefficients during simulation. Use the CoefficientNames argument to specify the names of the coefficient ports.

This argument applies only when the input filter object is a dsp.FIRFilter object.

Data Types: logical

Since R2026b

Variable name for coefficient port of the block, specified as a cell array containing one character vector.

Dependencies

To enable this property, set the MapCoefficientsToPorts property to true.

This property applies only if the input filter object is a dsp.FIRFilter object.

Data Types: char | string

Optimize elementary operations in the block implementation, specified as one of these options if the input filter is a dsp.FIRFilter object:

  • "zeros" — Remove zero-gain blocks.

  • "ones" — Replace unity-gain blocks with direct connections.

  • "negative-ones" — Replace negative unity-gain blocks with a sign change at the nearest sum block.

  • "delay-chains" — Replace delay chains made up of n unit delays with a single delay by n.

  • "all" — Apply all the above optimizations.

  • "none" — Do not apply any optimization.

(since R2026b)

If the input filter is a dsp.CICDecimator or a dsp.CICInterpolator object, set this property to true or false to enable or disable the optimization.

Dependencies

To use this argument, set UseLibraryBlocks to false.

Data Types: logical | char | string

Method to process input signals, specified as one of these options:

  • "frame-based" –– The block treats each column of the input signal as a separate channel. In this mode, the block always performs single-rate processing.

  • "sample-based" –– The block treats each element of the input signal as a separate channel. In this mode, the input to the block must be a scalar or a vector. You can use the RateOption property to specify whether the block performs single-rate or multirate processing.

Dependencies

To use this property,

Method to adjust the output rate to accommodate the change in number of output samples, specified as one of these options:

  • "single-rate" –– The block maintains the sample rate of the input.

  • "multirate" –– The block produces an output with a sample rate that is R times faster than the input sample rate. To select this option, you must set the InputProcessing property to "sample-based".

Dependencies

To use this property,

Version History

Introduced in R2024a

expand all