This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Optimize Lookup Tables for Memory-Efficiency

The Lookup Table Optimizer optimizes the spacing of the breakpoints and the data types of the 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.

Optimize an Existing Lookup Table Using the Lookup Table Optimizer

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');
This example shows how to optimize the Pumping Constant lookup table block.

  1. To open the Lookup Table Optimizer, in the model menu, select Analysis > Data Type Design > Lookup Table Optimizer.

  2. 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.

  3. Under Existing Block Information, enter the path to the Lookup Table block. Select the block in the model, then click Get Current Block in the Optimizer to fill in the block path automatically.

  4. Click the Collect Current Values from Model button to update the model diagram and allow the 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.

  5. 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.

  6. 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.

  7. 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.

  8. Specify options for the optimization, such as the max time or maximum memory usage for the generated lookup table by clicking the button.

  9. 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 942 bytes (37.86%).

    Click Next.

  10. 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 with the new block.

See Also

Apps

Classes

Related Topics