Mathematics |
There are two kinds of one-dimensional interpolation in MATLAB:
Polynomial Interpolation
The function interp1
performs one-dimensional interpolation, an important operation for data analysis and curve fitting. This function uses polynomial techniques, fitting the supplied data with polynomial functions between data points and evaluating the appropriate function at the desired interpolation points. Its most general form is
y
is a vector containing the values of a function, and x
is a vector of the same length containing the points for which the values in y
are given. xi
is a vector containing the points at which to interpolate. method
is an optional string specifying an interpolation method:
method = 'nearest'
). This method sets the value of an interpolated point to the value of the nearest existing data point.
method = 'linear'
). This method fits a different linear function between each pair of existing data points, and returns the value of the relevant function at the points specified by xi
. This is the default method for the interp1
function.
method = 'spline'
). This method fits a different cubic function between each pair of existing data points, and uses the spline
function to perform cubic spline interpolation at the data points.
method = 'pchip'
or 'cubic'
). These methods are identical. They use the pchip
function to perform piecewise cubic Hermite interpolation within the vectors x
and y
. These methods preserve monotonicity and the shape of the data.
If any element of xi
is outside the interval spanned by x
, the specified interpolation method is used for extrapolation. Alternatively, yi = interp1(x,Y,xi,method,extrapval)
replaces extrapolated values with extrapval
. NaN
is often used for extrapval
.
All methods work with nonuniformly spaced data.
Speed, Memory, and Smoothness Considerations
When choosing an interpolation method, keep in mind that some require more memory or longer computation time than others. However, you may need to trade off these resources to achieve the desired smoothness in the result.
The relative performance of each method holds true even for interpolation of two-dimensional or multidimensional data. For a graphical comparison of interpolation methods, see the section Comparing Interpolation Methods.
FFT-Based Interpolation
The function interpft
performs one-dimensional interpolation using an FFT-based method. This method calculates the Fourier transform of a vector that contains the values of a periodic function. It then calculates the inverse Fourier transform using more points. Its form is
x
is a vector containing the values of a periodic function, sampled at equally spaced points. n
is the number of equally spaced points to return.
Interpolation Function Summary | Two-Dimensional Interpolation |
© 1994-2005 The MathWorks, Inc.