Main Content

Interpolation Using Prelookup

Use precalculated index and fraction values to accelerate approximation of N-dimensional function

  • Interpolation Using Prelookup block

Libraries:
Simulink / Lookup Tables

Description

The Interpolation Using Prelookup block is most efficient when used with the Prelookup block. The Prelookup block calculates the index and interval fraction that specify how its input value u relates to the breakpoint data set. Feed the resulting index and fraction values into an Interpolation Using Prelookup block to interpolate an n-dimensional table. These two blocks have distributed algorithms. When combined together, they perform the same operation as the integrated algorithm in the n-D Lookup Table block. However, the Prelookup and Interpolation Using Prelookup blocks offer greater flexibility that can provide more efficient simulation and code generation. For more information, see Efficiency of Performance.

Supported Block Operations

To use the Interpolation Using Prelookup block, you specify a set of table data values directly on the dialog box or feed values into the T input port. Typically, these table values correspond to the breakpoint data sets specified in Prelookup blocks. The Interpolation Using Prelookup block generates output by looking up or estimating table values based on index and interval fraction values fed from Prelookup blocks. Labels for the index and interval fraction appear as k and f on the Interpolation Using Prelookup block icon.

When inputs for index and interval fraction...The Interpolation Using Prelookup block...
Map to values in breakpoint data setsOutputs the table value at the intersection of the row, column, and higher dimension breakpoints
Do not map to values in breakpoint data sets, but are within rangeInterpolates appropriate table values using the Interpolation method you select
Do not map to values in breakpoint data sets, and are out of rangeExtrapolates the output value using the Extrapolation method you select

How The Block Interpolates a Subset of Table Data

You can use the Number of sub-table selection dimensions parameter to specify that interpolation occur only on a subset of the table data. To activate this interpolation mode, set this parameter to a positive integer. This value defines the number of dimensions to select, starting from the highest dimension of table data for the default column-major algorithm. Therefore, the value must be less than or equal to the Number of table dimensions.

For row-major algorithms, the interpolation starts from the first or lowest dimension of the table data.

For nonzero values, the subtable selection behavior is optimized for row-major layout when you select the Math and Data Types > Use algorithms optimized for row-major array layout configuration parameter.

Suppose that you have 3-D table data in your Interpolation Using Prelookup block. This behavior applies for the column-major algorithm.

Number of Selection DimensionsAction by the BlockBlock Appearance
0Interpolates the entire table and does not activate subtable selectionDoes not change
1Interpolates the first two dimensions and selects the third dimension Displays an input port with the label s3 that you use to select and interpolate 2-D tables
2Interpolates the first dimension and selects the second and third dimensions Displays two input ports with the labels s2 and s3 that you use to select and interpolate 1-D tables

Subtable selection uses zero-based indexing. For an example of interpolating a subset of table data, see Using the Prelookup and Interpolation Blocks.

For 2-D or n-D interpolation without subtable selection, the column-major and row-major algorithms may differ in the order of output calculations, causing slight different numerical results.

Examples

expand all

This example shows how to feed a breakpoint data set from a Constant block into the bp input port of the Prelookup block.

The Prelookup block inherits these breakpoint attributes from the bp input port:

  • Minimum: Inf

  • Maximum: Inf

  • Data type: single

Similarly, a Constant block feeds the table data values to the T input port of the Interpolation Using Prelookup block, which inherits these attributes:

  • Minimum: Inf

  • Maximum: Inf

  • Data type: single

Simulink® uses double-precision, floating-point data to perform the computations in this model. However, the model stores the breakpoint and table data as single-precision, floating-point data. Using a lower-precision data type to store breakpoint and table data reduces the memory requirement.

This example shows how to specify evenly spaced breakpoint data in the Prelookup block.

In the Breakpoints data section, the Specification parameter is set to Even spacing. The parameters First point, Spacing, and Number of points are set to 25, 12, and 4 respectively. Specifying these parameters creates four evenly spaced breakpoints: [25, 37, 49, 61].

An alternative way to specify evenly spaced breakpoints is to set Specification to Explicit values and set Value to [25:12:61].

Simulink® uses double-precision, floating-point data to perform the computations in this model. However, the model stores the breakpoints and table data as double.

