Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

interp1

Interpolation


Description

Interpolation methods, including linear, spline, and cubic interpolation.

Usage

interp1(x, y, xi, method = c("linear", "nearest", "pchip", "cubic", "spline"), 
        extrap = NA, ...)

Arguments

x,y

vectors giving the coordinates of the points to be interpolated. x is assumed to be strictly monotonic.

xi

points at which to interpolate.

method

one of "linear", "nearest", "pchip", "cubic", "spline".

extrap

if TRUE or 'extrap', then extrapolate values beyond the endpoints. If extrap is a number, replace values beyond the endpoints with that number (defaults to NA).

...

for method='spline', additional arguments passed to splinefun.

Details

The following methods of interpolation are available:

'nearest': return nearest neighbour

'linear': linear interpolation from nearest neighbours

'pchip': piecewise cubic hermite interpolating polynomial

'cubic': cubic interpolation from four nearest neighbours

'spline': cubic spline interpolation–smooth first and second derivatives throughout the curve

Value

The interpolated signal, an array of length(xi).

Author(s)

Original Octave version by Paul Kienzle pkienzle@user.sf.net. Conversion to R by Tom Short.

References

Octave Forge http://octave.sf.net

See Also

Examples

xf <- seq(0, 11, length=500)
yf <- sin(2*pi*xf/5)
#xp <- c(0:1,3:10)
#yp <- sin(2*pi*xp/5)
xp <- c(0:10)
yp <- sin(2*pi*xp/5)
extrap <- TRUE
lin  <- interp1(xp, yp, xf, 'linear', extrap = extrap)
spl  <- interp1(xp, yp, xf, 'spline', extrap = extrap)
pch  <- interp1(xp, yp, xf, 'pchip', extrap = extrap)
cub  <- interp1(xp, yp, xf, 'cubic', extrap = extrap)
near <- interp1(xp, yp, xf, 'nearest', extrap = extrap)
plot(xp, yp, xlim = c(0, 11))
lines(xf, lin, col = "red")
lines(xf, spl, col = "green")
lines(xf, pch, col = "orange")
lines(xf, cub, col = "blue")
lines(xf, near, col = "purple")

signal

Signal Processing

v0.7-6
GPL-2
Authors
Uwe Ligges [aut, cre] (new maintainer), Tom Short [aut] (port to R), Paul Kienzle [aut] (majority of the original sources), Sarah Schnackenberg [ctb] (various test cases and bug fixes), David Billinghurst [ctb], Hans-Werner Borchers [ctb], Andre Carezia [ctb], Pascal Dupuis [ctb], John W. Eaton [ctb], E. Farhi [ctb], Kai Habel [ctb], Kurt Hornik [ctb], Sebastian Krey [ctb], Bill Lash [ctb], Friedrich Leisch [ctb], Olaf Mersmann [ctb], Paulo Neis [ctb], Jaakko Ruohio [ctb], Julius O. Smith III [ctb], Doug Stewart [ctb], Andreas Weingessel [ctb]
Initial release
2015-07-29

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.