Documentation

Prelookup

Compute index and fraction for Interpolation Using Prelookup block

Library

Lookup Tables

Description

How This Block Works with an Interpolation Using Prelookup Block

The Prelookup block works best with the Interpolation Using 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 User's Guide.

Supported Block Operations

To use the Prelookup block, you specify a set of breakpoint values directly on the dialog box or feed values into the bp input port. Typically, this breakpoint data set corresponds to one dimension of the table data in an Interpolation Using Prelookup block. The Prelookup block generates a pair of outputs for each input value u by calculating:

  • The index of the breakpoint set element that is less than or equal to u and forms an interval containing u

  • The interval fraction in the range 0 ≤ f < 1, which represents the normalized position of u on the breakpoint interval between the index and the next index value for in-range input

For example, if the breakpoint data set is [ 0 5 10 20 50 100 ] and the input value u is 55, the index is 4 and the fractional value is 0.1. Labels for the index and interval fraction appear as k and f on the Prelookup block icon. The index value is zero-based.

The interval fraction can be negative or greater than 1 for out-of-range input. See the documentation for the Extrapolation method block parameter for more information.

Data Type Support

The Prelookup block accepts real signals of any numeric data type that Simulink® supports, except Boolean. The Prelookup block supports fixed-point data types for signals and breakpoint data.

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

Parameters and Dialog Box

Main tab

Breakpoint data

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

  • If you set Source to Dialog, enter breakpoint data in the edit field under Value. Each breakpoint data set must be a strictly monotonically increasing vector that contains two or more elements. For this option, you specify breakpoint attributes on the Data Types pane.

  • If you set Source to Input port, verify that an upstream signal supplies breakpoint data to the bp input port. Each breakpoint data set must be a strictly monotonically increasing vector that contains two or more elements. For this option, your block inherits breakpoint attributes from the bp input port.

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

Index search method

Select Evenly spaced points, Linear search, or Binary search. Each search method has speed advantages in different situations:

  • For evenly spaced breakpoint sets (for example, 10, 20, 30, and so on), you achieve optimal speed by selecting Evenly spaced points to calculate table indices.

    This algorithm uses only the first two breakpoints of a set to determine the offset and spacing of the remaining points.

  • For unevenly spaced breakpoint sets, follow these guidelines:

    • If input values for u do not vary much between time steps, selecting Linear search with Begin index search using previous index result produces the best performance.

    • If input values for u jump more than one or two table intervals per time step, selecting Binary search produces the best performance.

A suboptimal choice of index search method can lead to slow performance of models that rely heavily on lookup tables.

    Tip   The generated code stores only the first breakpoint, the spacing, and the number of breakpoints when:

    • The breakpoint data is not tunable.

    • The index search method is Evenly spaced points.

Begin index search using previous index result

Select this check box when you want the block to start its search using the index found at the previous time step. For input values of u that change slowly with respect to the interval size, enabling this option can improve performance. Otherwise, the linear search and binary search methods can take longer, especially for large breakpoint sets.

Output only the index

Select this check box when you want the block to output only the resulting index value, without the interval fraction.

Typical applications include:

Extrapolation method

Specify how to handle out-of-range values for the block input u. Options include:

  • Clip

    Block InputBlock Outputs

    Less than the first breakpoint

    • Index of the first breakpoint (for example, 0)

    • Interval fraction of 0

    Greater than the last breakpoint

    • Index of the next-to-last breakpoint

    • Interval fraction of 1

    Suppose the range is [1 2 3] and you select this option. If u is 0.5, the index is 0 and the interval fraction is 0. If u is 3.5, the index is 1 and the interval fraction is 1.

  • Linear

    Block Input Block Outputs

    Less than the first breakpoint

    • Index of the first breakpoint (for example, 0)

    • Interval fraction that represents the linear distance from u to the first breakpoint

    Greater than the last breakpoint

    • Index of the next-to-last breakpoint

    • Interval fraction that represents the linear distance from the next-to-last breakpoint to u

    Suppose the range is [1 2 3] and you select this option. If u is 0.5, the index is 0 and the interval fraction is -0.5. If u is 3.5, the index is 1 and the interval fraction is 1.5.

    Tip   The Prelookup block supports linear extrapolation only when all of these conditions apply:

    • The input u, breakpoint data, and fraction output use floating-point data types.

    • The index uses a built-in integer data type.

Use last breakpoint for input at or above upper limit

Specify how to index input values of u that are greater than or equal to the last breakpoint. The index value is zero-based. When input equals the last breakpoint, block outputs differ as follows:

Check BoxBlock Outputs

Selected

  • Index of the last element in the breakpoint data set

  • Interval fraction of 0

Cleared

  • Index of the next-to-last breakpoint

  • Interval fraction of 1

This check box is visible only when:

  • Output only the index is cleared.

  • Extrapolation method is Clip.

However, when Output only the index is selected and Extrapolation method is Clip, the block behaves as if this check box is selected even though it is invisible.

    Tip   When you select Use last breakpoint for input at or above upper limit for a Prelookup block, you must also select Valid index input may reach last index for the Interpolation Using Prelookup block to which it connects. 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 u 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 input in generated code

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

Check BoxResultWhen to Use

Selected

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

For code efficiency

Cleared

Generated code includes conditional statements to check for out-of-range breakpoint 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 Run Model Checks in the Simulink documentation.

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 User's Guide for more information.

Data Types tab

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

Breakpoint > Data Type

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

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

  • 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 breakpoint data type.

See Specify Data Types Using Data Type Assistant for more information.

    Tip   Specify a breakpoint data type different from the data type of input u for these cases:

    • Lower memory requirement for storing breakpoint data that uses a smaller type than the input signal u

    • Sharing of prescaled breakpoint data between two Prelookup blocks with different data types for input u

    • Sharing of custom storage breakpoint data in the generated code for blocks with different data types for input u

Breakpoint > Minimum

Specify the minimum value that the breakpoint data can have. The default value is [] (unspecified).

Breakpoint > Maximum

Specify the maximum value that the breakpoint data can have. The default value is [] (unspecified).

Index > Data Type

Specify a data type that can index all elements in the breakpoint data set. You can:

  • Select a built-in integer data type from the list.

  • Specify an integer data type using a fixed-point representation.

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

See Specify Data Types Using Data Type Assistant for more information.

Fraction > Data Type

Specify the data type of the interval fraction. You can:

  • Select a built-in data type from the list.

  • Specify data type inheritance through an internal rule.

  • Specify a fixed-point data type using the [Slope Bias] or binary-point-only scaling representation.

    • If you use the [Slope Bias] representation, the scaling must be trivial — that is, the slope is 1 and the bias is 0.

    • If you use the binary-point-only representation, the fixed power-of-two exponent must be less than or equal to zero.

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

See Specify Data Types Using Data Type Assistant for more information.

Lock output data type setting against changes by the fixed-point tools

Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor. For more information, see Use Lock Output Data Type Setting.

Integer rounding mode

Specify the rounding mode for fixed-point operations. For more information, see Rounding in the Simulink Fixed Point™ 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 into the mask field.

Examples

In the following modelmodel, a Constant block feeds the breakpoint data set to the bp input port of the Prelookup block.

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

Breakpoint AttributeValue
MinimumInf
MaximumInf
Data typesingle

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

Table 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

Was this topic helpful?