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

resample

Change the sampling rate of a signal


Description

Resample using bandlimited interpolation.

Usage

resample(x, p, q = 1, d = 5)

Arguments

x

signal to be resampled.

p, q

p/q specifies the factor to resample by.

d

distance.

Details

Note that p and q do not need to be integers since this routine does not use a polyphase rate change algorithm, but instead uses bandlimited interpolation, wherein the continuous time signal is estimated by summing the sinc functions of the nearest neighbouring points up to distance d.

Note that resample computes all samples up to but not including time n+1. If you are increasing the sample rate, this means that it will generate samples beyond the end of the time range of the original signal. That is why xf must go all the way to 10.95 in the example below.

Nowadays, the signal version in Matlab and Octave contain more modern code for resample that has not been ported to the signal R package (yet).

Value

The resampled signal, an array of length ceiling(length(x) * p / q).

Author(s)

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

References

J. O. Smith and P. Gossett (1984). A flexible sampling-rate conversion method. In ICASSP-84, Volume II, pp. 19.4.1-19.4.2. New York: IEEE Press.

Octave Forge http://octave.sf.net

See Also

Examples

xf <- seq(0, 10.95, by=0.05)
yf <- sin(2*pi*xf/5)
xp <- 0:10
yp <- sin(2*pi*xp/5)
r <- resample(yp, xp[2], xf[2])
title("confirm that the resampled function matches the original")
plot(xf, yf, type = "l", col = "blue")
lines(xf, r[1:length(xf)], col = "red")
points(xp,yp, pch = 19, col = "blue")
legend("bottomleft", c("Original", "Resample", "Data"),
       col = c("blue", "red", "blue"),
       pch = c(NA, NA, 19),
       lty = c(1, 1, NA), bty = "n")

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.