## Specify Fixed-Point Attributes for Blocks

### Fixed-Point Block Parameters

Toolbox blocks that have fixed-point support usually allow you to specify fixed-point characteristics through block parameters. By specifying data type and scaling information for these fixed-point parameters, you can simulate your target hardware more closely.

**Note**

Floating-point inheritance takes precedence over the settings discussed in this section. When the block has floating-point input, all block data types match the input.

You can find most fixed-point parameters on the **Data
Types** pane of toolbox blocks. The following figure shows a typical
**Data Types** pane.

All toolbox blocks with fixed-point capabilities share a set of common parameters, but each block can have a different subset of these fixed-point parameters. The following table provides an overview of the most common fixed-point block parameters.

Fixed-Point Data Type Parameter | Description |
---|---|

Rounding Mode | Specifies the rounding mode for the block to use when the specified data type and scaling cannot exactly represent the result of a fixed-point calculation. See Rounding Modes for more information on the available options. |

Saturate on integer overflow | When you select this parameter, the block saturates the result of its fixed-point operation. When you clear this parameter, the block wraps the result of its fixed-point operation. For details on saturate and wrap, see Overflow Handling for fixed-point operations. |

Intermediate Product | Specifies the data type and scaling of the intermediate product for fixed-point blocks. Blocks that feed multiplication results back to the input of the multiplier use the intermediate product data type. See the reference page of a specific block to learn about the intermediate product data type for that block. |

Product Output | Specifies the data type and scaling of the product output for fixed-point blocks that must compute multiplication results. See the reference page of a specific block to learn about the product output data type for that block. For or complex-complex multiplication, the multiplication result is in the accumulator data type. See Multiplication Data Types for more information on complex fixed-point multiplication in toolbox software. |

Accumulator | Specifies the data type and scaling of the accumulator (sum) for fixed-point blocks that must hold summation results for further calculation. Most such blocks cast to the accumulator data type before performing the add operations (summation). See the reference page of a specific block for details on the accumulator data type of that block. |

Output | Specifies the output data type and scaling for blocks. |

#### Using the Data Type Assistant

The **Data Type Assistant** is an interactive graphical tool
available on the **Data Types** pane of some Fixed-Point Designer™ blocks.

To learn more about using the **Data Type Assistant** to help
you specify block data type parameters, see Specify Data Types Using Data Type Assistant (Simulink).

#### Checking Signal Ranges

Some Fixed-Point Designer blocks have **Minimum** and
**Maximum** parameters on the **Data
Types** pane. When a fixed-point data type has these parameters,
you can use them to specify appropriate minimum and maximum values for range
checking purposes.

To learn how to specify signal ranges and enable signal range checking, see Specify Signal Ranges (Simulink).

### Specify System-Level Settings

You can monitor and control fixed-point settings for Fixed-Point Designer blocks at a system or subsystem level with the Fixed-Point Tool. For
more information, see **Fixed-Point Tool (Fixed-Point Designer)**.

#### Logging

The Fixed-Point Tool logs overflows, saturations, and simulation minimums and
maximums for Fixed-Point Designer blocks. The Fixed-Point Tool does not log overflows and
saturations when the `Data overflow`

line in the
**Diagnostics > Data Integrity** pane of the
Configuration Parameters dialog box is set to
`None`

.

#### Autoscaling

You can use the Fixed-Point Tool autoscaling feature to set the scaling for toolbox fixed-point data types.

#### Data type override

Toolbox blocks obey the `Use local settings`

,
`Double`

, `Single`

, and
`Off`

modes of the **Data type
override** parameter in the Fixed-Point Tool. The
`Scaled double`

mode is also supported for
toolboxes source and byte-shuffling blocks, and for some arithmetic blocks such
as Difference and Normalization.

Scaled double is a double data type that retains fixed-point scaling information. Using the data type override, you can convert your fixed-point data types to scaled doubles. You can then simulate to determine the ideal floating-point behavior of your system. After you gather that information, you can turn data type override off to return to fixed-point data types, and your quantities still have their original scaling information because it was held in the scaled double data types.

### Inherit via Internal Rule

