Main Content

Configure Blocks with Fixed-Point Parameters

Certain Simulink®blocks allow you to specify fixed-point numbers as the values of parameters used to compute the block's output, for example, theGainparameter of aGainblock.

Note

S-functions and the Stateflow®Chart block do not support fixed-point parameters.

You can specify a fixed-point parameter value either directly by setting the value of the parameter to an expression that evaluates to afiobject, or indirectly by setting the value of the parameter to an expression that refers to a fixed-pointSimulink.Parameterobject.

Note

Simulating or performing data type override on a model withfiobjects requires a Fixed-Point Designer™ software license. SeeSharing Fixed-Point Modelsfor more information.

Specify Fixed-Point Values Directly

You can specify fixed-point values for block parameters usingfiobjects. In the block dialog's parameter field, simply enter the name of afiobject or an expression that includes theficonstructor function.

For example, entering the expression

fi(3.3,1,8,3)

as theConstant valueparameter for theConstantblock specifies a signed fixed-point value of 3.3, with a word length of 8 bits and a fraction length of 3 bits.

Specify Fixed-Point Values Via Parameter Objects

You can specify fixed-point parameter objects for block parameters using instances of theSimulink.Parameterclass. To create a fixed-point parameter object, either specify afi对象的对象作为参数Valueproperty, or specify the relevant fixed-point data type for the parameter object'sDataTypeproperty.

For example, suppose that you want to create a fixed-point constant in your model. You could do this using a fixed-point parameter object and aConstant块如下:

  1. Enter the following command at the MATLAB®prompt to create an instance of theSimulink.Parameterclass:

    my_fixpt_param = Simulink.Parameter
  2. Specify either the name of afiobject or an expression that includes theficonstructor function as the parameter object'sValueproperty:

    my_fixpt_param.Value = fi(3.3,1,8,3)

    Alternatively, you can set the parameter object'sValueandDataTypeproperties separately. In this case, specify the relevant fixed-point data type using aSimulink.AliasTypeobject, aSimulink.NumericTypeobject, or afixdtexpression. For example, the following commands independently set the parameter object's value and data type, using afixdtexpression as theDataType:

    my_fixpt_param.Value = 3.3; my_fixpt_param.DataType = 'fixdt(1,8,2^-3,0)'
  3. Specify the parameter object as the value of a block's parameter. For example,my_fixpt_paramspecifies theConstant valueparameter for theConstantblock in the following model:

    TheConstantblock outputs a signed fixed-point value of 3.3, with a word length of 8 bits and a fraction length of 3 bits.

Related Topics