This example shows how to output a bus containing the index (k) and fraction (f) from the Prelookup block. The bus object can then be used as an input to the Interpolation Using Prelookup block. The example also shows how to get the same results without using a bus object.

Open and simulate the model.

At the top of the model, open the dialog box for the Prelookup block. In the Main tab, note that Output selection is set to Index and fraction as bus. In the Data Types tab, note that Output is set to Bus: myBus. In the Simulink® Editor, select Modeling>Model Settings>Model Properties and open the Callbacks tab. In the model's PreLoadFcn, the code defines the bus object myBus, which specifies the index as the first bus element and the fraction as the second element.

Open the dialog box for the Interpolation Using Prelookup block. In the Main tab, note that Require index and fraction as bus check box is selected. That option configures the block to use the bus output from the Prelookup block.

Extended Examples

Ports

Input

expand all

Zero-based index, k, specifying the interval containing the input u for the first dimension of the table.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Fraction, f, representing the normalized position of the input within the interval, k, for the first dimension of the table.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Zero-based index, k, specifying the interval containing the input u for the n-th dimension of the table.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Fraction, f, representing the normalized position of the input within the interval, k, for the n-th dimension of the table.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Inputs to the kf1 port contain index k and fraction f specified as a bus object.

Dependencies

To enable this port, select the Require index and fraction as a bus check box.

The number of available kf input ports depends on the value of the Number of dimensions and Number of sub-table selection dimensions parameters.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point | bus

Inputs to the kfn port contain index k and fraction f for the n-th dimension of the input, specified as a bus object.

Dependencies

To enable this port, select the Require index and fraction as a bus check box.

The number of available kf input ports depends on the value of the Number of dimensions and Number of sub-table selection dimensions parameters.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point | bus

For column-major algorithm, the block uses inputs to the sm, sm+1, ... sn port to perform selection and interpolation within the subtables. m maps to the mth dimension of the table. n equals the Number of dimensions.

For row-major algorithm, the block uses inputs to the s1, s2,... ,sm port to perform selection and interpolation within the subtables. m maps to the mth dimension of the table. m equals the Number of sub-table selection dimensions.

Dependencies

To enable this port, the Number of sub-table selection dimensions must be a positive integer less than or equal to the Number of dimensions.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus

Table data values provided as input to port T. Typically, these table values correspond to the breakpoint data sets specified in Prelookup blocks. The Interpolation Using Prelookup block generates output by looking up or estimating table values based on index (k) and interval fraction (f) values fed from Prelookup blocks.

Dependencies

To enable this port, set Source to Input port.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Output

expand all

Approximation of N-dimensional function, computed by interpolating (or extrapolating) table data using values from the input index, k, and fraction, f.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Parameters

expand all

Main

Table data

Specify the number of dimensions that the table data must have. The Number of dimensions defines the number of independent variables for the table.

To specify...Do this...

1, 2, 3, or 4

Select the value from the drop-down list.

A higher number of table dimensions

Enter a positive integer directly in the field.

The maximum number of table dimensions that this block supports is 30.

Programmatic Use

Block Parameter: NumberOfTableDimensions
Type: character vector
Values: '1' | '2' | '3' |'4' | ... | '30'
Default: '2'

Select this check box to combine index and fraction inputs in a bus.

To enable the Prelookup block to supply input to the Interpolation Using Prelookup block, set:

  • Output selection to Index and fraction as bus

  • Output to Bus: <object name>, where <object name> must be a valid bus object name accessible to the model

Regardless of this check box setting, the selection port always operates in nonbus mode.

Programmatic Use

Block Parameter: RequireIndexFractionAsBus
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Specify whether to enter table data directly or use a lookup table object. If you set this parameter to:

  • Explicit values, the Source and Value parameters are visible on the dialog box.

  • Lookup table object, the Name parameter is visible on the dialog box.

Programmatic Use

Block Parameter: TableSpecification
Type: character vector
Values: 'Explicit values' | 'Lookup table object'
Default: 'Explicit values'

To set this parameter from 'Explicit values' to 'Lookup table object', use the same set_param call to set the LookupTableObject parameter. For example:

set_param('myModel/myInterpBlock',...
   'TableSpecification','Lookup table object',...
   'LookupTableObject','myLUTObject')

Specify whether to enter table data in the dialog box or to inherit the data from an input port. If you set Source to:

  • Dialog, enter table data in the text box under Value

  • Input port, verify that an upstream signal supplies table data to the table input port

