Convert a floating-point model to a fixed-point model
Simulink Toolstrip: On theAppstab, underCode Generation, click the app icon.
MATLAB command prompt: Enterfxptdlg
('system_name')
, where'system_name'
is the name of the model or system you want to convert, specified as a string.
System Under Design (SUD)
— System or subsystem to analyze or convertSystem or subsystem to analyze or convert to fixed-point. You can select individual subsystems in your model one at a time to facilitate debugging by isolating the source of numerical issues, or you can choose the top-level model.
For more information on converting systems containing particular modeling constructs, see:
Range Collection Mode
— How the tool collects ranges for objects in your systemHow the tool collects ranges for objects in your system, specified as one of the following:
Simulation ranges— Collect ranges through simulation. To collect and merge the ranges of multiple simulation runs, specifySimulation Inputs. Data type proposals are as good as the test bench provided.
Derived ranges— Collect ranges through a static analysis that derives the ranges, also known asrange analysisorderived range analysis. Ranges collected using this option are based only on design ranges specified on the model. This option typically delivers more conservative data type proposals. For more information, seeHow Range Analysis Works.
Simulation with derived ranges— Collect ranges through simulation and derived range analysis and combine the results. Proposed data types are based on the union of simulation and derived ranges. This option provides the most comprehensive range information.
For more information, seeChoosing a Range Collection Method.
Simulation Inputs
— Inputs for simulations使用默认模型的输入
(default) |Simulink.SimulationInput
objectInputs for simulations, specified as aSimulink.SimulationInput
object.
If you choose theRange Collection Modeto beSimulation rangesorSimulation with derived ranges, you can choose to specify additional simulation inputs to improve the accuracy of the collected ranges and data type proposals. During the range collection simulation, theFixed-Point Toolcaptures the minimum and maximum values from each specified simulation scenario. If theSimulink.SimulationInput
object that you select contains more than one simulation scenario, theFixed-Point Toolproposes data types based on the merged ranges from all simulation scenarios.
A comprehensive set of input signals that exercise the full range of your design will result in more accurate data type proposals for your system. For an example, seePropose Data Types For Merged Simulation Ranges.
Signal Tolerances
— Tolerances for signals in your model that have signal logging enabled确定的数值行为新的fixed-point implementation is acceptable, you can define tolerances for individual signals in your model that have logging enabled. You can specify any of the following types of tolerances:
Absolute Tolerance— Absolute value of the maximum acceptable difference between the original signal and the signal in the converted design.
Relative Tolerance— Maximum relative difference, specified as a percentage, between the original output and the output of the new design. For example, a value of1e-2
indicates a maximum difference of one percent between the original values and the signal values of the converted design.
Time Tolerance (seconds)— Time interval in which the maximum and minimum values define the upper and lower values to compare against.
In theOptimized Fixed-Point Conversionworkflow, you must specify at least one behavioral constraint in order to optimize data types. Signal tolerances are one type of behavioral constraint that you can specify.
In theIterative Fixed-Point Conversionworkflow, signal tolerances are not required to propose data types, but are required for the tool to determine whether the embedded run is within tolerance.
In theRange Collectionworkflow, signal tolerances are not required to collect ranges, but are required for the tool to determine whether the ranges collected are within tolerance.
For more information, seeSpecify Behavioral ConstraintsandTolerance Computation.
Collect Ranges
— Collect rangesUse current settings
(default) |Double precision
|Single precision
|Scaled double precision
Collect ranges for objects in your model using:
Use current settings
— Use the current data type override set on the model.
Double precision
— Override data types in the model with doubles.
Single precision
— Override data types in the model with singles.
Scaled double precision
— Override data types in the model with scaled doubles.
Ranges collected depend on theRange Collection Modeand anySimulation Inputsspecified.
For more information, seeFixed-Point Instrumentation and Data Type OverrideandUse Custom Data Type Override Settings for Range Collection.
Settings
— Data typing optionsAllowable Wordlengths
|Max Iterations
|Propose
|Propose signedness
|Verify using
| ...Data typing options available in theSettingsmenu depend on the workflow chosen.
Optimized Fixed-Point Conversion Workflow Options
Option | Description |
---|---|
Allowable Wordlengths |
Word lengths that can be used in your optimized system under design. The final result of the optimization uses word lengths in the intersection of the |
Max Iterations |
Maximum number of iterations to perform, specified as a scalar integer. The optimization process iterates through different solutions until it finds an ideal solution, reaches the maximum number of iterations, or reaches another stopping criteria. |
Max Time (sec) |
Maximum amount of time for the optimization to run, specified in seconds as a scalar number. The optimization runs until it reaches the time specified, an ideal solution, or another stopping criteria. |
Patience (iterations) |
Maximum number of iterations where no new best solution is found, specified as a scalar integer. The optimization continues as long as the algorithm continues to find new best solutions. |
Safety Margin (%) |
A safety margin, specified as a positive scalar value, indicating the percentage increase in the bounds of the collected range. The safety margin is applied to the union of all collected ranges. |
Objective Function |
Objective function to use during the optimization search. The optimization algorithm seeks to minimize an objective function while meeting the specified behavioral constraints.
Note To use |
Perform Neighborhood Search |
Whether to perform a neighborhood search for the optimized solution. Disabling this option can increase the speed of the optimization process, but also increases the chances of finding a less ideal solution. |
Use Parallel |
Whether to run iterations of the optimization in parallel. Running the iterations in parallel requires a Parallel Computing Toolbox™ license. If you do not have a Parallel Computing Toolbox license, or if you do no enable this option, the iterations run in serial. |
Iterative Fixed-Point Conversion Workflow Options
Option | Description |
---|---|
Propose |
Whether to propose fraction lengths or word lengths for objects in the system under design.
|
Propose signedness |
Whether to use the collected range information to propose signedness. |
Safety margin for simulation min/max (%) |
Specify a safety margin to apply to collected simulation ranges. TheFixed-Point Toolwill add the specified amount to the collected ranges and base proposals on this larger range. |
Convert double/single/half types |
Whether to generate data type proposals for objects that currently specify a double, single, or half-precision data type. |
Convert inherited types |
Whether to generate data type proposals for results that currently specify an inherited data type. |
Default word length |
Default word length to use for data type proposals, specified as a scalar integer. This setting is enabled only when the |
Default fraction length |
Default fraction length to use for data type proposals, specified as a scalar integer. This setting is enabled only when the |
Range Collection Workflow Options
Option | Description |
---|---|
Verify using |
Data type override settings to use for embedded simulation.
|
Some blocks do not support fixed-point data types and can result in an error during fixed-point conversion. SeeBlocks That Do Not Support Fixed-Point Data Types.
Some modeling constructs may cause data type propagation issues. See模型可能会导致Data Type Propagation Errors.
If your model contains a MATLAB Function block, use only supported modeling constructs for successful conversion. SeeMATLAB Language Features Supported for Automated Fixed-Point Conversion.
For best practices and recommendations, seeBest Practices for Fixed-Point Conversion Workflow.
To customize views in theFixed-Point Tool, seeControl Views in the Fixed-Point Tool.
For help troubleshooting the optimization workflow, seeData Type Optimization Not Successful.
fxptdlg
|DataTypeWorkflow.Converter
|fxpopt
|Optimize Fixed-Point Data Types for a System|The Command-Line Interface for the Fixed-Point Tool