Specify Behavioral Constraints
To determine if the numerical behavior of a new fixed-point implementation is acceptable, define constraints by setting signal tolerances, by using one or more model verification blocks, or both.
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. 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 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 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-2
indicates 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 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