Dependencies

To enable this parameter, set Specification to Explicit values.

Programmatic Use

Block Parameter: TableSource
Type: character vector
Values: 'Dialog' | 'Input port'
Default: 'Dialog'

Specify table data as an N-D array, where N is the value of the Number of dimensions parameter. You can edit the block diagram without specifying a correctly dimensioned matrix by entering an empty matrix ([]) or an undefined workspace variable in the Value edit field. For information about how to construct multidimensional arrays in MATLAB®, see Multidimensional Arrays.

If you set Source to Input port, verify that an upstream signal supplies table data to the T input port. The size of table data must match the Number of table dimensions. For this option, the block inherits table attributes from the T input port.

To edit lookup tables using the Lookup Table Editor, click Edit (see Edit Lookup Tables).

Dependencies

To enable this parameter and explicitly specify table values on the dialog box, you must set Specification to Explicit values and Source to Dialog.

Programmatic Use

Block Parameter: Table
Type: character vector
Values: scalar | vector | matrix | N-D array
Default: 'sqrt([1:11]' * [1:11])'

Specify the name of a Simulink.LookupTable object. A lookup table object references Simulink® breakpoint objects. If a Simulink.LookupTable object does not exist, click the action button and select Create. The corresponding parameters of the new lookup table object are automatically populated with the block information.

Dependencies

To enable this parameter, set Specification to Lookup table object.

Programmatic Use

Block Parameter: LookupTableObject
Type: character vector
Value: Simulink.LookupTable object
Default: ''
Algorithm

Specify the method the block uses to interpolate table data. You can select Linear point-slope, Flat, Nearest, or Linear Lagrange. See Interpolation Methods for more information.

Programmatic Use

Block Parameter: InterpMethod
Type: character vector
Values: 'Flat' | 'Linear point-slope' | 'Nearest' | 'Linear Lagrange'
Default: 'Linear point-slope'

Specify the method the block uses to extrapolate values for all inputs that fall outside the range of the breakpoint data set. You can select Clip or Linear. See Extrapolation Methods for more information.

If the extrapolation method is Linear, the extrapolation value is calculated based on the selected linear interpolation method. For example, if the interpolation method is Linear Lagrange, the extrapolation method inherits the Linear Lagrange equation to compute the extrapolated value.

To use Prelookup and Interpolation Using Prelookup blocks to replicate n-D Lookup Table block behavior, the Extrapolation method for both Prelookup and Interpolation Using Prelookup blocks must be the same as if you use only the n-D Lookup Table block. For example, to get the same behavior as the n-D Lookup Table block with Extrapolation method set to Linear, set Extrapolation method to Linear for both Prelookup and Interpolation Using Prelookup blocks.

Dependencies

To enable the Extrapolation method parameter, set the Interpolation method to Linear.

The Interpolation Using Prelookup block does not support Linear extrapolation when the input or output signals specify integer or fixed-point data types.

Programmatic Use

Block Parameter: ExtrapMethod
Type: character vector
Values: 'Clip' | 'Linear'
Default: 'Linear'

Specify how block inputs for index (k) and interval fraction (f) access the last elements of n-dimensional table data. Index values are zero based.

This check box is relevant if the input index is equal to or larger than the table's last index for that dimension. Due to rounding, selecting and clearing this check box may result in differing results for the last index between simulation and code generation.

Check BoxBlock Behavior

on

Returns the value of the last element in a dimension of its table when:

  • k indexes the last table element in the corresponding dimension

  • f is 0

off

Returns the value of the last element in a dimension of its table when:

  • k indexes the next-to-last table element in the corresponding dimension

  • f is 1

Dependencies

This check box is visible only when:

  • Interpolation method is Linear point-slope or Linear Lagrange

  • Extrapolation method is Clip

Tip

When you select Valid index input may reach last index for an Interpolation Using Prelookup block, you must also select Use last breakpoint for input at or above upper limit for all Prelookup blocks that feed it. This action allows the blocks to use the same indexing convention when accessing the last elements of their breakpoint and table data sets.

Programmatic Use

Block Parameter: ValidIndexMayReachLast
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Specify whether to produce a warning or error when the input is out of range. Options include:

  • None — Produce no response.

  • Warning — Display a warning and continue the simulation.

  • Error — Terminate the simulation and display an error.

