Last chance! 50% off unlimited learning
Sale ends in
Plots the oscillogram (waveform) of a sound on a logarithmic scale, in dB. Analogous to "Waveform (dB)" view in Audacity.
osc_dB(x, dynamicRange = 80, maxAmpl = NULL, samplingRate = NULL,
returnWave = FALSE, plot = TRUE, xlab = NULL, ylab = "dB",
bty = "n", midline = TRUE, ...)
path to a .wav file or a vector of amplitudes with specified samplingRate
dynamic range of the oscillogram, dB
the maximum theoretically possible value indicating on which scale the sound is coded: 1 if the range is -1 to +1, 2^15 for 16-bit wav files, etc
sampling rate of x
(only needed if x
is a
numeric vector, rather than a .wav file)
if TRUE, returns a log-transformed waveform as a numeric vector
if TRUE, plots the oscillogram
axis labels
box type (see `?par`)
if TRUE, draws a line at 0 dB
Other graphical parameters passed on to `plot()`
Returns the input waveform on a dB scale: a vector with range from `-dynamicRange` to `dynamicRange`.
Algorithm: centers and normalizes the sound, then takes a logarithm of the positive part and a flipped negative part.
# NOT RUN {
sound = sin(1:2000/10) *
getSmoothContour(anchors = c(1, .01, .5), len = 2000)
# Oscillogram on a linear scale
plot(sound, type = 'l')
# or, for fancy plotting options: seewave::oscillo(sound, f = 1000)
# Oscillogram on a dB scale
osc_dB(sound)
# Time in ms if samplingRate is specified
osc_dB(sound, samplingRate = 5000)
# Assuming that the waveform can range up to 50 instead of 1
osc_dB(sound, maxAmpl = 50)
# Embellish and customize the plot
o = osc_dB(sound, samplingRate = 1000, midline = FALSE,
main = 'My waveform', col = 'blue')
abline(h = 0, col = 'orange', lty = 3)
# }
Run the code above in your browser using DataLab