Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Prelookup - Compute index and fraction for Interpolation Using Prelookup block

Library

Lookup Tables

Description

Comparison with the Lookup Table (n-D) Block

The Prelookup block works best with the Interpolation Using Prelookup block. The Prelookup block calculates the index and interval fraction that specifies how its input value 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. This combination of blocks performs the same operation that a single instance of the Lookup Table (n-D) block performs. However, the Prelookup and Interpolation Using Prelookup blocks offer greater flexibility that can provide more efficient simulation and code generation.

How the Block Works with an Interpolation Using Prelookup Block

To use this block, you must define a set of breakpoint values. Typically, this breakpoint data set corresponds to one dimension of the Table data parameter in an Interpolation Using Prelookup block. The block generates a pair of outputs for each input value by calculating:

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, denoted respectively as k and f on the block. The index value is zero-based.

Data Type Support

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

For a discussion on the data types supported by Simulink software, see Data Types Supported by Simulink in the Simulink documentation.

Parameters and Dialog Box

The Main pane of the Prelookup block dialog box appears as follows:

Breakpoint data

The set of numbers to search. Specify a strictly monotonically increasing vector that contains two or more elements.

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

Index search method

Select Evenly spaced points, Linear search, or Binary search (the default). Each search method has speed advantages in different circumstances:

  • 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 signals do not vary much between time steps, selecting Linear search with Begin index search using previous index result produces the best performance.

    • If input signals 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.

    Note   Real-Time Workshop 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 inputs 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.

Typical applications include:

  • Feeding a Direct Lookup Table (n-D) block, with no interpolation on the interval

  • Feeding selection ports of a sub-table selection for an Interpolation Using Prelookup block

  • Performing nonlinear quantizations

Process out-of-range input

Specifies how to handle out-of-range input. Options include:

  • Clip to range

    If the input is less than the first breakpoint, return the index of the first breakpoint (for example, 0) and 0 for the interval fraction. If the input is greater than the last breakpoint, return the index of the next-to-last breakpoint and 1 for the interval fraction.

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

  • Linear extrapolation

    If the input is less than the first breakpoint, return the index of the first breakpoint (for example, 0) and an interval fraction representing the linear distance from the input to the first breakpoint. If the input is greater than the last breakpoint, return the index of the next-to-last breakpoint and an interval fraction that represents the linear distance from the next-to-last breakpoint to the input.

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

    The Prelookup block supports Linear extrapolation only if all of these conditions apply:

    • The block input, breakpoint data, and fraction output specify floating-point data types.

    • The data type of its index specifies a built-in integer.

Use last breakpoint for input at or above upper limit

Specifies how to index inputs that are greater than or equal to the last breakpoint. The index value is zero-based.

If this check box is...The block returns these values when the input equals the last breakpoint...
Selected
  • Index of the last element in the breakpoint data set

  • Interval fraction of 0

Not selected
  • Index of the next-to-last breakpoint

  • Interval fraction of 1

This check box is visible only when:

  • Output only the index is cleared.

  • Process out-of-range input is Clip to range.

However, if Output only the index is selected and Process out-of-range input is Clip to range, the block behaves as if this check box is selected even though it is invisible.

    Tip   If 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 data and Table data parameters.

Action for out-of-range input

Specifies whether to produce a warning or error message if the input is out of range. Options include:

  • None — the default, no warning or error message

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

  • Error — halt the simulation and display an error message in the Simulation Diagnostics Viewer

Sample time

Specifies the time interval between samples. To inherit the sample time, set this parameter to -1. See How to Specify the Sample Time in the Simulink User's Guide for more information.

The Signal Attributes pane of the Prelookup block dialog box appears as follows:

Index data type

Specify how the data type of the index is designated. You can choose a built-in integer data type from the list, or you can specify an integer data type using a fixed-point representation. The data type that you specify must be capable of indexing all elements in the Breakpoint data parameter.

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

See Using the Data Type Assistant for more information.

Fraction data type

Specify how the data type of the interval fraction is designated. You can choose a built-in data type from the list, specify that the data type is inherited through an internal rule, or specify a fixed-point data type using either the [Slope Bias] or the binary-point-only scaling representation. If using the [Slope Bias] representation, the scaling must be trivial — i.e., the slope is 1 and the bias is 0. If using 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 parameter.

See Using the 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 Fixed-Point Tool and Fixed-Point Advisor in the Simulink Fixed Point documentation.

Integer rounding mode

Select the rounding mode for fixed-point operations. For more information, see Rounding in the Simulink Fixed Point User's Guide.

Block parameters such as Breakpoint data are always rounded 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.

The Breakpoint Attributes pane of the Prelookup block dialog box appears as follows:

Breakpoint minimum

Specify the minimum value that the breakpoint data can have. The default value, [], is equivalent to -Inf.

Breakpoint maximum

Specify the maximum value that the breakpoint data can have. The default value, [], is equivalent to Inf.

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

See Using the Data Type Assistant for more information.

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

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

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

    • Sharing of custom storage breakpoint data in Real-Time Workshop generated code for blocks with different input data types

Examples

See Examples for 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

Interpolation Using Prelookup

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS