soundgen (version 1.5.0)

getRMS: RMS amplitude per frame

Description

Calculates root mean square (RMS) amplitude in overlapping frames, providing an envelope of RMS amplitude as a measure of sound intensity. Longer windows provide smoother, more robust estimates; shorter windows and more overlap improve temporal resolution, but they also increase processing time and make the contour less smooth.

Usage

getRMS(x, samplingRate = NULL, windowLength = 50, step = NULL,
  overlap = 75, killDC = FALSE, scale = NULL, normalize = TRUE,
  windowDC = 200, plot = TRUE, xlab = "Time, ms", ylab = "",
  type = "b", col = "blue", lwd = 2, ...)

Arguments

x

path to a .wav or .mp3 file or a vector of amplitudes with specified samplingRate

samplingRate

sampling rate of x (only needed if x is a numeric vector, rather than an audio file)

windowLength

length of FFT window, ms

step

you can override overlap by specifying FFT step, ms

overlap

overlap between successive FFT frames, %

killDC

if TRUE, removed DC offset (see also flatEnv)

scale

maximum possible amplitude of input used for normalization (not needed for audio files)

normalize

if TRUE, RMS amplitude is normalized to [0, 1]

windowDC

the window for calculating DC offset, ms

plot

should a spectrogram be plotted? TRUE / FALSE

xlab, ylab

general graphical parameters

type, col, lwd

graphical parameters pertaining to the RMS envelope

...

other graphical parameters

Value

Returns a numeric vector of RMS amplitudes per frame on the scale of input. Names give time stamps for the center of each frame, in ms.

Details

Note that you can also get similar estimates per frame from analyze on a normalized scale of 0 to 1, but getRMS is much faster, operates on the original scale, and plots the amplitude contour. If you need RMS for the entire sound instead of per frame, you can simply calculate it as sqrt(mean(x^2)), where x is your waveform. Having RMS estimates per frame gives more flexibility: RMS per sound can be calculated as the mean / median / max of RMS values per frame.

Examples

Run this code
# NOT RUN {
s = soundgen() + .1  # with added DC offset
plot(s, type = 'l')
r = getRMS(s, samplingRate = 16000,
  windowLength = 40, overlap = 50, killDC = TRUE,
  col = 'green', lty = 2, main = 'RMS envelope')
# short window = jagged envelope
r = getRMS(s, samplingRate = 16000,
  windowLength = 5, overlap = 0, killDC = TRUE,
  col = 'green', lty = 2, main = 'RMS envelope')
# }
# NOT RUN {
r = getRMS('~/Downloads/temp/032_ut_anger_30-m-roar-curse.wav')
# }

Run the code above in your browser using DataCamp Workspace