The Lookup Table Optimizer optimizes the spacing of breakpoints and the data types of lookup table data to reduce the memory used by a lookup table. Using the Lookup Table Optimizer and its command-line equivalent, you can:
Optimize an existing Lookup Table block.
Generate a lookup table from a Simulink® block, including a Math Function block or a subsystem.
Generate a lookup table from a function or function handle.
To optimize an existing lookup table, open the model containing the Lookup Table block.
load_system('sldemo_fuelsys'); open_system('sldemo_fuelsys/fuel_rate_control/airflow_calc');
Pumping Constant
Lookup Table block.To open the Lookup Table Optimizer, select the Pumping Constant
Lookup Table block. In the Lookup Table tab, select
Lookup Table Optimizer.
Select the type of block you want to optimize. To optimize an existing lookup table, or a Simulink block, including a Math Function block or a subsystem, select Simulink block. To generate a lookup table approximation for a function handle, select MATLAB Function Handle.
In this example, select Simulink block to optimize the
Pumping Constant
lookup table. Click
Next.
Under Block Information, enter the path to the Pumping
Constant
Lookup Table block. Select the block in the model, then click
Get Current Block in the Lookup Table Optimizer to fill in the
block path automatically.
Click Collect Current Values from Model to update the model diagram and allow the Lookup Table Optimizer to automatically gather information needed for the optimization process including current output data type, and input number, data type, and value range. You can manually edit all of these fields to specify ranges and data types other than those currently specified on the block.
Specify the Desired Output Data Type of the generated
lookup table as a numerictype
or Simulink.NumericType
object.
Specify the data type of each input to the block as a
numerictype
or Simulink.NumericType
object.
Specify the minimum and maximum values of each input of the generated lookup table as scalars in the table.
For this example, use the current values specified on the model. Click Next.
Specify constraints to use in the optimization. Set the Output Error Tolerance that is acceptable for your design.
Absolute tolerance is defined as the absolute value of the difference between the original output value and the output value of the optimized lookup table.
Relative tolerance measures the error relative to the value at that point, specified as a non-negative.
Specify the allowed word lengths as a vector based on types that are efficient for
your intended hardware target. For example, if you want to allow the optimizer to
consider only 8-, 16-, and 32-bit types, specify [8 16 32]
in the
Allowed Word Lengths (Vector) field.
To specify additional properties for the optimized lookup table, click
LUT Specification. For more information on each of the
properties, see FunctionApproximation.Options
. In this example, use the default values for
these properties.
Specify options for the optimization, such as the maximum time or maximum memory
usage for the generated lookup table by clicking the button.
After you set the constraints, click Optimize. When the optimization is complete, the optimizer reports the memory of the optimized lookup table. You can edit the constraints and run the optimization again to achieve further memory reduction.
Using the default settings, the Lookup Table Optimizer reduces the memory used by
the Pumping Constant
Lookup Table block from 1516 bytes to 572 bytes (62.27%).
Click Next.
Click Show Comparison Plot to view a plot of the original block output compared to the output of the new optimized lookup table.
Click Replace Original Function to generate a new lookup table using the optimized settings found by the app, and replace the original block.
The new block is a masked variant subsystem in which the active variant is the optimized lookup table block. The inactive variant is the original block.
You can iteratively change the approximation block by editing the settings used during the optimization to generate a new lookup table.
Double-click the Pumping Constant block. To edit the optimization settings, in the Block Parameters dialog, click Redesign approximate.
In the Lookup Table Optimizer, click Next to proceed to the Create page of the app. In this example, edit the absolute and relative tolerances to a slightly larger value so that you can further reduce the size of the lookup table.
Set the Absolute tolerance to 0.01
, or
1%.
Set the Relative tolerance to 0.01
, or
1%.
Click Optimize to optimize the lookup table with the new options.
Using these tolerance values, the new lookup table uses only 362 bytes of memory.
Click Next. On the Results page, click the Replace Original Function button to replace the first iteration of the approximation block with this newest iteration.
In the model, double-click the Pumping Constant block to open the Block Parameters. The Block Parameters displays the settings used for the approximation
To make the original block or subsystem the active variant, next to Select
desired function version, select
Original
.
To delete the lookup table approximation from the model, in the Block Parameters, click Revert to original.
FunctionApproximation.LUTMemoryUsageCalculator
| FunctionApproximation.LUTSolution
| FunctionApproximation.Options
| FunctionApproximation.Problem