๐Ÿ“‹

Lookup Table

Math
Run the live example Free ยท no sign-up ยท runs in your browser

The LookupTable block implements a one-dimensional lookup table with configurable linear or cubic spline interpolation and extrapolation. It maps an arbitrary scalar input uu to an interpolated output value yy using a set of strictly monotonically increasing input breakpoints (XX) and corresponding output values (YY).

In the Property Editor, both series (XX and YY) are edited side-by-side in an Excel-style spreadsheet (Spreadsheet (X / Y)) paired with a live LUT curve preview (y = f(x)) that immediately visualizes every point and interpolation mode (linear or spline). Calibration tables can also be saved and loaded directly via CSV Import / Export (lut_data.csv), supporting standard comma (,), European semicolon (;), and tab (\t) delimiters.

Mathematical Model

Given NN strictly monotonically increasing input breakpoints x0<x1<โ‹ฏ<xNโˆ’1x_0 < x_1 < \dots < x_{N-1} and corresponding output table values y0,y1,โ€ฆ,yNโˆ’1y_0, y_1, \dots, y_{N-1}:

For an input uu falling within the breakpoint interval xkโ‰คuโ‰คxk+1x_k \le u \le x_{k+1} (0โ‰คk<Nโˆ’10 \le k < N-1):

y(u)=yk+yk+1โˆ’ykxk+1โˆ’xk(uโˆ’xk)y(u) = y_k + \frac{y_{k+1} - y_k}{x_{k+1} - x_k} (u - x_k)

When interpolation is set to spline, the block constructs a natural cubic spline through all data points, ensuring continuous first and second derivatives (C2C^2 continuity) across knot boundaries:

y(u)=ak(uโˆ’xk)3+bk(uโˆ’xk)2+ck(uโˆ’xk)+dky(u) = a_k (u - x_k)^3 + b_k (u - x_k)^2 + c_k (u - x_k) + d_k

When the input uu falls outside the breakpoint range (u<x0u < x_0 or u>xNโˆ’1u > x_{N-1}), the output is governed by the extrapolation mode:

y(u)={y0,u<x0(extrapolation=clip)yNโˆ’1,u>xNโˆ’1(extrapolation=clip)y0+y1โˆ’y0x1โˆ’x0(uโˆ’x0),u<x0(extrapolation=linear)yNโˆ’1+yNโˆ’1โˆ’yNโˆ’2xNโˆ’1โˆ’xNโˆ’2(uโˆ’xNโˆ’1),u>xNโˆ’1(extrapolation=linear)y(u) = \begin{cases} y_0, & u < x_0 \quad (\text{extrapolation} = \text{clip}) \\ y_{N-1}, & u > x_{N-1} \quad (\text{extrapolation} = \text{clip}) \\ y_0 + \frac{y_1 - y_0}{x_1 - x_0}(u - x_0), & u < x_0 \quad (\text{extrapolation} = \text{linear}) \\ y_{N-1} + \frac{y_{N-1} - y_{N-2}}{x_{N-1} - x_{N-2}}(u - x_{N-1}), & u > x_{N-1} \quad (\text{extrapolation} = \text{linear}) \end{cases}

Inputs & Outputs

Direction ID Label Type Status
→ In in In number Required
← Out out Out number Output

Parameters

Parameters Label Type Default Description
breakpoints Lookup Table (X / Y) table 0 1 2 3
tableData Table Data text 0 1 4 9
interpolation Interpolation select linear
extrapolation Extrapolation select clip

Usage Examples

Example 1: NTC Thermistor Temperature-to-Resistance Linearization

In temperature monitoring circuits, negative temperature coefficient (NTC) thermistors exhibit highly nonlinear exponential resistance curves. Entering ADC voltage rows X=[0.5,1.2,2.1,3.3,4.2]X = [0.5, 1.2, 2.1, 3.3, 4.2] and calibrated temperatures Y=[โˆ’10,15,45,80,110]Y = [-10, 15, 45, 80, 110] into the LookupTable spreadsheet (or importing them from a calibration CSV) with linear or spline interpolation yields an accurate, linearized temperature signal in degrees Celsius (โˆ˜C^\circ\text{C}) across the operational range.

Example 2: Aerodynamic Wing Lift Coefficient Curve with Stall Clamping

Simulating aerodynamic lift coefficient CLC_L as a function of angle of attack ฮฑ\alpha in degrees. Breakpoints -15 -10 0 10 15 20 map to table data -0.8 -0.6 0.1 1.1 1.4 0.9. Setting extrapolation = clip ensures that extreme aerodynamic angles during severe wind gusts do not extrapolate into unphysical supersonic lift forces.

Remarks & Best Practices

  • Interactive Spreadsheet & Live Preview: Double-clicking the block opens an Excel-style two-column sheet (X and Y) with row numbers, + Add Row (Point), row deletion (ร—), and a live uPlot curve preview that updates as you type.
  • CSV Save & Load (Import / Export & Excel Paste): Click Export CSV to download the current table as lut_data.csv (X,Y columns), Import CSV to load measurements from Excel/CSV files (comma, semicolon, or tab separated), or paste multi-row selections directly from Excel (Ctrl+V).
  • Monotonic Breakpoint Requirement: The values in breakpoints (XX) are automatically sorted in ascending order (xk+1>xkx_{k+1} > x_k).
  • Fast Binary Interval Search: The WASM simulation engine employs an O(logโกN)O(\log N) binary partition search to identify active intervals, ensuring high-speed lookup execution even with large empirical datasets.
  • Continuous Derivative Preservation: Selecting spline interpolation prevents sharp slope discontinuities at knots, ensuring smooth integration when interacting with variable-step continuous ODE solvers such as RK45 or TR-BDF2.

Frequently Asked Questions (FAQ)

Q: How does lookup table interpolation handle out-of-bounds input values?

BlockWerk clamps inputs to the table boundary limits [xminโก,xmaxโก][x_{\min}, x_{\max}] (flat extrapolation) by default. Flat clamping protects physical models (e.g. non-negative friction, engine torque maps, or fluid density) against runaway divergence, whereas unrestricted linear extrapolation can produce non-physical negative values that crash downstream ODE solvers.

Related Components

  • LookupTable2D: Two-dimensional lookup table with interactive 2D matrix spreadsheet and bilinear/bicubic surface interpolation z=f(x,y)z = f(x, y).
  • MathFunction: Standard mathematical functions (expโก\exp, lnโก\ln, pow\text{pow}, round\text{round}).
  • Saturation: Clamps dynamic signals between fixed lower and upper bounds.