configure blocks with fixed-凯发k8网页登录

main content

configure blocks with fixed-point output

to create a fixed-point model, configure simulink® blocks to output fixed-point signals. simulink blocks that support fixed-point output provide parameters that allow you to specify whether a block should output fixed-point signals and, if so, the size, scaling, and other attributes of the fixed-point output. these parameters typically appear on the signal attributes pane of the block's parameter dialog box.

block parameters dialog for gain block with signal attributes pane selected.

the following sections explain how to use these parameters to configure a block for fixed-point output.

specify the output data type and scaling

many simulink blocks allow you to specify an output data type and scaling using a parameter that appears on the block dialog box. this parameter (typically named output data type) provides a pull-down menu that lists the data types a particular block supports. in general, you can specify the output data type as a rule that inherits a data type, a built-in data type, an expression that evaluates to a data type, or a simulink data type object. for more information, see .

the fixed-point designer™ software enables you to configure simulink blocks with:

  • fixed-point data types

    fixed-point data types are characterized by their word size in bits and by their binary point — the means by which fixed-point values are scaled.

  • floating-point data types

    floating-point data types are characterized by their sign bit, fraction (mantissa) field, and exponent field.

to configure blocks with fixed-point designer data types, specify the data type parameter on a block dialog box as an expression that evaluates to a data type. alternatively, you can use an assistant that simplifies the task of entering data type expressions (see specify fixed-point data types with the data type assistant). the sections that follow describe varieties of fixed-point and floating-point data types and example of how to specify these types by using the function. the fixdt function also allows you to specify scaling for fixed-point data types.

integers

to configure a 16-bit unsigned integer via the block dialog box, specify the output data type parameter as fixdt(0,16,0). to configure a 16-bit signed integer, specify the output data type parameter as fixdt(1,16,0).

for integer data types, the default binary point is assumed to lie to the right of all bits.

fractional numbers

to configure the output as a 16-bit unsigned fractional number via the block dialog box, specify the output data type parameter to be fixdt(0,16,16). to configure a 16-bit signed fractional number, specify output data type to be fixdt(1,16,15).

fractional numbers are distinguished from integers by their default scaling. whereas signed and unsigned integer data types have a default binary point to the right of all bits, unsigned fractional data types have a default binary point to the left of all bits, while signed fractional data types have a default binary point to the right of the sign bit.

both unsigned and signed fractional data types support guard bits, which act to guard against overflow. for example, fixdt(1,16,11) specifies a 16-bit signed fractional number with 4 guard bits. the guard bits lie to the left of the default binary point.

generalized fixed-point numbers

to configure the output as a 16-bit unsigned generalized fixed-point number via the block dialog box, specify the output data type parameter to be fixdt(0,16). to configure a 16-bit signed generalized fixed-point number, specify output data type to be fixdt(1,16).

generalized fixed-point numbers are distinguished from integers and fractionals by the absence of a default scaling. for these data types, a block typically inherits its scaling from another block.

floating-point numbers

the fixed-point designer software supports single-precision and double-precision floating-point numbers as defined by the ieee® standard 754–1985 for binary floating-point arithmetic.

to configure the output as a single-precision floating-point number via the block dialog box, specify the output data type parameter as fixdt('single'). to configure a double-precision floating-point number, specify output data type as fixdt('double').

specify fixed-point data types with the data type assistant

the data type assistant is an interactive graphical tool that simplifies the task of specifying data types for simulink blocks and data objects. the assistant appears on block and object dialog boxes, adjacent to parameters that provide data type control, such as the output data type parameter. for more information about accessing and interacting with the assistant, see .

you can use the data type assistant to specify a fixed-point data type. when you select fixed point in the mode field, the assistant displays fields for describing additional attributes of a fixed-point data type, as shown in this example:

block parameters dialog for constant block with signal attributes pane selected and the data type assistant expanded.

you can set the following fixed-point attributes:

signedness

select whether you want the fixed-point data to be signed or unsigned. signed data can represent positive and negative quantities. unsigned data represents positive values only.

word length

specify the size (in bits) of the word that will hold the quantized integer. large word sizes represent large quantities with greater precision than small word sizes. fixed-point word sizes up to 128 bits are supported for simulation.

scaling

specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors. you can select the following scaling modes:

scaling modedescription
binary point

if you select this mode, the assistant displays the fraction length field, specifying the binary point location.

binary points can be positive or negative integers. a positive integer moves the binary point left of the rightmost bit by that amount. for example, an entry of 2 sets the binary point in front of the second bit from the right. a negative integer moves the binary point further right of the rightmost bit by that amount.

schematic diagram of a 16 bit binary word.

see for more information.

slope and bias

if you select this mode, the assistant displays fields for entering the slope and bias.

  • slope can be any positive real number.

  • bias can be any real number.

see for more information.

best precision

if you select this mode, the block scales a constant vector or matrix such that the precision of its elements is maximized. this mode is available only for particular blocks.

see for more information.

calculate best-precision scaling

the fixed-point designer software can automatically calculate “best-precision” values for both binary point and slope and bias scaling, based on the values that you specify for other parameters on the dialog box. to calculate best-precision-scaling values automatically, enter values for the block's output minimum and output maximum parameters. then click the calculate best-precision scaling button in the assistant.

rounding

you specify how fixed-point numbers are rounded with the integer rounding mode parameter. the following rounding modes are supported:

  • ceiling — this mode rounds toward positive infinity and is equivalent to the matlab® ceil function.

  • convergent — this mode rounds toward the nearest representable number, with ties rounding to the nearest even integer. convergent rounding is equivalent to the fixed-point designer convergent function.

  • floor — this mode rounds toward negative infinity and is equivalent to the matlab floor function.

  • nearest — this mode rounds toward the nearest representable number, with the exact midpoint rounded toward positive infinity. rounding toward nearest is equivalent to the fixed-point designer nearest function.

  • round — this mode rounds to the nearest representable number, with ties for positive numbers rounding in the direction of positive infinity and ties for negative numbers rounding in the direction of negative infinity. this mode is equivalent to the fixed-point designer round function.

  • simplest — this mode automatically chooses between round toward floor and round toward zero to produce generated code that is as efficient as possible.

  • zero — this mode rounds toward zero and is equivalent to the matlab fix function.

for more information about each of these rounding modes, see .

overflow handling

to control how overflow conditions are handled for fixed-point operations, use the saturate on integer overflow check box.

if this box is selected, overflows saturate to either the maximum or minimum value represented by the data type. for example, an overflow associated with a signed 8-bit integer can saturate to -128 or 127.

if this box is not selected, overflows wrap to the appropriate value that is representable by the data type. for example, the number 130 does not fit in a signed 8-bit integer, and would wrap to -126.

lock the output data type setting

if the output data type is a generalized fixed-point number, you have the option of locking its output data type setting by selecting the lock output data type setting against changes by the fixed-point tools check box.

when locked, the fixed-point tool and automatic scaling script do not change the output data type setting. otherwise, the fixed-point tool and autofixexp script are free to adjust the output data type setting.

real-world values versus stored integer values

you can configure blocks to treat signals as real-world values or as stored integers with the input and output to have equal parameter.

block parameters dialog for data type conversion block. the input and output to have equal is set to real world value (rwv).

the possible values are real world value (rwv) and stored integer (si).

in terms of the variables defined in , the real-world value is given by v and the stored integer value is given by q. you may want to treat numbers as stored integer values if you are modeling hardware that produces integers as output.

related topics

    网站地图