1-D data interpolation (table lookup) (2024)

1-D data interpolation (table lookup)

Since R2024a

collapse all in page

Syntax

vq = fixed.interp1(x,v,xq)

vq = fixed.interp1(v,xq)

vq = fixed.interp1(___,method)

vq = fixed.interp1(___,method,extrapval)

Description

example

vq = fixed.interp1(x,v,xq) returns interpolated values of a 1-D function at specific query points using linear interpolation. Vector x contains the coordinates of the sample points and v contains the corresponding function values at each sample point. The variable xq contains the coordinates of the query points.

If you have multiple sets of data that are sampled at the same point coordinates, then you can pass v as an array. Each column of array v contains a different set of 1-D sample values.

vq = fixed.interp1(v,xq) returns interpolated values and assumes a default set of sample point coordinates. The default points are the sequence of numbers from 1 to n, where n depends on the shape of v:

  • When v is a vector, the default points are 1:length(v).

  • When v is an array, the default points are 1:size(v,1).

Use this syntax when you are not concerned about the absolute distances between points.

vq = fixed.interp1(___,method) specifies an alternative interpolation method: "linear", "nearest", "previous", or "next". The default method is "linear".

vq = fixed.interp1(___,method,extrapval) specifies extrapval, a scalar value that is assigned to all queries that lie outside the domain of the sample points.

Examples

collapse all

Implement 1-D Fixed-Point Lookup Tables Using Interpolation

Open Live Script

This example shows how to implement a one-dimensional fixed-point lookup table using fixed.interp1.

Run the example multiple times to see the approximation over different query points.

Create Lookup Table for Function

Define a function f(x) to replace with a lookup table approximation.

clearvarsf = @(x) exp(x);

Define breakpoints x for the lookup table. Use the following values, which were computed to estimate exp(x) by the Lookup Table Optimizer and targeted 16-bit fixed-point types and on-curve table values.

x = [-11, -6.80029296875, -5.49609375, -4.708984375, -4.1484375, -3.70849609375, ... -3.3466796875, -3.04150390625, -2.7763671875, -2.54150390625, -2.33251953125, ... -2.142578125, -1.96875, -1.8095703125, -1.66259765625, -1.525390625, -1.3974609375, ... -1.27685546875, -1.16357421875, -1.05712890625, -0.95556640625, -0.85791015625, ... -0.76611328125, -0.677734375, -0.5927734375, -0.51171875, -0.43359375, -0.35791015625, ... -0.28515625, -0.21533203125, -0.1484375, -0.08349609375, -0.0205078125, 0];

Generate on-curve table values v corresponding to the breakpoints.

v = f(x);

Plot the table values and notice that the breakpoints x are not linearly spaced.

plot(x,v,'o-')

1-D data interpolation (table lookup) (1)

Query Lookup Table

Choose a random query point xq in the range of x.

xq = fixed.example.realUniformRandomArray(x(1),x(end),1);

Cast the inputs to 16-bit fixed-point.

x = fi(x);v = fi(v);xq = fi(xq);

The fixed.interp1 function computes vq, the lookup table approximation of f(xq). That is, vqf(xq).

vq = fixed.interp1(x,v,xq)
vq = 0.1307 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 14

Compare Lookup Approximation to Actual Function Value

Compare vq to the actual function evaluation f(xq).

vq_expected = f(double(xq))
vq_expected = 0.1303
err = double(vq) - vq_expected
err = 4.5947e-04

Plot f(x).

clf;plot(x,v)xlabel('x')ylabel('v')hold on

Plot vq, the lookup table approximation of f(xq), using a red stem plot.

stem(xq,vq,'Filled','red')legend('f(x)','vq = Fixed-point lookup-table approximation of f(xq)','location','best')

Input Arguments

collapse all

xSample points
vector

Sample points, specified as a row or column vector of real numbers. The values in x must be strictly monotonically increasing. The length of x must conform to one of the following requirements:

  • If v is a vector, then length(x) must equal length(v).

  • If v is an array, then length(x) must equal size(v,1).

The inputs x, v, and xq must be the same data type: fi, half, single, or double. When using fi data, you can use the shortened function name interp1.

Example: fi(1:10,0,8,0)

Example: half(1:10)

Data Types: fi | single | double

vSample values
vector | matrix | array

Sample values, specified as a vector, matrix, or array of real or complex numbers. If v is a matrix or an array, then each column contains a separate set of 1-D values.

If v contains complex numbers, then fixed.interp1 interpolates the real and imaginary parts separately.

The inputs x, v, and xq must be the same data type: fi, half, single, or double. When using fi data, you can use the shortened function name interp1.

Example: fi(rand(10,1),0,12,8)

Example: half(rand(10,1))

Data Types: fi | single | double
Complex Number Support: Yes

xqQuery points
scalar | vector | matrix | array

Query points, specified as a scalar, vector, matrix, or array of real numbers.

The inputs x, v, and xq must be the same data type: fi, half, single, or double. When using fi data, you can use the shortened function name interp1.

Example: fi(5,0,12,8)

Example: half(5)

Example: half(1:0.05:10)

Example: half((1:0.05:10)')

Example: half([0 1 2 7.5 10])

Data Types: fi | single | double

methodInterpolation method
"linear" (default) | "nearest" | "next" | "previous"

Interpolation method, specified as one of the options in this table.

Method

Description

Continuity

Comments

"linear"

Linear interpolation. The interpolated value at a query point is based on linear interpolation of the values at neighboring grid points in each respective dimension. This method is the default interpolation method.

C0

  • Requires at least 2 points

  • Requires more memory and computation time than nearest neighbor

"nearest"

Nearest neighbor interpolation. The interpolated value at a query point is the value at the nearest sample grid point.

Discontinuous

  • Requires at least 2 points

  • Modest memory requirements

  • Fastest computation time

"next"

Next neighbor interpolation. The interpolated value at a query point is the value at the next sample grid point.

Discontinuous

  • Requires at least 2 points

  • Same memory requirements and computation time as "nearest"

"previous"

Previous neighbor interpolation. The interpolated value at a query point is the value at the previous sample grid point.

Discontinuous

  • Requires at least 2 points

  • Same memory requirements and computation time as "nearest"

extrapvalFunction value outside the domain of x
scalar

Function value outside the domain of x, specified as a real or complex scalar. fixed.interp1 returns this constant value for all points outside the domain of x. If the scalar value is nonzero and outside the range of the sample values v, then this value is set to the minimum or maximum value of v, whichever is closer.

The data type of extrapval must be the same as x, v, and xq.

The default behavior with fi input data is to return 0 for query points outside the domain. The default behavior with half, single, or double input data is to return NaN for query points outside the domain.

Example: fi(5,0,12,8)

Example: half(5)

Data Types: fi | single | double

Note

The default behavior of the interp1 function is to return NaN when a query point is outside the domain. The fixed.interp1 function with fi input data is not consistent with this behavior because fi casts NaN to 0.

Output Arguments

collapse all

vq — Interpolated values
scalar | vector | matrix | array

Interpolated values, returned as a scalar, vector, matrix, or array. The size of vq depends on the shape of v and xq. The data type of vq is the same as that of the sample values v.

Shape of vShape of xqSize of VqExample
VectorVectorsize(xq)If size(v) = [1 100]
and size(xq) = [1 500],
then size(vq) = [1 500].
VectorMatrix
or N-D Array
size(xq)If size(v) = [1 100]
and size(xq) = [50 30],
then size(vq) = [50 30].
Matrix
or N-D Array
Vector[length(xq) size(v,2),...,size(v,n)]If size(v) = [100 3]
and size(xq) = [1 500],
then size(vq) = [500 3].
Matrix
or N-D Array
Matrix
or N-D Array
[size(xq,1),...,size(xq,n),... size(v,2),...,size(v,m)]If size(v) = [4 5 6]
and size(xq) = [2 3 7],
then size(vq) = [2 3 7 5 6].

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.

Version History

Introduced in R2024a

See Also

fixed.interp2 | fixed.interp3 | fixed.interpn | interp1

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

1-D data interpolation (table lookup) (3)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

1-D data interpolation (table lookup) (2024)

FAQs

What is a 1D lookup table? ›

1D Lookup table generates an output signal by interpolating based on a given data set and input value. The Input values x property must be a strictly increasing or decreasing array. It supports equidistant and non-equidistant distributions of table indexes (Input values x):

How to calculate lookup table in MATLAB? ›

Use the tablelookup function in the equations section to compute an output value by interpolating the query input value against a set of data points. This functionality is similar to that of the Simulink® and Simscape™ Lookup Table blocks.

What is the formula for 1D linear interpolation? ›

Performs 1D linear interpolation of 'xi' points using 'x' and 'y', resulting in 'yi', following the formula yi = y1 + (y2-y1)/(x2-x1)*(xi-x1).

What is an interpolation table? ›

Interpolation is the process of deducing the value between two points in a set of data. When you're looking at a line graph or function table, you might estimate values that fall between two points or entries. The interpolation formula allows you to find a more precise estimate of an added value.

How does a lookup table work? ›

A lookup table is an array of data that maps input values to output values, thereby approximating a mathematical function. Given a set of input values, a lookup operation retrieves the corresponding output values from the table.

What is the difference between lookup table and dimension table? ›

Dimensions define a hierarchy for the information retrieved by the lookup table, so that it can be organized and presented in a meaningful way. Lookup tables are retrieved from the Case Analyzer store. The preconfigured Case Monitor objects provide ready-made lookup tables for dimensions.

What is lookup data table? ›

Lookup tables — similar to cross-reference tables — allow you to easily look up frequently used data in a recipe. Lookup tables are structured with rows and columns. You can look up entries in a lookup table by matching data in one or more columns.

How does interpolation work in Matlab? ›

The interpolated value at a query point is based on linear interpolation of the values at neighboring grid points in each respective dimension. This is the default interpolation method. The interpolated value at a query point is the value at the nearest sample grid point. Requires two grid points in each dimension.

What is interpolate 1D array? ›

Interpolate 1D Array. Calculates a decimal y-value from an array of numbers or points at a specified fractional index or x-value using linear interpolation.

What is one dimensional interpolation? ›

One dimensional interpolation allows to compute new values from a set of known values in R. Values are computed based on a (hidden) function and the given data.

How to calculate interpolation? ›

The interpolation equation is as follows: y − y 1 = y 2 − y 1 x 2 − x 1 ( x − x 1 ) , where ( x 1 , y 1 ) and ( x 2 , y 2 ) are two known data points and ("x," "y") represents the data point to be estimated.

How to do data interpolation? ›

It works by fitting a straight line between two given data points, represented by coordinates (x1,y1) and (x2,y2). The formula used for linear interpolation is y-y1=y2-y1x2-x1 . (x-x1), where y represents the estimated value at a point x between x1 and x2.

What is the best interpolation method? ›

In terms of the ability to fit your data and produce a smooth surface, the Multiquadric method is considered by many to be the best.

How to solve linear interpolation? ›

Formula of Linear Interpolation
  1. x 1. and.
  2. y 1. are the first coordinates.
  3. x 2. and.
  4. y 2. are the second coordinates. x is the point to perform the interpolation. y is the interpolated value. Solved Examples. ...
  5. y 1. + ( x − x 1 ) ( y 2 − y 1 ) x 2 − x 1. y = 4 + ( 4 − 2 ) ( 7 − 4 ) 6 − 2.

What is the use of lookup table in Excel? ›

In computer science, a lookup table is an array of data, which is generally used to map input values to output values. In terms of this tutorial, an Excel lookup table is nothing else but a range of cells where you search for a lookup value. Main table (master table) - a table into which you pull matching values.

What is the difference between lookup table and reference table? ›

Both types of tables are used in the mapping and translation process. The primary difference is that a lookup table has only one key field and a cross-reference table has two. A lookup table is used when you want to supplement data before it is sent to your partner.

What is SQL lookup table? ›

MySQL lookup tables are specialized tables used primarily for mapping key values to corresponding data. They provide an efficient way to store and retrieve static or rarely changed data, often used for things like status codes, configuration settings, or reference data.

What is the difference between lookup table and truth table? ›

A truth table typically would be a LUT with a 1b output with the potential to be more efficiently implemented by gates. A table lookup may mean any type of RAM access where data is stored in a table or data structure of any sort. For example, a router may have a "routing table" that maps IP addresses to port numbers.

References

Top Articles
Latest Posts
Article information

Author: Ms. Lucile Johns

Last Updated:

Views: 5801

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Ms. Lucile Johns

Birthday: 1999-11-16

Address: Suite 237 56046 Walsh Coves, West Enid, VT 46557

Phone: +59115435987187

Job: Education Supervisor

Hobby: Genealogy, Stone skipping, Skydiving, Nordic skating, Couponing, Coloring, Gardening

Introduction: My name is Ms. Lucile Johns, I am a successful, friendly, friendly, homely, adventurous, handsome, delightful person who loves writing and wants to share my knowledge and understanding with you.