Documentation Center

  • Trial Software
  • Product Updates

Interpolation Using Prelookup

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

Library

Lookup Tables

Description

How This Block Works with a Prelookup Block

The Interpolation Using Prelookup block works best 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. You 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 in the Simulink® documentation.

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. Therefore, the value must be less than or equal to the Number of table dimensions.

Suppose that you have 3-D table data in your Interpolation Using Prelookup block. The following behavior applies.

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 dimensionDisplays an input port with the label sel1 that you use to select and interpolate 2-D tables
2Interpolates the first dimension and selects the second and third dimensionsDisplays two input ports with the labels sel1 and sel2 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, type sldemo_bpchecksldemo_bpcheck at the MATLAB® command prompt.

Data Type Support

The Interpolation Using Prelookup block accepts real signals of any numeric data type supported by Simulink software, except Boolean. The Interpolation Using Prelookup block supports fixed-point data types for signals, table data, and intermediate results.

For more information, see Data Types Supported by Simulink in the Simulink documentation.

Parameters and Dialog Box

Main tab

Number of table dimensions

Specify the number of dimensions that the table data must have. This value defines the number of independent variables for the table. Enter an integer between 1 and 30 into this field.

Table data

Specify whether to enter table data directly on the dialog box or to inherit the data from an input port.

  • If you set Source to Dialog, enter table data in the edit field under Value. The size of the table data must match the Number of table dimensions. For this option, you specify table attributes on the Data Types pane.

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

During block diagram editing, you can enter an empty matrix (specified as []) or an undefined workspace variable in the edit field under Value. Use this behavior to postpone specifying a correctly dimensioned matrix for the table data and continue editing the block diagram. For information about how to construct multidimensional arrays in MATLAB, see Multidimensional Arrays in the MATLAB documentation.

Click the Edit button to open the Lookup Table Editor (see Edit Existing LookupTables in the Simulink documentation).

Interpolation method

Select Flat or Linear. See Interpolation Methods in the Simulink documentation for more information.

Extrapolation method

Select Clip or Linear. See Extrapolation Methods in the Simulink documentation for more information. The Extrapolation method parameter is visible only when you select Linear as the Interpolation method parameter.

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

Valid index input may reach last index

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.

Check BoxBlock Behavior

Selected

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

Cleared

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

This check box is visible only when:

  • Interpolation method is Linear.

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

Diagnostic for out-of-range input

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

  • None — no warning or error

  • Warning — display a warning in the MATLAB Command Window and continue the simulation

  • Error — halt the simulation and display an error in the Diagnostic Viewer

Remove protection against out-of-range index in generated code

Specify whether or not to include code that checks for out-of-range index inputs.

Check BoxResultWhen to Use

Selected

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

For code efficiency

Cleared

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

For safety-critical applications

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 Verification and Validation > Modeling Standards > DO-178C/DO-331 Checks > Check usage of lookup table blocks

For more information about the Model Advisor, see Consult the Model Advisor in the Simulink documentation.

This check box has no effect on 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.

Number of sub-table selection dimensions

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 more information, see How The Block Interpolates a Subset of Table Data.

Sample time

Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See Specify Sample Time in the Simulink documentation for more information.

Data Types tab

    Note:   The parameters for table attributes (data type, minimum, and maximum) are not available when you set Source to Input port. In this case, the block inherits all table attributes from the T input port.

Table data > Data Type

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

Table data > Minimum

Specify the minimum value for table data. The default value is [] (unspecified).

Table data > Maximum

Specify the maximum value for table data. The default value is [] (unspecified).

Intermediate results > Data Type

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)

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

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

Output > Data Type

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 Specify Block Output Data Types for more information.

Output > Minimum

Specify the minimum value that the block should output. The default value is [] (unspecified). Simulink software uses this value to perform:

Output > Maximum

Specify the maximum value that the block should output. The default value is [] (unspecified). Simulink software uses this value to perform:

Internal rule priority

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.

Lock data type settings against changes by the fixed-point tools

Select to lock all data type settings of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor. For more information, see Lock the Output Data Type Setting in the Fixed-Point Designer™ documentation.

Integer rounding mode

Specify the rounding mode for fixed-point operations. For more information, see Rounding in the Fixed-Point Designer documentation.

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.

Saturate on integer overflow
ActionReasons for Taking This ActionWhat Happens for OverflowsExample

Select this check box.

Your model has possible overflow, and you want explicit saturation protection in the generated code.

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

The maximum value that the int8 (signed, 8-bit integer) data type can represent is 127. Any block operation result greater than this maximum value causes overflow of the 8-bit integer. With the check box selected, the block output saturates at 127. Similarly, the block output saturates at a minimum output value of -128.

Do not select this check box.

You want to optimize efficiency of your generated code.

You want to avoid overspecifying how a block handles out-of-range signals. For more information, see Checking for Signal Range Errors.

Overflows wrap to the appropriate value that is representable by the data type.

The maximum value that the int8 (signed, 8-bit integer) data type can represent is 127. Any block operation result greater than this maximum value causes overflow of the 8-bit integer. With the check box 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.

When you select this check box, saturation applies to every internal operation on the block, not just the output or result. Usually, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.

Examples

In the following modelmodel, a Constant block feeds the table data values to the T input port of the Interpolation Using Prelookup block.

The Interpolation Using Prelookup block inherits the following table attributes from the T input port:

Table AttributeValue
MinimumInf
MaximumInf
Data typesingle

Similarly, a Constant block feeds the breakpoint data set to the bp input port of the Prelookup block, which inherits the following breakpoint attributes:

Breakpoint AttributeValue
MinimumInf
MaximumInf
Data typesingle

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.

For other examples, see Prelookup and Interpolation Blocks in the Simulink documentation.

Characteristics

Direct Feedthrough

Yes

Sample Time

Specified in the Sample time parameter

Scalar Expansion

Yes

Dimensionalized

Yes

Zero-Crossing Detection

No

See Also

Prelookup

Was this topic helpful?