Specify Behavioral Constraints
When converting a system to use fixed-point data types, use your system requirements to set signal tolerances and behavioral constraints on your model. The Fixed-Point Tool uses the information you provide to propose fixed-point data types that meet your requirements. After conversion, you can use signal tolerances and behavioral constraints to verify the numerical behavior of the fixed-point implementation.
In the Optimized Fixed-Point Conversion workflow of the
Fixed-Point Tool, or when using fxpopt at the
command line, you must specify at least one behavioral constraint using
signal tolerances or Model Verification blocks. Data types are optimized to
meet all specified constraints.
In the Iterative Fixed-Point Conversion workflow of the
Fixed-Point Tool, or when using DataTypeWorkflow.Converter at the command line, you can specify behavioral
constraints to improve data type proposals and verify the numerical behavior of the model with
embedded types. After simulating with embedded types, the Workflow
Browser indicates whether the embedded run meets the specified signal tolerances
compared to the range collection run. For more information, see Verify New Settings.
Specify Target Hardware
Specify details of your target device in the Hardware Implementation pane of the Configuration Parameters dialog box. The Fixed-Point Tool uses this information to propose fixed-point data types. For more information, see How the Fixed-Point Tool Uses Target Hardware Information.
Specify Design Minimum and Maximum Values
For elements in your system which have known ranges, or minimum or maximum range limits, enter these as known design ranges in your model. The Fixed-Point Tool prioritizes this information when proposing fixed-point data types. If necessary, you can also specify a safety margin in the Fixed-Point Tool. For more information, see How the Fixed-Point Tool Uses Range Information.
Specify Known Parameter Data Types
When using fxpopt to
optimize data types, you can specify known parameter data types. These known parameter data
types are not considered during range collection, and will not be changed during the
optimization process.
Lock Blocks Against Automatic Data Typing
You can choose to lock some blocks against automatic data typing by selecting the Lock output data type setting against changes by the fixed-point tools parameter for the block. For more information, see Use Lock Output Data Type Setting.
Create a Test Bench with Multiple Simulation Inputs
Create a thorough test bench for range collection and verification by using the
Simulink.SimlationInput object to specify multiple simulation scenarios.
Including simulation scenarios that cover the full range of real-world use cases can improve
data type proposals. During range collection, the Fixed-Point Tool merges the
results from these simulation runs and proposes data types based on the merged ranges. After
conversion to fixed point, you can use the simulation scenarios again to verify performance
of the model with embedded types applied.
For examples, see Use the Fixed-Point Tool to Explore Numerical Behavior, Propose Data Types for Merged Simulation Ranges, and Optimize Data Types Using Multiple Simulation Scenarios.
Specify Signal Tolerances
You can specify tolerances for signals in your model that have signal logging enabled. To enable signal logging:
In the Simulink® Editor, select one or more signals.
In the Signal tab of the Simulink Editor, click Log Signals.
In the Fixed-Point Tool, specify individual signal tolerances in the table
under Signal Tolerances. The table contains all signals in the model
with signal logging enabled. If you log additional signals after opening the
Fixed-Point Tool, click Refresh Signals to update the
Signal Tolerances table. At the command line, specify tolerances
using the addTolerance method.
You can specify any of the following types of tolerances:
Abs Tol — Absolute value of the maximum acceptable difference between the original signal and the signal in the converted design.
Rel Tol — Maximum relative difference, specified as a percentage, between the original signal and the signal in the converted design. For example, a value of
1e-2indicates a maximum relative difference of one percent.Time Tol (seconds) — Time interval, in which the maximum and minimum values define the upper and lower values to compare against.
Enter signal tolerances using any valid MATLAB® expression that returns a finite, non-negative value. (since R2023a)
You can define a tolerance band using any combination of absolute, relative, and time tolerance values. When you specify the tolerance for your signal using multiple types of tolerances, the overall tolerance band is computed by selecting the most lenient tolerance result for each data point. For more information about how tolerances are computed, see Tolerance Computation.
Use Model Verification Blocks
You can use enabled Model Verification blocks to specify custom behavioral constraints on the behavior of your system.
The blocks in the Model Verification library maintain a true (1)
assertion when a specified desired behavior is maintained by the input signals. The block
halts the simulation and returns an error message by default if the true
(1) assertion is not maintained. If a new fixed-point implementation is unable
to maintain a true (1) assertion for a Model Verification block during
simulation, that set of data types is considered infeasible for the model because it does
not meet the specified constraints.
All Model Verification blocks must be able to maintain a true (1)
assertion when the model is simulated with the floating-point data type selected for data
type override in order to establish a baseline for the model behavior.
The following examples use Model Verification blocks for data type optimization.
Optimize Data Types Using Multiple Simulation Scenarios contains a model that uses an Assertion block to verify that a boolean signal maintains a
true (1)value during simulation.Image Denoising Using Fixed-Point Quantized Restricted Boltzmann Machine Algorithm contains a model that uses a Check Static Range block to verify that the mean-squared error between two signals remains within a specified threshold.
See Also
Optimize Fixed-Point Data Types for a System