| Contents | Index |
Open the ex_fixed_point_workflow model.
The Fixed-Point Advisor provides a set of tasks that help you prepare a floating-point model or subsystem for conversion to an equivalent fixed-point representation. After preparing your model, you use the Fixed-Point Tool to perform the fixed-point conversion.
In this part of the tutorial, you use the Fixed-Point Advisor to prepare the Controller Subsystem in the ex_fixed_point_workflow model for conversion.
In the ex_fixed_point_workflow model menu, select Tools > Fixed-Point Tool.
In the Fixed-Point Tool:
In the Model Hierarchy pane, select the Controller Subsystem.
In the Fixed-point preparation for selected system pane, click the Fixed-Point Advisor button.
You run the Fixed-Point Advisor on the ex_fixed_point_workflow Controller Subsystem because this is the system of interest. There is no need to convert the system inputs or the display to fixed point.
In the Fixed-Point Advisor left pane, expand the Prepare Model for Conversion folder to view the tasks. For the purpose of this tutorial, run the tasks in the this folder one at a time. Select Verify model simulation settings and, in the right pane, select Run this task.
This task validates that model simulation settings allow signal logging and disables data type override in the model and for fi objects or embedded numeric data types in your model or workspace. These settings facilitate conversion to fixed point in later tasks.
A waitbar appears while the task runs. When the run is complete, the result shows that the task passed.
Select and run Verify update diagram status.
Verify update diagram status runs. Your model must be able to successfully update diagram to run the checks in the Fixed-Point Advisor.
The task passes.
Select and run Address unsupported blocks. This task identifies blocks that do not support fixed-point data types.
The task passes because the subsystem contains no blocks that do not support fixed-point data.
Select and run Set up signal logging. Prior to simulation, you must specify at least one signal for the Fixed-Point Advisor to use for analysis and comparison in downstream checks. You should log, at minimum, the unique input and output signals.
The task generates a warning because signal logging is not specified for any signals.
Fix the warning using the Model Advisor Result Explorer:
Click the Explore Result button.
The Model Advisor Result Explorer opens.
In the middle pane, select each signal you want to log and, next to the signal, select the corresponding EnableLogging check box.
For this tutorial, log these signals:
Lookup Table for Gain
Lookup Table for Chart
Chart
Discrete Filter
Close the Model Advisor Result Explorer.
In the Fixed-Point Advisor window, click Run This Task.
The task passes because signal logging is now enabled for at least one signal.
Select and run Create simulation reference data.
The Fixed-Point Advisor simulates the model using the current solver settings, and creates and archives reference signal data in a run named FPA_Reference to use for analysis and comparison in later conversion tasks. This task also validates that model simulation settings allow signal logging and that the Fixed-point instrumentation mode is set to Minimums, maximums and overflows.
The Fixed-Point Advisor issues a warning and provides information in the Analysis Result box that logging simulation minimum and maximum values failed.
Logging failed because the Fixed-point instrumentation mode is Use local settings, but the recommended setting is Minimums, maximums and overflows.
To fix the failure, in the Action pane, click Modify All.
The Fixed-Point Advisor configures the model to the settings recommended in the Analysis Result pane. The Action pane displays a table of changes showing that the Fixed-point instrumentation mode is now Minimums, maximums and overflows
Click Run This Task.
Running the task after using the Modify All action verifies that you made the necessary changes. The Analysis Result pane updates to display a passed result and information about why the task passed.
In the Verify Fixed-Point Conversion Guidelines folder, select and run Check model configuration data validity diagnostic parameters settings. This task verifies that the Configuration Parameters > Diagnostics > Data Validity > Parameters options are all set to warning. If these options are set to error, the model update diagram action fails in downstream checks.
The task passes because none of these options are set to error.
Select and run Implement logic signals as Boolean data. This task verifies that Configuration Parameters > Optimization > Implement logic signals as Boolean data is selected. If it is cleared, the code generated in downstream checks is not optimized.
The task passes.
Select and run Check for proper bus usage. This task identifies:
Mux blocks that are bus creators
Bus signals that the top-level model treats as vectors
Note This is a Simulink check. For more information, see Check for proper bus usage in the Simulink documentation. |
The task runs and generates a warning because this check works only from top-level models and you are running from the subsystem. Because this model uses no buses, ignore this warning. For models containing buses, you must run the Fixed-Point Advisor from the top-level model to perform this check.
Select and run Simulation range checking. This tasks verifies that the Configuration Parameters > Diagnostics > Simulation range checking option is not set to none.
The task generates a warning because the Simulation range checking option is none.
To fix the warning, in the Action box, click Modify All.
The Fixed-Point Advisor sets the Simulation range checking option to warning.
Rerun the task.
The task now passes because the Simulation range checking option is correct.
Select and run Check for implicit signal resolution. This task checks for models that use implicit signal resolution.
The task fails because implicit signal resolution is enabled.
To fix the failure, in the Action box, click Modify All.
The Fixed-Point Advisor sets the Signal resolution option to Explicit only.
Rerun the task.
The task now passes.
You have completed all the tasks for the Prepare Model for Conversion folder. At this point, you can review the results report found at the folder level, or continue to the next folder.
This folder contains tasks that set the block configuration options and set output minimum and maximum values for blocks. The block settings from this task simplify the initial data typing and scaling. Later tasks set optimal block configuration. The tasks in this folder prepare the model for automatic data typing in the Fixed-Point Tool.
For the purpose of this tutorial, run the tasks in the Prepare for Data Typing and Scaling folder one at a time.
Open the Prepare for Data Typing and Scaling folder then select and run Review locked data type settings. This task identifies blocks that have their data type settings locked down which excludes them for automatic data typing.
This task passes because the model contains no blocks with locked data types.
Select and run Remove output data type inheritance. This task identifies blocks that have an inherited output signal data type that might lead to data type propagation errors.
This task fails because there are floating-point inheritance blocks in the model. For floating-point inheritance blocks, when inputs are floating-point, all internal and output data types are floating point. Therefore, you must specify an input parameter data type for these blocks.
In the Fixed-Point Advisor Input Parameters pane, set Data type for blocks with floating-point inheritance to int16, and rerun the task.
The task fails and the Fixed-Point Advisor provides information about the failure in the Analysis Result box. The Fixed-Point Advisor recommends that you set:
The input data type of the Discrete Filter block, which is a floating-point inheritance block, to a fixed-point data type to avoid floating-point inheritance.
The output data type of all the other blocks that currently have their output data type set by inheritance rules to the compiled (current propagated) data type.
Fix the failure using the Modify All button to configure the output data types to the recommended values.
The Action Result box displays:
A table showing the previous and current data types for all the floating-point inheritance blocks.
A table showing the previous and current data types for blocks that use other types of inheritance.
Rerun the task.
The task passes.
Select and run Relax input data type settings. This task identifies blocks with input data type constraints that might cause data type propagation issues.
The task passes because the model contains no blocks that have inherited input data types.
Select and run Verify Stateflow charts have strong data typing with Simulink. This task verifies that the configuration of all Stateflow charts ensures strong data typing with Simulink I/O.
The task passes because the configuration of the Stateflow chart in the subsystem is correct.
Select and run Remove redundant specification between signal objects and blocks. This task identifies and removes redundant data type specification originating from blocks and Simulink signal objects.
The task passes because the model contains no resolved Simulink signal objects.
Select and run Verify hardware selection. This task identifies the hardware device information in the Hardware Implementation pane of the Configuration Parameters dialog box. It also checks the default data type selected for floating-point signals in the model.
The task fails because the default data type for all floating-point signals is set to Remain floating-point. Because the target hardware is an embedded processor, the Fixed-Point Advisor recommends that you set this value to the hardware integer used by the embedded hardware.
To fix the failure, in the Input Parameters pane, set Default data type of all floating-point signals to Same as embedded hardware integer.
Rerun the task.
The task passes.
Select and run Specify block minimum and maximum values. Ideally, you should specify block output and parameter minimum and maximum values for, at minimum, the Inport blocks in the system. You can specify the minimum and maximum values for any block in this step. Typically, you determine these values during the design process based on the system you are creating.
The Fixed-Point Advisor warns you that you have not specified any minimum and maximum values.
Fix the warning by specifying minimum and maximum values for Inport blocks:
Click the Explore Result button.
The Model Advisor Result Explorer opens, showing that the Inport blocks, In1 and In2, do not have output minimum and maximum values specified.
In the center pane, select In1. This block receives the output from Repeating table Source, which has a minimum value of 10 and a maximum value of 20. Therefore, set OutMin to 10 and set OutMax to 20 as follows:
In the OutMin column for In1, select [] and replace with 10.
In the OutMax column for In1, select [] and replace with 20.
Select In2. This block receives the output from Sine Wave block, which has a minimum value of -1 and a maximum value of 1. Therefore, set OutMin to -1 and set OutMax to 1.
Close the Model Advisor Result Explorer.
In the Fixed-Point Advisor, rerun the task.
The task passes because you specified minimum and maximum values for all Inport blocks.
The tool advises you to specify minimum and maximum values for all blocks if possible. For the purpose of this tutorial, do not specify other minimum and maximum values for other blocks.
You have completed all tasks in the Prepare for Data Typing and Scaling folder. At this point, you can review the results report found at the folder level, or continue to the next folder.
Select and run this task to close the Fixed-Point Advisor and return to the Fixed-Point Tool.
Use the Fixed-Point Tool to propose fixed-point data types for appropriately configured blocks based on the double-precision simulation results stored in the simulation reference run that the Fixed-Point Advisor created. These results are stored in the run named FPA_Reference. You can view the results in the Fixed-Point Tool Contents pane.
The tool proposes fixed-point data types and scaling based on the ranges of the Repeating table Source and Sine Wave inputs. You can then use the tool to accept and apply the proposed data types selectively. In this example, you propose fraction lengths for the specified word lengths.
In the Fixed-Point Tool, click the Propose
fraction lengths button
.
The Fixed-Point Tool analyzes the scaling of all fixed-point blocks whose:
Lock output data type setting against changes by the fixed-point tools parameter is not selected.
Output data type parameter specifies a generalized fixed-point number.
Data types are not inherited.
The Fixed-Point Tool updates the results in the Contents pane.
In the Fixed-Point Tool, set the Column View to Automatic Data Typing with Simulation Min/Max View to display information relevant to the proposal. The tool displays the proposed data types in the ProposedDT column in the Contents pane. The tool does not propose data types for objects with inherited data types.
To accommodate the full simulation range, the Fixed-Point Tool proposes data types for blocks that do not have inherited data types. By default, it selects the Accept check box for these signals because the proposed data type differs from the object's current data type. If you apply data types, the tool will apply the proposed data types to these signals. For more information, see Apply Proposed Data Types.
Examine the results to resolve any conflicts and to ensure that you want to accept the proposed data type for each result.
In the Fixed-Point Tool toolbar, select Show > Conflicts with proposed data types.
The Fixed-Point Tool detected no conflicts.
Tip If the tool does detect conflicts, you must resolve these before applying data types. For more information, see Examine Results to Resolve Conflicts. |
Now that you have reviewed the results and ensured that there are no issues, you are ready to apply the proposed data types to the model, as described in Apply Fixed-Point Data Types.
Click the Apply accepted fraction lengths button
to write the proposed data types to the model.
![]()
The Fixed-Point Tool applies the data type proposals to the subsystem blocks.
In the Fixed-Point Tool toolbar, select Show > All results.
The tool has set all the specified data types to the proposed types.
You are now ready to check that the new data types are acceptable, as described in Verify Fixed-Point Settings.
Next, you simulate again using the new fixed-point settings. You then use the Fixed-Point Tool plotting capabilities to compare the results from the floating-point FPA_Reference run with the fixed-point results.
In the Fixed-Point Tool Model Hierarchy pane, select the Controller Subsystem.
In the Data collection pane, set Store results in run to Initial_fixed_point. You specify a new run name to prevent the tool from overwriting the results that you want to retain in the FPA_Reference run.
Click the Fixed-Point Tool Simulation button
to run the simulation.
The Simulink software simulates using the new data types that you applied in the previous step. Afterward, the Fixed-Point Tool displays in its Contents pane information about blocks that logged fixed-point data. The CompiledDT (compiled data type) column for the run shows that the Controller Subsystem blocks use fixed-point data types with the new data types.
Examine the results to verify that there are no overflows or saturations.
In the Fixed-Point Tool Model Hierarchy pane,
select the Controller Subsystem. In the Contents pane,
select the Discrete Filter: Output that corresponds
to the FPA_Reference run, and then click the Difference
Plot of Signal button
.
The Fixed-Point Tool plots the signal for the FPA_Reference and Initial_fixed_point runs, as well as their difference. The difference plot shows that the floating-point signal and the fixed-point signal are almost identical, the difference is on the order of 10^-5.

