Next: , Up: Interpolation   [Contents][Index]

29.1 One-dimensional Interpolation


yi = interp1 (x, y, xi)
yi = interp1 (y, xi)
yi = interp1 (…, method)
yi = interp1 (…, extrap)
yi = interp1 (…, "left")
yi = interp1 (…, "right")
pp = interp1 (…, "pp")

One-dimensional interpolation.

Interpolate input data to determine the value of yi at the points xi. If not specified, x is taken to be the indices of y (1:length (y)). If y is a matrix or an N-dimensional array, the interpolation is performed on each column of y.

The interpolation method is one of:


Return the nearest neighbor.


Return the previous neighbor.


Return the next neighbor.

"linear" (default)

Linear interpolation from nearest neighbors.


Piecewise cubic Hermite interpolating polynomial—shape-preserving interpolation with smooth first derivative.


Cubic interpolation (same as "pchip").


Cubic spline interpolation—smooth first and second derivatives throughout the curve.

Adding ’*’ to the start of any method above forces interp1 to assume that x is uniformly spaced, and only x(1) and x(2) are referenced. This is usually faster, and is never slower. The default method is "linear".

If extrap is the string "extrap", then extrapolate values beyond the endpoints using the current method. If extrap is a number, then replace values beyond the endpoints with that number. When unspecified, extrap defaults to NA.

If the string argument "pp" is specified, then xi should not be supplied and interp1 returns a piecewise polynomial object. This object can later be used with ppval to evaluate the interpolation. There is an equivalence, such that ppval (interp1 (x, y, method, "pp"), xi) == interp1 (x, y, xi, method, "extrap").


An example of the use of interp1 is

xf = [0:0.05:10];
xp = [0:10];
lin = interp1 (xp, yp, xf);
pch = interp1 (xp, yp, xf, "pchip");
plot (xf,yf,"r", xf,near,"g", xf,lin,"b", xf,pch,"c", xf,spl,"m",
legend ("original", "nearest", "linear", "pchip", "spline");

See also: pchip, spline, interpft, interp2, interp3, interpn.


This can be demonstrated by the code

t = -2:2;
dt = 1;
ti =-2:0.025:2;
dti = 0.025;
y = sign (t);
figure (1);
figure (2);
legend ("spline", "pchip");







interpft (x, n)
interpft (x, n, dim)

Fourier interpolation.


If dim is specified, then interpolate along the dimension dim.


See also: interp1.

There are two significant limitations on Fourier interpolation. First, the function signal is assumed to be periodic, and so non-periodic signals will be poorly represented at the edges. Second, both the signal and its interpolation are required to be sampled at equispaced points. An example of the use of interpft is

n = length (t); k = 100;





pp = spline (x, y)
yi = spline (x, y, xi)

Return the cubic spline interpolant of points x and y.



The variable x must be a vector of length n.



See also: pchip, ppval, mkpp, unmkpp.

Next: , Up: Interpolation   [Contents][Index]