πŸ“Š

2-D Lookup Table

Math
Run the live example Free Β· no sign-up Β· runs in your browser

The LookupTable2D block maps two independent input signals (xx and yy) to an output value zz using bilinear or bicubic spline interpolation over a rectangular two-dimensional grid. It models complex bivariate nonlinear functions where physical behavior depends simultaneously on two operational variablesβ€”such as electric motor efficiency maps (Ο‰,Ο„\omega, \tau), internal combustion engine fuel maps (RPM,MAP\text{RPM}, \text{MAP}), compressor pressure ratio characteristics, and aerodynamic drag polars.

In the Property Editor, all three series (XX column headers, YY row headers, and Z=f(X,Y)Z = f(X, Y) matrix cells) are edited together in a 2D Excel-style matrix spreadsheet (2D Matrix (Y \ X β†’ Z)) paired with a live multi-slice LUT plot preview (z = f(x, y)). You can add or remove columns (+X) and rows (+Y), and save or load the entire 2D surface directly via CSV Import / Export (lut2d_data.csv), supporting comma (,), semicolon (;), and tab (\t) delimiters.

Mathematical Model

Given NxN_x strictly increasing grid coordinates x0<x1<β‹―<xNxβˆ’1x_0 < x_1 < \dots < x_{N_x-1} and NyN_y strictly increasing coordinates y0<y1<β‹―<yNyβˆ’1y_0 < y_1 < \dots < y_{N_y-1}, the grid values zi,j=f(xi,yj)z_{i,j} = f(x_i, y_j) are defined across the rectangular mesh in row-major order.

For input coordinates (x,y)(x, y) falling within cell [xi,xi+1]Γ—[yj,yj+1][x_i, x_{i+1}] \times [y_j, y_{j+1}], normalized local coordinates uu and vv are computed as:

u=xβˆ’xixi+1βˆ’xi,v=yβˆ’yjyj+1βˆ’yj,u,v∈[0,1]u = \frac{x - x_i}{x_{i+1} - x_i}, \quad v = \frac{y - y_j}{y_{j+1} - y_j}, \quad u, v \in [0, 1]

Bilinear interpolation calculates the interpolated surface value z(x,y)z(x, y):

z(x,y)=(1βˆ’u)(1βˆ’v)zi,j+u(1βˆ’v)zi+1,j+(1βˆ’u)vzi,j+1+uvzi+1,j+1z(x, y) = (1 - u)(1 - v) z_{i,j} + u(1 - v) z_{i+1,j} + (1 - u)v z_{i,j+1} + u v z_{i+1,j+1}

When extrapolation is set to clip, input coordinates outside the grid bounds are clamped to the boundary ranges [x0,xNxβˆ’1][x_0, x_{N_x-1}] and [y0,yNyβˆ’1][y_0, y_{N_y-1}] prior to surface evaluation:

xeval=min⁑(max⁑(x,x0),xNxβˆ’1),yeval=min⁑(max⁑(y,y0),yNyβˆ’1)x_{\text{eval}} = \min(\max(x, x_0), x_{N_x-1}), \quad y_{\text{eval}} = \min(\max(y, y_0), y_{N_y-1})

When set to linear, the block projects the bilinear tangent plane of the nearest outer bounding cell.

Inputs & Outputs

Direction ID Label Type Status
→ In in1 x number Required
→ In in2 y number Required
← Out out Out number Output

Parameters

Parameters Label Type Default Description
xBreakpoints 2D Lookup Table (X / Y / Z) table-2d 0 1
yBreakpoints Y Breakpoints text 0 1
tableData Table Data (row-major) text 0 1 1 2
interpolation Interpolation select linear
extrapolation Extrapolation select linear

Usage Examples

Example 1: Permanent Magnet Synchronous Motor (PMSM) Efficiency Map

In an electric powertrain model, motor efficiency varies nonlinearly with both shaft speed and output torque. Entering XX column headers 500 1500 3000 6000 (RPM), YY row headers 10 50 100 150 (Nm), and the 4Γ—44 \times 4 efficiency cells in the 2D matrix editor (or importing from a test-bench CSV) allows the block to evaluate continuous drive efficiency for any operating point during regenerative braking and acceleration cycles.

Example 2: Engine Fuel Injection Mass Calibration Map

Modeling mass fuel injection per cylinder stroke as a function of intake manifold absolute pressure (MAP, xx-axis in kPa: 20 40 60 80 100) and engine speed (yy-axis in RPM: 1000 2000 3000 4000 5000). Using extrapolation = clip ensures that unexpected intake pressure spikes during turbocharger lag do not extrapolate into uncalibrated, dangerously lean or rich fueling states.

Remarks & Best Practices

  • 2D Matrix Spreadsheet & Live Preview: Double-clicking the block opens a corner-indexed Y \ X spreadsheet where the top header row defines XX breakpoints, the left header column defines YY breakpoints, and interior cells define Z(X,Y)Z(X, Y), alongside a live uPlot chart showing one colored curve per YY row.
  • CSV Save & Load (Import / Export & Excel Paste): Click Export CSV to save the 2D grid as lut2d_data.csv (with blank top-left corner cell, XX breakpoints in row 1, and each subsequent row starting with its YY breakpoint followed by ZZ values), Import CSV to load a 2D table from Excel/CSV, or paste a 2D grid selection directly from Excel (Ctrl+V).
  • Row-Major Memory Order: Under the hood, tableData is stored in row-major order: index sequence increments through all xx column values before advancing to the subsequent yy row.
  • Strict Coordinate Monotonicity: Both xBreakpoints and yBreakpoints must be strictly monotonically increasing.
  • Independent Binary Coordinate Search: The simulation engine performs independent O(log⁑Nx+log⁑Ny)O(\log N_x + \log N_y) binary bisections along each axis, ensuring rapid real-time performance even with dense surface meshes.

Frequently Asked Questions (FAQ)

Q: How is bilinear interpolation computed across a 2D grid in real-time simulation?

For input coordinates (x,y)(x, y) falling in cell [xi,xi+1]Γ—[yj,yj+1][x_i, x_{i+1}] \times [y_j, y_{j+1}], normalized fractions u=xβˆ’xixi+1βˆ’xiu = \frac{x - x_i}{x_{i+1} - x_i} and v=yβˆ’yjyj+1βˆ’yjv = \frac{y - y_j}{y_{j+1} - y_j} are calculated. The output is z=(1βˆ’u)(1βˆ’v)zi,j+u(1βˆ’v)zi+1,j+(1βˆ’u)vzi,j+1+uvzi+1,j+1z = (1-u)(1-v) z_{i,j} + u(1-v) z_{i+1,j} + (1-u)v z_{i,j+1} + uv z_{i+1,j+1}. Monotonic breakpoint ordering enables O(log⁑N)O(\log N) binary search, guaranteeing constant-time evaluation in 60fps WebAssembly simulation.

Related Components

  • LookupTable: One-dimensional lookup table with interactive 2-column spreadsheet and linear/cubic spline interpolation.
  • Product: Multiplies two independent dynamic signals.
  • MathFunction: Standard mathematical functions (exp⁑\exp, ln⁑\ln, pow\text{pow}).