Programmatic Use

Block Parameter: DiagnosticForOutOfRangeInput
Type: character vector
Values: 'None' | 'Warning' | 'Error'
Default: 'None'

Specify the number of dimensions of the subtable that the block uses to compute the output. Follow these rules:

  • To enable subtable selection, enter a positive integer.

    This integer must be less than or equal to the Number of table dimensions.

  • To disable subtable selection, enter 0 to interpolate the entire table.

For nonzero values, the subtable selection behavior is optimized for row-major layout when you select the Math and Data Types > Use algorithms optimized for row-major array layout configuration parameter.

For more information, see How The Block Interpolates a Subset of Table Data.

Programmatic Use

Block Parameter: NumSelectionDims
Type: character vector
Values: '0' | '1' | '2' | '3' | '4' | ... | Number of table dimensions
Default: '0'
Code generation
Check BoxResultWhen to Use

on

Generated code does not include conditional statements to check for out-of-range index inputs.

When the input k or f is out of range, it may cause undefined behavior for generated code.

For code efficiency

off

Generated code includes conditional statements to check for out-of-range index inputs.

For safety-critical applications

If your input is not out of range, you can select the Remove protection against out-of-range index in generated code check box for code efficiency. By default, this check box is cleared. For safety-critical applications, do not select this check box. If you want to select the Remove protection against out-of-range index in generated code check box, first check that your model inputs are in range. For example:

  1. Clear the Remove protection against out-of-range index in generated code check box.

  2. Set the Diagnostic for out-of-range input parameter to Error.

  3. Simulate the model in normal mode.

  4. If there are out-of-range errors, fix them to be in range and run the simulation again.

  5. When the simulation no longer generates out-of-range input errors, select the Remove protection against out-of-range index in generated code check box.

    Note

    When you select the Remove protection against out-of-range index in generated code check box and the input k or f is out of range, the behavior is undefined for generated code.

Depending on your application, you can run the following Model Advisor checks to verify the usage of this check box:

  • By Product > Embedded Coder > Identify lookup table blocks that generate expensive out-of-range checking code

  • By Product > Simulink Check > Modeling Standards > DO-178C/DO-331 Checks > Check usage of lookup table blocks

For more information about the Model Advisor, see Run Model Advisor Checks.

Additionally, to determine if it is safe to select this check box, if you have a Simulink Design Verifier™ license, consider using the Detect Block Input Range Violations (Simulink Design Verifier) check.

This check box has no effect on the generated code when one of the following is true:

  • The Prelookup block feeds index values to the Interpolation Using Prelookup block.

    Because index values from the Prelookup block are always valid, no check code is necessary.

  • The data type of the input k restricts the data to valid index values.

    For example, unsigned integer data types guarantee nonnegative index values. Therefore, unsigned input values of k do not require check code for negative values.

Programmatic Use

Block Parameter: RemoveProtectionIndex
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Specify the time interval between samples. To inherit the sample time, set this parameter to -1. For more information, see Specify Sample Time.

Dependencies

This parameter is visible only if you set it to a value other than -1. To learn more, see Blocks for Which Sample Time Is Not Recommended.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: SampleTime
Values: "-1" (default) | scalar or vector in quotes

Data Types

Specify the table data type. You can set it to:

  • A rule that inherits a data type, for example, Inherit: Same as output

  • The name of a built-in data type, for example, single

  • The name of a data type object, for example, a Simulink.NumericType object

  • An expression that evaluates to a data type, for example, fixdt(1,16,0)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the table data type.

Tip

Specify a table data type different from the output data type for these cases:

  • Lower memory requirement for storing table data that uses a smaller type than the output signal

  • Sharing of prescaled table data between two Interpolation Using Prelookup blocks with different output data types

  • Sharing of custom storage table data in Simulink Coder™ generated code for blocks with different output data types

Programmatic Use

Block Parameter: TableDataTypeStr
Type: character vector
Values: 'Inherit: Inherit from table data' | 'Inherit: Same as output' | 'double' | 'single' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | 'fixdt(1,16)' | 'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)' | '<data type expression>'
Default: 'Inherit: Same as output'

Specify the minimum value for table data as a finite, real, double, scalar. The default value is [] (unspecified).

Programmatic Use

