Data type optimization seeks to minimize the total bit-width of a specified system, while maintaining original system behavior within a specified tolerance. During the optimization, the software establishes a baseline by simulating the original model. It then constructs different fixed-point versions of your model and runs simulations to determine the behavior using the new data types. The optimization selects the model with the smallest total bit-width that meets the specified behavioral constraints.

The model containing the system you want to optimize must have the following characteristics:

All blocks in the model must support fixed-point data types.

The model cannot rely on data type override to establish baseline behavior.

The design ranges specified on blocks in the model must be consistent with the simulation ranges.

The data logging format of the model must be set to

`Dataset`

.To configure this setting, in the Configuration Parameters, in the

**Data Import/Export**pane, set**Format**to`Dataset`

.The model must have finite simulation stop time.

During the optimization process, the software makes the following model configuration changes:

In the Configuration Parameters, in the

**Diagnostics**>**Data Validity**pane, set the**Simulation range checking**parameter to`error`

.If any simulation ranges violate the specified design ranges, the optimization stops.

In the Configuration Parameters, in the

**Diagnostics**>**Data Validity**pane, set the**Detect precision loss**,**Detect underflow**, and**Detect overflow**parameters to`none`

.To optimize the data types of a system, the optimization lowers the precision of the baseline model. Therefore, some overflows, underflows, and precision loss is expected. You can set the acceptable level of quantization using the

`addTolerance`

method.

You can restore these diagnostics after the optimization in the Configuration Parameters dialog box.

To determine if the behavior of a new fixed-point implementation is acceptable, the
optimization requires well-defined behavioral constraints. To define a constraint, use the
`addTolerance`

method of the `fxpOptimizationOptions`

object, or using one or more Model Verification (Simulink) blocks.

When the **Lock data types against changes by the fixed-point tools**
setting of a block within the system you want to optimize is enabled, it minimizes the
freedom of the optimization process to find new solutions.

The `fxpopt`

function returns an `OptimizationResult`

object containing a series of fixed-point implementations called solutions. If the
optimization process finds a fixed-point implementation that meets the specified behavioral
constraints, the solutions are sorted by cost, giving the best solution with the smallest
cost (bit-width) as the first element of the array.

In cases where the optimization is not able to find a fixed-point implementation meeting the behavioral constraints, the solutions are ordered by maximum absolute difference from the baseline model, with the smallest difference as the first element.

Explore the best found solution using the `explore`

method of the
`OptimizationResult`

object. You can also explore any of the other found
solutions in the same manner. Do not save and close the model until you select the solution
you want to keep. Closing or saving the model inhibits further exploration of different
solutions.

This example shows how to optimize the data types used by a system based on specified tolerances.

To begin, open the system for which you want to optimize the data types.

model = 'ex_auto_gain_controller'; sud = 'ex_auto_gain_controller/sud'; open_system(model)

Create an `fxpOptimizationOptions`

object to define constraints and tolerances to meet your design goals. Set the `UseParallel`

property of the `fxpOptimizationOptions`

object to `true`

to run iterations of the optimization in parallel. You can also specify word lengths to allow in your design through the `AllowableWordLengths`

property.

opt = fxpOptimizationOptions('AllowableWordLengths', 10:24, 'UseParallel', true)

opt = fxpOptimizationOptions with properties: MaxIterations: 50 MaxTime: 600 Patience: 10 Verbosity: High AllowableWordLengths: [10 11 12 13 14 15 16 17 18 19 20 21 22 23 24] Advanced Options AdvancedOptions: [1×1 struct]

Use the `addTolerance`

method to define tolerances for the differences between the original behavior of the system, and the behavior using the optimized fixed-point data types.

tol = 10e-2; addTolerance(opt, [model '/output_signal'], 1, 'AbsTol', tol);

Use the `fxpopt`

function to run the optimization. The software analyzes ranges of objects in your system under design and the constraints specified in the `fxpOptimizationOptions`

object to apply heterogeneous data types to your system while minimizing total bit width.

result = fxpopt(model, sud, opt);

