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 afi
object, or indirectly by setting the value of the parameter to an expression that refers to a fixed-pointSimulink.Parameter
object.
Note
Simulating or performing data type override on a model withfi
objects 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 usingfi
objects. In the block dialog's parameter field, simply enter the name of afi
object or an expression that includes thefi
constructor 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.Parameter
class. To create a fixed-point parameter object, either specify afi
对象的对象作为参数Value
property, or specify the relevant fixed-point data type for the parameter object'sDataType
property.
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块如下:
Enter the following command at the MATLAB®prompt to create an instance of the
Simulink.Parameter
class:my_fixpt_param = Simulink.Parameter
Specify either the name of a
fi
object or an expression that includes thefi
constructor function as the parameter object'sValue
property:my_fixpt_param.Value = fi(3.3,1,8,3)
Alternatively, you can set the parameter object's
Value
andDataType
properties separately. In this case, specify the relevant fixed-point data type using aSimulink.AliasType
object, aSimulink.NumericType
object, or afixdt
expression. For example, the following commands independently set the parameter object's value and data type, using afixdt
expression as theDataType
:my_fixpt_param.Value = 3.3; my_fixpt_param.DataType = 'fixdt(1,8,2^-3,0)'
Specify the parameter object as the value of a block's parameter. For example,
my_fixpt_param
specifies 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.