Selecting appropriate word lengths and scalings for the fixed-point parameters in
your model can be challenging. To aid you, an ```
Inherit via internal
rule
```

choice is often available for fixed-point block data type
parameters, such as the **Accumulator** and **Product
output** signals. The following sections describe how the word and
fraction lengths are selected for you when you choose ```
Inherit via
internal rule
```

for a fixed-point block data type parameter in
toolbox software:

**Note**

In the equations in the following sections, *WL* = word
length and *FL* = fraction length.

#### Internal Rule for Accumulator Data Types

The internal rule for accumulator data types first calculates the ideal,
full-precision result. Where *N* is the number of
addends:

$$W{L}_{idealaccumulator}=W{L}_{inputtoaccumulator}+\mathrm{floor}({\mathrm{log}}_{2}(N-1))+1$$

$$F{L}_{idealaccumulator}=F{L}_{inputtoaccumulator}$$

For example, consider summing all the elements of a vector of length 6 and data type sfix10_En8. The ideal, full-precision result has a word length of 13 and a fraction length of 8.

The accumulator can be real or complex. The preceding equations are used for both the real and imaginary parts of the accumulator. For any calculation, after the full-precision result is calculated, the final word and fraction lengths set by the internal rule are affected by your particular hardware. See The Effect of the Hardware Implementation Pane on the Internal Rule for more information.

#### Internal Rule for Product Data Types

The internal rule for product data types first calculates the ideal, full-precision result:

$$W{L}_{idealproduct}=W{L}_{input1}+W{L}_{input2}$$

$$F{L}_{idealproduct}=F{L}_{input1}+F{L}_{input2}$$

For example, multiplying together the elements of a real vector of length 2 and data type sfix10_En8. The ideal, full-precision result has a word length of 20 and a fraction length of 16.

For real-complex multiplication, the ideal word length and fraction length is used for both the complex and real portion of the result. For complex-complex multiplication, the ideal word length and fraction length is used for the partial products, and the internal rule for accumulator data types described above is used for the final sums. For any calculation, after the full-precision result is calculated, the final word and fraction lengths set by the internal rule are affected by your particular hardware. See The Effect of the Hardware Implementation Pane on the Internal Rule for more information.

#### Internal Rule for Output Data Types

A few toolbox blocks have an ```
Inherit via internal
rule
```

choice available for the block output. The internal rule
used in these cases is block-specific, and the equations are listed in the block
reference page.

As with accumulator and product data types, the final output word and fraction lengths set by the internal rule are affected by your particular hardware, as described in The Effect of the Hardware Implementation Pane on the Internal Rule.

#### The Effect of the Hardware Implementation Pane on the Internal Rule

The internal rule selects word lengths and fraction lengths that are
appropriate for your hardware. To get the best results using the internal rule,
you must specify the type of hardware you are using on the **Hardware
Implementation** pane of the Configuration Parameters dialog
box. To open this dialog box, click **Modeling** >
**Model Settings** in the Simulink^{®} toolstrip.

**ASIC/FPGA. **On an ASIC/FPGA target, the ideal, full-precision word length and fraction
length calculated by the internal rule are used. If the calculated ideal
word length is larger than the largest allowed word length, you receive an
error.

**Other Targets. **For all targets other than ASIC/FPGA, the ideal, full-precision word
length calculated by the internal rule is rounded up to the next available
word length of the target. The calculated ideal fraction length is used,
keeping the least-significant bits.

If the calculated ideal word length for a product data type is larger than the largest word length on the target, you receive an error. If the calculated ideal word length for an accumulator or output data type is larger than the largest word length on the target, the largest target word length is used.

The largest word length allowed for Simulink and toolbox software on any target is 128 bits.

#### Internal Rule Examples

For examples of how the internal rule interacts with the **Hardware
Implementation** pane to calculate accumulator data types and
product data types, see Accumulator Data
Types (DSP System Toolbox) and Product Data Types (DSP System Toolbox).

### Specify Data Types for Fixed-Point Blocks

For an example that shows how to select appropriate data types for fixed-point blocks using the Fixed-Point Tool, see Specify Data Types for Fixed-Point Blocks (DSP System Toolbox).