+ Preprocessing + Modeling the optimization problem - Constructing decision variables - Binding constraints + Running the optimization solver - Evaluating new solution: cost 180, does not meet the tolerances. - Evaluating new solution: cost 198, does not meet the tolerances. - Evaluating new solution: cost 216, does not meet the tolerances. - Evaluating new solution: cost 234, does not meet the tolerances. - Evaluating new solution: cost 252, does not meet the tolerances. - Evaluating new solution: cost 270, does not meet the tolerances. - Evaluating new solution: cost 288, does not meet the tolerances. - Evaluating new solution: cost 306, meets the tolerances. - Updated best found solution, cost: 306 - Evaluating new solution: cost 304, meets the tolerances. - Updated best found solution, cost: 304 - Evaluating new solution: cost 300, meets the tolerances. - Updated best found solution, cost: 300 - Evaluating new solution: cost 299, meets the tolerances. - Updated best found solution, cost: 299 - Evaluating new solution: cost 298, meets the tolerances. - Updated best found solution, cost: 298 - Evaluating new solution: cost 297, meets the tolerances. - Updated best found solution, cost: 297 - Evaluating new solution: cost 296, meets the tolerances. - Updated best found solution, cost: 296 - Evaluating new solution: cost 295, meets the tolerances. - Updated best found solution, cost: 295 - Evaluating new solution: cost 294, does not meet the tolerances. - Evaluating new solution: cost 293, meets the tolerances. - Updated best found solution, cost: 293 - Evaluating new solution: cost 292, meets the tolerances. - Updated best found solution, cost: 292 - Evaluating new solution: cost 291, meets the tolerances. - Updated best found solution, cost: 291 - Evaluating new solution: cost 290, meets the tolerances. - Updated best found solution, cost: 290 - Evaluating new solution: cost 289, meets the tolerances. - Updated best found solution, cost: 289 - Evaluating new solution: cost 287, meets the tolerances. - Updated best found solution, cost: 287 - Evaluating new solution: cost 283, meets the tolerances. - Updated best found solution, cost: 283 - Evaluating new solution: cost 282, meets the tolerances. - Updated best found solution, cost: 282 - Evaluating new solution: cost 281, meets the tolerances. - Updated best found solution, cost: 281 - Evaluating new solution: cost 280, meets the tolerances. - Updated best found solution, cost: 280 - Evaluating new solution: cost 279, meets the tolerances. - Updated best found solution, cost: 279 - Evaluating new solution: cost 278, meets the tolerances. - Updated best found solution, cost: 278 - Evaluating new solution: cost 277, does not meet the tolerances. - Evaluating new solution: cost 276, meets the tolerances. - Updated best found solution, cost: 276 - Evaluating new solution: cost 275, meets the tolerances. - Updated best found solution, cost: 275 - Evaluating new solution: cost 274, meets the tolerances. - Updated best found solution, cost: 274 - Evaluating new solution: cost 273, meets the tolerances. - Updated best found solution, cost: 273 - Evaluating new solution: cost 272, meets the tolerances. - Updated best found solution, cost: 272 - Evaluating new solution: cost 270, meets the tolerances. - Updated best found solution, cost: 270 - Evaluating new solution: cost 266, meets the tolerances. - Updated best found solution, cost: 266 - Evaluating new solution: cost 265, meets the tolerances. - Updated best found solution, cost: 265 - Evaluating new solution: cost 264, meets the tolerances. - Updated best found solution, cost: 264 - Evaluating new solution: cost 263, meets the tolerances. - Updated best found solution, cost: 263 - Evaluating new solution: cost 262, meets the tolerances. - Updated best found solution, cost: 262 - Evaluating new solution: cost 261, meets the tolerances. - Updated best found solution, cost: 261 - Evaluating new solution: cost 260, does not meet the tolerances. - Evaluating new solution: cost 259, does not meet the tolerances. - Evaluating new solution: cost 260, meets the tolerances. - Updated best found solution, cost: 260 - Evaluating new solution: cost 259, meets the tolerances. - Updated best found solution, cost: 259 - Evaluating new solution: cost 258, meets the tolerances. - Updated best found solution, cost: 258 - Evaluating new solution: cost 257, meets the tolerances. - Updated best found solution, cost: 257 - Evaluating new solution: cost 255, meets the tolerances. - Updated best found solution, cost: 255 - Evaluating new solution: cost 251, meets the tolerances. - Updated best found solution, cost: 251 - Evaluating new solution: cost 250, meets the tolerances. - Updated best found solution, cost: 250 - Evaluating new solution: cost 249, meets the tolerances. - Updated best found solution, cost: 249 - Evaluating new solution: cost 248, meets the tolerances. - Updated best found solution, cost: 248 - Evaluating new solution: cost 247, meets the tolerances. - Updated best found solution, cost: 247 - Evaluating new solution: cost 246, meets the tolerances. - Updated best found solution, cost: 246 - Evaluating new solution: cost 245, does not meet the tolerances. - Evaluating new solution: cost 244, does not meet the tolerances. - Evaluating new solution: cost 245, meets the tolerances. - Updated best found solution, cost: 245 - Evaluating new solution: cost 244, meets the tolerances. - Updated best found solution, cost: 244 + Optimization has finished. - Neighborhood search complete. - Maximum number of iterations completed. + Fixed-point implementation that met the tolerances found. - Total cost: 244 - Maximum absolute difference: 0.077478 - Use the explore method of the result to explore the implementation.

Use the `explore`

method of the `OptimizationResult`

object, `result`

, to launch Simulation Data Inspector and explore the design containing the smallest total number of bits while maintaining the numeric tolerances specified in the `opt`

object.

explore(result);