Block Parameter: TableMin
Type: character vector
Values: scalar
Default: '[]'

Specify the maximum value for table data as a finite, real, double, scalar. The default value is [] (unspecified).

Programmatic Use

Block Parameter: TableMax
Type: character vector
Values: scalar
Default: '[]'

Specify the intermediate results data type. You can set it to:

  • A rule that inherits a data type, for example, Inherit: Same as output

  • The name of a built-in data type, for example, single

  • The name of a data type object, for example, a Simulink.NumericType object

  • An expression that evaluates to a data type, for example, fixdt(1,16,0)

The Data Type Assistant helps you set data attributes. To use the Data Type Assistant, click the Show data type assistant button. For more information, see Specify Data Types Using Data Type Assistant.

Tip

Use this parameter to specify higher precision for internal computations than for table data or output data.

Programmatic Use

Block Parameter: IntermediateResultsDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule' | 'Inherit: Same as output' | 'double' | 'single' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | 'fixdt(1,16)' | 'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)' | '<data type expression>'
Default: 'Inherit: Inherit via internal rule'

Specify the output data type. You can set it to:

  • A rule that inherits a data type, for example, Inherit: Inherit via back propagation

  • The name of a built-in data type, for example, single

  • The name of a data type object, for example, a Simulink.NumericType object

  • An expression that evaluates to a data type, for example, fixdt(1,16,0)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the output data type.

See Control Data Types of Signals for more information.

Programmatic Use

Block Parameter: OutDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via back propagation' | 'Inherit: Inherit from table data' | 'double' | 'single' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | 'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)' | 'fixdt(1,16,2^0,0)' | '<data type expression>'
Default: 'Inherit: Inherit from table data'

Specify the minimum value that the block should output as a finite, real-valued scalar. The default value is [] (unspecified). Simulink software uses this value to perform:

Programmatic Use

Block Parameter: OutMin
Type: character vector
Values: scalar
Default: '[]'

Specify the maximum value that the block should output as a finite, real-valued scalar. The default value is [] (unspecified). Simulink software uses this value to perform:

Programmatic Use

Block Parameter: OutMax
Type: character vector
Values: scalar
Default: '[]'

Specify the internal rule for intermediate calculations. Select Speed for faster calculations. If you do, a loss of accuracy might occur, usually up to 2 bits.

Programmatic Use

Block Parameter: InternalRulePriority
Type: character vector
Values: 'Speed' | 'Precision'
Default: 'Speed'

Select this parameter to prevent the fixed-point tools from overriding the data types you specify on this block. For more information, see Lock the Output Data Type Setting (Fixed-Point Designer).

Programmatic Use

Block Parameter: LockScale
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Specify the rounding mode for fixed-point operations. For more information, see Rounding Modes (Fixed-Point Designer).

Block parameters always round to the nearest representable value. To control the rounding of a block parameter, enter an expression using a MATLAB rounding function in the mask field.

Programmatic Use

Block Parameter: RndMeth
Type: character vector
Values: 'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' | 'Zero'
Default: 'Floor'

Specify whether overflows saturate or wrap.

  • on — Overflows saturate to either the minimum or maximum value that the data type can represent.

  • off — Overflows wrap to the appropriate value that the data type can represent.

For example, the maximum value that the signed 8-bit integer int8 can represent is 127. Any block operation result greater than this maximum value causes overflow of the 8-bit integer.

  • With this parameter selected, the block output saturates at 127. Similarly, the block output saturates at a minimum output value of -128.

  • With this parameter cleared, the software interprets the overflow-causing value as int8, which can produce an unintended result. For example, a block result of 130 (binary 1000 0010) expressed as int8 is -126.

Tips

  • Consider selecting this parameter when your model has a possible overflow and you want explicit saturation protection in the generated code.

  • Consider clearing this parameter when you want to optimize efficiency of your generated code. Clearing this parameter also helps you to avoid overspecifying how a block handles out-of-range signals. For more information, see Troubleshoot Signal Range Errors.

  • When you select this parameter, saturation applies to every internal operation on the block, not just the output or result.

  • In general, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: SaturateOnIntegerOverflow
Values: 'off' (default) | 'on'

Block Characteristics

Data Types

double | fixed point | integer | single

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

no

Zero-Crossing Detection

no

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Version History

Introduced in R2006b