| getEnv | R Documentation |
Calculates a smoothed envelope of a waveform based on peaks, running average,
root mean square (intensity), or envelope of the analytic signal with Hilbert
transform. Algorithm: calculates one envelope value per frame of length
wl, then upsamples to the original sampling rate with
spline.
getEnv(
x,
method = c("rms", "hil", "peak", "mean"),
wl = 200,
overlap = 0,
step = NULL,
upsample = TRUE
)
x |
numeric vector at least |
method |
"peak" for peak amplitude per window, "rms" for root mean square amplitude, "mean" for mean (for DC offset removal), "hil" for Hilbert envelope |
wl |
the length of smoothing window (samples) |
overlap |
overlap between successive windows, 0 to 100% |
step |
step between successive windows (samples); overrides overlap |
upsample |
if TRUE, upsamples the envelope to the length of the original sound; if FALSE, returns one sample per window |
The envelope as a numeric vector on the original scale. If
upsample = TRUE, it has the same length as the input, regardless of
the amount of smoothing.
a = rnorm(500) * seq(1, 0, length.out = 500)
wl = 50
scale = max(abs(a))
plot(a, type = 'l', ylim = c(-scale, scale))
lines(getEnv(a, 'rms', wl), col = 'red')
lines(getEnv(a, 'peak', wl), col = 'green')
lines(getEnv(a, 'hil', wl), col = 'blue')
lines(getEnv(a, 'mean', wl), lty = 3, lwd = 3)
# No upsampling (short output)
getEnv(1:16, 'mean', wl = 5, upsample = FALSE)
env_short = getEnv(a, 'rms', wl = wl, overlap = 50, upsample = FALSE)
plot(a, type = 'l')
lines(seq(1, length(a), length.out = length(env_short)), env_short, col = 'red')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.