Main Content

Lookup Table Optimizer

Optimize existing lookup table or approximate function with lookup table

Description

Use the Lookup Table Optimizer app to obtain an optimized (memory-efficient) lookup table.

Using this app, you can:

  • Approximate an existing Simulink® block, including Subsystem blocks and math function blocks

  • Approximate a MATLAB® handle

  • Approximate a curve fit object

You can choose to return the optimized lookup table as a Simulink block or as a MATLAB function.

The optimizer supports any combination of floating-point and fixed-point data types. The original input and output data types can be kept or changed as desired. To minimize memory used, the optimizer selects the data types of breakpoints and table data as well as the number and spacing of breakpoints.

Screenshot of Lookup Table Optimizer app

Open the Lookup Table Optimizer App

  • Simulink toolstrip: On the Apps tab, under Code Generation, click the app icon.

  • In a Simulink model with a Lookup Table block, select the Lookup Table block. In the Lookup Table tab, select Lookup Table Optimizer.

Parameters

expand all

Select the source for memory-efficient LUT:

  • Simulink block or subsystem — Simulink block or subsystem to approximate, or lookup table block to optimize, for example, 1-D Lookup Table or n-D Lookup Table. If you specify one of the lookup table blocks, the app generates an optimized lookup table.

  • MATLAB function handle — MATLAB function handle to approximate with a lookup table. Function handles must be on the MATLAB search path, or approximation fails.

  • Fitted curve — Curve fit cfit (Curve Fitting Toolbox) object from the base workspace to approximate. For a list of library models to approximate, see List of Library Models for Curve and Surface Fitting (Curve Fitting Toolbox).

Tip

The process of generating a lookup table approximation is faster for a function handle than for a subsystem. If a subsystem can be represented by a function handle, approximating the function handle is faster.

Specify the maximum tolerance of the Absolute and Relative difference between the original output value and the output value of the approximation.

Specify the word lengths, in bits, that can be used in the lookup table approximation based on your intended hardware. For example, if you intend to target an embedded processor, you can restrict the data types in your lookup table to native types. The word lengths must be between 1 and 128.

Specify options to use for the optimized lookup table.

OptionDescription
Interpolation

When an input falls between breakpoint values, the lookup table interpolates the output value using neighboring breakpoints.

  • Linear — Fits a line between the adjacent breakpoints and returns the point on that line that corresponds to the input.

  • Flat — Returns the output value that corresponds to the breakpoint value that is immediately less than the input value. If no breakpoint value exists below the input value, this option returns the breakpoint value nearest to the input value.

  • Nearest — Returns the value that corresponds to the breakpoint that is closest to the input. If the input is equidistant from two adjacent breakpoints, this option selects the breakpoint with the higher index.

  • None — Generates a Direct Lookup Table (n-D) block, which performs table lookups without any interpolation or extrapolation.

    Note

    When generating a Direct Lookup Table block, the maximum number of inputs is two.

Breakpoint specification

Spacing of breakpoint data.

  • ExplicitValues — Lookup table breakpoints are specified explicitly. Breakpoints can be closer together for some input ranges and farther apart in others.

  • EvenSpacing — Lookup table breakpoints are evenly spaced throughout.

  • EvanPow2Spacing — Lookup table breakpoints use power-of-two spacing. This breakpoint specification boasts the fastest execution speed because a bit shift can replace the position search.

For more information on how breakpoint specification can affect performance, see Effects of Spacing on Speed, Error, and Memory Usage.

Saturate to output type

Whether to automatically saturate the range of the output of the function to approximate to the range of the output data type.

AUTOSAR Compliant

Whether the generated lookup table is AUTOSAR compliant. When this option is set to True,

  • The generated lookup table is a Curve or Map block from the AUTOSAR Blockset.

  • The data type of the table data must equal the output data type of the block.

  • An AUTOSAR Blockset license is checked out.

This option is not supported when the Solution Type option is set to MATLAB.

Explore Half

Whether to allow the optimizer to explore half-precision data types for table data and breakpoints.

HDL Optimized

Whether to generate an HDL-optimized approximation. When this option is set to True, the generated approximation is a subsystem consisting of a prelookup step followed by interpolation that functions as a lookup table with explicit pipelining to generate efficient HDL code.

To generate an HDL-optimized approximation, the function to approximate must be one-dimensional and Breakpoint specification must be set to EvenSpacing or EvenPow2Spacing. This property is not supported when the Solution Type option is set to MATLAB.

Solution Type

How the app outputs the optimized lookup table.

  • Simlink — Generate a Simulink subsystem containing the optimized lookup table.

  • MATLAB — Output the optimized lookup table as a MATLAB function. Generating an optimized lookup table as a MATLAB function is not supported when:

    • The AUTOSARCompliant property is set to true.

    • The UseParallel property is set to true.

    • The HDLOptimized property is set to true.

    • The InterpolationMethod property is set to 'None'.

Note

The Simulink block and MATLAB function lookup table approximations generated by the Lookup Table Optimizer may not be exactly numerically equivalent. However, both solution forms are guaranteed to meet all constraints specified in the optimization problem.

Specify additional optimization options.

OptionDescription
Max time

Maximum amount of time for the approximation to run, specified in seconds as a scalar number. The approximation runs until it reaches the time specified, finds an ideal solution, or reaches another stopping criterion.

Default: Inf

Max memory usage (bytes)

The maximum amount of memory the generated lookup table can use, in bytes, specified as a scalar integer.

Default: 10000000

On curve table values

Whether to constrain table values to the quantized output of the function being approximated. When you set this option to False and allow off-curve table values, you may be able to reduce the memory of the lookup table while maintaining the same error tolerances or maintain the same memory while reducing the error tolerances.

Default: False

Use parallel

Whether to run iterations of the optimization in parallel. Running iterations in parallel requires a Parallel Computing Toolbox™ license. If you do not have a Parallel Computing Toolbox, or if you specify False, the iterations run in serial.

This option is not supported when the Solution Type option is set to MATLAB.

Default: False

Limitations

  • Lookup table objects and breakpoint objects are not supported in a model mask workspace.

  • Functions and function handles that you approximate must meet these criteria:

    • The function must be time-invariant.

    • The function must operate element-wise, meaning for each input there is one output.

    • The function must not contain states.

    For more information, see Vectorization.

Algorithms

expand all

Version History

Introduced in R2018a

expand all