Optionally, you can zoom in to view the steady-state region with greater detail. From the Tools menu of the figure window, select Zoom In and then drag the pointer to draw a box around the area you want to view more closely.
Now you are ready to test the fixed-point settings with new the input data, as described in Test Fixed-Point Settings With New Input Data.
You have successfully used the Fixed-Point tool to propose fixed-point data types for your model. In the previous step, you saw that the numerical results for the double-precision system and the fixed-point system are very close. These results indicate that the fixed-point data types are suitable for the range of input data that you used. In practice, you might need to run multiple simulations to cover the entire design range of your system and use the results of these simulations to refine the fixed-point data types in your model.
In this part of the tutorial, you continue working on the model. First, you modify the range of the Sine Wave input and obtain simulation data based on this new range. Then, you use the Fixed-Point Tool to refine the model fixed-point settings based on the new simulation data. The Fixed-Point Tool proposes new data types that can accommodate the new input range.
To change the range of the input data and test the fixed-point settings:
In the ex_fixed_point_workflow model, double-click the Sine Wave Source block.
The Source Block Parameters dialog box opens.
In this dialog box, change the Amplitude to 2 and click OK.
In the Fixed-Point Tool Model Hierarchy pane , select the Controller Subsystem.
In the Data collection pane, set Store results in run to Input2.
Click the Fixed-Point Tool Simulation button
to run the simulation.
The Simulink software simulates the ex_fixed_point_workflow model. The Stateflow debugger reports a data overflow error in the Stateflow chart.
In the Stateflow Debugging window, under Error checking options, clear the Data Range option and close the debugger and the Chart.
This action disables data range error detection and allows the simulation to run to completion.
In the Fixed-Point Tool Model Hierarchy pane, select the Controller Subsystem.
The Fixed-Point Tool Contents pane displays the simulation results for each block in the subsystem that logged fixed-point data. The tool stores the results in the Input2 run.
In the Input2 run, the tool highlights in red the result for the Gain block, indicating that there are issues.
Examine the result for the Gain block.
The result shows that the Gain block output saturated, which indicates that the fixed-point data settings for this block are not suitable for the new input range.
Next, override the fixed-point data types with doubles and simulate the model again to obtain the ideal behavior of the subsystem, as described in Gather a Floating-Point Benchmark.
Run the model with a global override of the fixed-point data types using double-precision numbers to avoid quantization effects. This provides a floating-point benchmark that represents the ideal output. The Simulink software logs the signal logging results to the MATLAB workspace. The Fixed-Point Tool displays the simulation results including minimum and maximum values that occur during the run.
In the Fixed-Point Tool Model Hierarchy pane, select the Controller Subsystem.
In the Settings for selected system pane, set Data type override to Double.
Using this setting, the Fixed-Point Tool performs a global override of the fixed-point data types and scaling using double-precision numbers, thus avoiding quantization effects.
In the Data collection pane, set Store results in run to DTO_Input2.
Click the Fixed-Point Tool Simulate button
to run the simulation.
The Fixed-Point Tool highlights any simulation results that have issues, such as overflows or saturations.
In the Contents pane, click the Run column to sort the runs. Verify that there were no overflows or saturations in the DTO_Input2 run.
Now, use the Fixed-Point Tool to propose fixed-point data types based on the double-precision simulation results for the new input stored in the DTO_Input2 run.
In the Fixed-Point Tool, click the Propose
fraction lengths button
.
In the Propose Data Types dialog box, select DTO_Input2 as the run to use for proposing data types, and then click OK.
The Fixed-Point Tool proposes new data types for all objects in the model and updates the results in the Contents pane.
In the Fixed-Point Tool, set the Column View to Automatic Data Typing with Simulation Min/Max View to display information relevant to the proposal. The tool displays the proposed data types in the ProposedDT column in the Contents pane. The tool does not propose data types for objects with inherited data types.
To accommodate the full simulation range, the Fixed-Point Tool proposes new data types with reduced precision for the Chart/output and Gain block output.
Examine the results to resolve any conflicts and to ensure that you want to accept the proposed data type for each result.
In the Fixed-Point Tool toolbar, select Show > Conflicts with proposed data types.
The Fixed-Point Tool detected no conflicts, so you are ready to apply the new data types as described in Apply the New Fixed-Point Data Types.
Click Apply accepted fraction lengths
to write the proposed
data types to the model.
In the Apply Data Types dialog box, select DTO_Input2 as the run to use for applying proposed data types and then click OK.
In the Fixed-Point Tool toolbar, select Show > All results.
The tool has set all the specified data types to the proposed types.
Finally, you simulate again using the new fixed-point settings. You then use the Fixed-Point Tool plotting capabilities to compare the results for the initial and final fixed-point settings.
In the Fixed-Point Tool Model Hierarchy pane, select the Controller Subsystem.
In the Settings for selected system pane, set Data type override to Use local settings.
In the Data collection pane, set Store results in run to Final_fixed_point.
Click Start to run the simulation.
The Simulink software simulates using the new data types that you applied in the previous step and stores the results in the Final_fixed_point run.
Examine the results to verify that there are no overflows or saturations.
In the Fixed-Point Tool Model Hierarchy pane
, select the Controller Subsystem. In the Contents pane,
select the Discrete Filter: Output that corresponds
to the Initial_fixed_point run, and then click
the Difference Plot of Signal button
.
In the Difference Plot Selector dialog box, select Final_fixed_point, and then click OK.
The Fixed-Point Tool plots the signal for both runs, as well as their difference. The difference plot shows that the floating-point signal and the fixed-point signal are identical.
Optionally, you can zoom in to view the steady-state region with greater detail. From the Tools menu of the figure window, select Zoom In and then drag the pointer to draw a box around the area you want to view more closely.
Optionally, use the Simulink Model Advisor to identify model settings that might lead to nonoptimal results in code generation.
From the Simulink Tools menu, select Model Advisor.
In the System Selector dialog box, select Controller Subsystem, and then click OK.
In the Model Advisor left pane, expand the By Task node.
Expand the Code Generation Efficiency node.
Select and run Identify blocks that generate expensive saturation and rounding code. This task optimizes the code to eliminate unnecessary saturation and rounding.
The result is a warning because there are settings that can result in nonoptimized code. The Fixed-Point Advisor identified that:
The Gain block has the Saturate on integer overflow parameter selected. This setting can result in unnecessary condition-checking code.
The integer rounding mode selected for the model is Undefined. This setting results in inefficient generated code.
Fix the warning conditions.
Click Explore Result to open the Model Advisor Result Explorer.
Clear the SaturateOnOverflow setting for the Gain block and close the Model Advisor Result Explorer.
In the Analysis Result box, click the Embedded Hardware properties link to open the Configuration Parameters dialog box Hardware Implementation pane.
Set the Signed integer division rounds to parameter to Zero and click OK to close the dialog box.
Rerun the task.
The task passes.
Select and run Identify questionable fixed-point operations. This task identifies fixed-point operations that can lead to nonoptimal results.
The task passes.
![]() | Before You Begin | Key Points to Remember | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |