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')

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

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

How do you interpolate data tables? ›

Interpolate data within a data table
  1. In the toolbar, click Interpolate. The Interpolate dialog box appears.
  2. In the Range Item list, select the item that you want to interpolate.
  3. Type the desired value in the Value to be added field. Note: ...
  4. Click Interpolate. ...
  5. If necessary, repeat steps 1–4 to receive the desired result.

How to solve interpolation method? ›

How to interpolate
  1. Organize your data. First, put the data you've collected into a chart that shows your independent and dependent variables. ...
  2. Consider creating a graph. ...
  3. Select your two points. ...
  4. Enter values into the interpolation equation. ...
  5. Solve for the missing variable.
Oct 16, 2023

What is the best way to interpolate data? ›

Linear interpolation is the most straightforward and commonly used interpolation method. It comes naturally when we have two points, we connect them with a straight line to fill out the missing information in between. By doing so, we made our assumption that the points on the line represent the unobserved values.

What is the best data interpolation method? ›

Radial Basis Function interpolation is a diverse group of data interpolation methods. 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 do you interpolate between two data sets? ›

How to interpolate
  1. Identify your data. Use a table to list your data. ...
  2. Create a line of best fit. After using the values to plot a graph, you can draw a line of best fit. ...
  3. Determine your value for interpolation. ...
  4. Use the linear interpolation equation. ...
  5. Solve the equation.
Sep 30, 2022

How to interpolate data from a table in Excel? ›

Here's how to use the FORECAST function to interpolate in Excel:
  1. Chart your data points. The first step is to chart your data points. ...
  2. Designate your cells for the input and output formula. ...
  3. Input your formula into the interpolated value cell. ...
  4. Assign the variables in the function to your cells. ...
  5. Test the formula.

What is an example of interpolation of data? ›

Interpolation definition says that interpolation is to estimate the value of a point between two given points in a data set. For example, if a child's height was measured at age 5 and age 6, interpolation could be used to estimate the child's height at age 5.5.

What is the simplest method of interpolation? ›

One of the simplest methods, linear interpolation, requires knowledge of two points and the constant rate of change between them. With this information, you may interpolate values anywhere between those two points.

What is the fastest interpolation method? ›

The Nearest Point interpolation method is the fastest of all the interpolation methods when used with point data (fig. 19). If used with line or polygon data it can be slower than the Nearest interpolation especially if many of the object vertices lie outside the grid.

Why do we interpolate data? ›

Interpolation is a mathematical technique to estimate the values of unknown data points that fall in between existing, known data points. This process helps fill in the blanks. Technical traders use interpolation to understand how prices have behaved in the past, even when they do not have full information.

Is interpolation legal? ›

But be careful to remember that musical works and sound recordings are different works. If you want to make a copy, interpolation, or performance of a musical work in the public domain in the United States—for example, Grieg's “In the Hall of the Mountain King”—you can.

How do you know when to use interpolation? ›

It is used when there is an exact relationship between the values, but no data points are available. Nearest Neighbor Interpolation: This method uses the closest known value to predict the value between two known values. It is useful when there are limited data points available.

What is the easiest method for solving interpolation? ›

Linear interpolation is the simplest method of getting values at positions in between the data points. The points are simply joined by straight line segments. Each segment (bounded by two data points) can be interpolated independently.

What is the average interpolation method? ›

The Average Interpolated algorithm calculates an average value based on: The interpolated value for the start of the resample interval. The good quality raw historic values in the resample interval.

How many methods are there for interpolation of data? ›

It is widely used to analyze photos and videos, estimate values between known data points, and decrease the amount of data required to describe curves and surfaces. There are several methods of interpolation, including linear interpolation, polynomial interpolation, and spline interpolation.

What is interpolation of a data set? ›

Interpolation is the process of using known data values to estimate unknown data values. Various interpolation techniques are often used in the atmospheric sciences. One of the simplest methods, linear interpolation, requires knowledge of two points and the constant rate of change between them.

What are the methods available for interpolation of data? ›

They are: Linear Interpolation Method – This method applies a distinct linear polynomial between each pair of data points for curves, or within the sets of three points for surfaces. Nearest Neighbour Method – This method inserts the value of an interpolated point to the value of the most adjacent data point.

What is interpolation of tabulated values? ›

The finding of value between tabulated entries is called interpolation. The ex- tending of tabulated values to find values beyond the limits of the table is called extrapolation.

Can you interpolate in SQL? ›

A SQL string containing variables to interpolate. Variables must start with a question mark and can be any valid R identifier, i.e. it must start with a letter or . , and be followed by a letter, digit, . or _ . Values (for ... ) or a list (for . dots ) to interpolate into a string.

References

Top Articles
Latest Posts
Article information

Author: Aracelis Kilback

Last Updated:

Views: 6702

Rating: 4.3 / 5 (64 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Aracelis Kilback

Birthday: 1994-11-22

Address: Apt. 895 30151 Green Plain, Lake Mariela, RI 98141

Phone: +5992291857476

Job: Legal Officer

Hobby: LARPing, role-playing games, Slacklining, Reading, Inline skating, Brazilian jiu-jitsu, Dance

Introduction: My name is Aracelis Kilback, I am a nice, gentle, agreeable, joyous, attractive, combative, gifted person who loves writing and wants to share my knowledge and understanding with you.