This example shows how to use the Fixed-Point Tool to propose fraction lengths for a model
based on the minimum and maximum values captured over multiple simulations. In this example,
you define a
Simulink.SimulationInput object in the base or
model workspace to specify the simulation scenarios to use for range collection. The
Fixed-Point Tool merges the results from two simulation runs and proposes a data type based on
the merged ranges. Merging results allows you to autoscale your model over the complete
When converting a system based on multiple simulation scenarios, structurally altering the contents of the system under design during the conversion process could lead to errors. When defining the simulation scenarios avoid making any of the following changes to the system under design:
Add or delete a block in the system under design
Add another input to the system under design
Change a block type in the system under design
This example uses the
ex_fpt_merge model. The model contains a sine wave input and two alternate noise sources, band-limited white noise and random uniform noise. In this example, define a
Simulink.SimulationInput object and collect ranges using the Band-Limited White Noise source and the Random Number 1 source. Propose data types for the model based on the merged simulation ranges.
Open the model.
model = 'ex_merge_ranges'; open_system(model);
Simulink.SimulationInput object. The first object sets the Manual Switch block to the Band-Limited White Noise source, the second
SimulationInput object sets the Manual Switch block to the Random Number source.
simIn(1) = Simulink.SimulationInput(model); simIn(2) = Simulink.SimulationInput(model);
simIn(1) = simIn(1).setBlockParameter('ex_merge_ranges/Manual Switch', 'sw', '0'); simIn(2) = simIn(2).setBlockParameter('ex_merge_ranges/Manual Switch', 'sw', '1');
In the Apps gallery of the
model, select Fixed-Point Tool.
In the Fixed-Point Tool, click New, and select
Iterative Fixed-Point Conversion.
Under System Under Design, select
Under Range Collection Mode, select Simulation Ranges as the range collection method.
Under Simulation Inputs, select the
simIn that you
defined in the base workspace.
Set the absolute tolerance of the
Subsystem: 1 signal to
0.1, or 10%.
In the toolstrip, click the Prepare button.
Expand the Collect Ranges button arrow and select
Double precision. Click Collect
Simulink® simulates the
ex_merge_ranges model twice, once using
the Band-Limited White Noise source block and once using the
Random Number source block.
You can view the ranges of each simulation individually by selecting the simulation
in the Workflow Browser. In this example the
BaselineRun_Scenario_1 simulation had a SimMin
-3.5821 and a SimMax value of
had a SimMin value of
-2.5317 and a
SimMax value of
BaselineRun node in the Workflow
Browser shows the merged ranges from the two simulation scenarios.
In the Convert section of the toolstrip, click the Propose Data Types button .
The Fixed-Point Tool uses the merged minimum and maximum values to propose fraction lengths for each block. These values ensure maximum precision while spanning the full range of simulation values. The tool displays the proposed data types in the spreadsheet.
Click the Apply Data Types button to write the proposed data types to the model.
In the Verify section of the toolstrip, click the
Simulate with Embedded Types button . The Fixed-Point Tool simulates the model using the
Simulink.SimulationInput scenarios that were used to collect ranges
and verifies whether each scenario met the specified tolerances.
The Workflow Browser indicates whether the verification runs met the tolerances. In this example, both simulation scenarios met the specified tolerances.
To view the simulation data for an individual run, right-click on the run in the Workflow Browser.