# fxpopt

Optimize data types of a system

## Description

## Examples

### Optimize Fixed-Point Data Types

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] UseParallel: 1 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);

Starting parallel pool (parpool) using the 'local' profile ... Connected to the parallel pool (number of workers: 4). + Preprocessing + Modeling the optimization problem - Constructing decision variables + Running the optimization solver Analyzing and transferring files to the workers ...done. - 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. - Evaluating new solution: cost 324, meets the tolerances. - Evaluating new solution: cost 342, meets the tolerances. - Evaluating new solution: cost 360, meets the tolerances. - Evaluating new solution: cost 378, meets the tolerances. - Evaluating new solution: cost 396, meets the tolerances. - Evaluating new solution: cost 414, meets the tolerances. - Evaluating new solution: cost 432, meets the tolerances. - Updated best found solution, cost: 306 - Evaluating new solution: cost 304, meets the tolerances. - Evaluating new solution: cost 304, meets the tolerances. - Evaluating new solution: cost 301, meets the tolerances. - Evaluating new solution: cost 305, does not meet the tolerances. - Evaluating new solution: cost 305, meets the tolerances. - Evaluating new solution: cost 301, meets the tolerances. - Evaluating new solution: cost 299, meets the tolerances. - Evaluating new solution: cost 299, meets the tolerances. - Evaluating new solution: cost 296, meets the tolerances. - Evaluating new solution: cost 299, meets the tolerances. - Evaluating new solution: cost 291, meets the tolerances. - Evaluating new solution: cost 296, does not meet the tolerances. - Evaluating new solution: cost 299, meets the tolerances. - Evaluating new solution: cost 300, meets the tolerances. - Evaluating new solution: cost 296, does not meet the tolerances. - Evaluating new solution: cost 301, meets the tolerances. - Evaluating new solution: cost 303, meets the tolerances. - Evaluating new solution: cost 299, meets the tolerances. - Evaluating new solution: cost 304, does not meet the tolerances. - Evaluating new solution: cost 300, meets the tolerances. - Updated best found solution, cost: 304 - Updated best found solution, cost: 301 - Updated best found solution, cost: 299 - Updated best found solution, cost: 296 - Updated best found solution, cost: 291 - Evaluating new solution: cost 280, meets the tolerances. - Evaluating new solution: cost 287, meets the tolerances. - Evaluating new solution: cost 288, does not meet the tolerances. - Evaluating new solution: cost 287, does not meet the tolerances. - Evaluating new solution: cost 283, meets the tolerances. - Evaluating new solution: cost 283, does not meet the tolerances. - Evaluating new solution: cost 262, does not meet the tolerances. - Evaluating new solution: cost 283, does not meet the tolerances. - Evaluating new solution: cost 282, does not meet the tolerances. - Evaluating new solution: cost 288, meets the tolerances. - Evaluating new solution: cost 289, meets the tolerances. - Evaluating new solution: cost 288, meets the tolerances. - Evaluating new solution: cost 290, meets the tolerances. - Evaluating new solution: cost 281, does not meet the tolerances. - Evaluating new solution: cost 286, does not meet the tolerances. - Evaluating new solution: cost 287, meets the tolerances. - Evaluating new solution: cost 284, meets the tolerances. - Evaluating new solution: cost 282, meets the tolerances. - Evaluating new solution: cost 285, does not meet the tolerances. - Evaluating new solution: cost 277, meets the tolerances. - Updated best found solution, cost: 280 - Updated best found solution, cost: 277 - Evaluating new solution: cost 272, meets the tolerances. - Evaluating new solution: cost 266, meets the tolerances. - Evaluating new solution: cost 269, meets the tolerances. - Evaluating new solution: cost 271, does not meet the tolerances. - Evaluating new solution: cost 274, meets the tolerances. - Evaluating new solution: cost 275, meets the tolerances. - Evaluating new solution: cost 274, does not meet the tolerances. - Evaluating new solution: cost 275, meets the tolerances. - Evaluating new solution: cost 276, does not meet the tolerances. - Evaluating new solution: cost 271, meets the tolerances. - Evaluating new solution: cost 267, meets the tolerances. - Evaluating new solution: cost 270, meets the tolerances. - Evaluating new solution: cost 272, meets the tolerances. - Evaluating new solution: cost 264, does not meet the tolerances. - Evaluating new solution: cost 265, does not meet the tolerances. - Evaluating new solution: cost 269, meets the tolerances. - Evaluating new solution: cost 270, meets the tolerances. - Evaluating new solution: cost 269, meets the tolerances. - Evaluating new solution: cost 276, meets the tolerances. - Evaluating new solution: cost 274, meets the tolerances. - Updated best found solution, cost: 272 - Updated best found solution, cost: 266 + Optimization has finished. - Neighborhood search complete. - Maximum number of iterations completed. + Fixed-point implementation that met the tolerances found. - Total cost: 266 - Maximum absolute difference: 0.087035 - 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);

You can revert your model back to its original state using the `revert`

method of the `OptimizationResult`

object.

revert(result);

## Input Arguments

`model`

— Model containing system under design, `sud`

character vector

Name of the model containing the system that you want to optimize.

**Data Types: **`char`

`sud`

— Model or subsystem whose data types you want to optimize

character vector

Model or subsystem whose data types you want to optimize, specified as a character vector containing the path to the system.

**Data Types: **`char`

`options`

— Additional optimization options

`fxpOptimizationOptions`

object

`fxpOptimizationOptions`

object specifying additional options to
use during the data type optimization process.

## Output Arguments

`result`

— Object containing the optimized design

`OptimizationResult`

object

Result of the optimization, returned as an `OptimizationResult`

object. Use the `explore`

method of the object to open the Simulation Data Inspector and view the
behavior of the optimized system. You can also explore other solutions found
during the optimization that may or may not meet the constraints specified
in the `fxpOptimizationOptions`

object,
`options`

.

## See Also

### Classes

### Functions

**Introduced in R2018a**

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

# Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)