View source: R/modulationSpectrum_utilities.R
| getRoughness | R Documentation |
Calculates psychoacoustic roughness or slow fluctuation strength as the
proportion of a modulation spectrum that falls within a specified range of
temporal modulation frequencies - both as a single total value and per
frequency band. Roughness or fluctuation can be calculated either as the
simple proportion of the spectrum within modRange, or as a weighted
version using a lognormal weighting function centered at modMean with
spread modSD. Recommended weighting function for measuring roughness:
modMean = 100, modSD = 8 (100 Hz ± 8 semitones); for measuring
low-frequency fluctuation: modMean = 4, modSD = 12 (4 Hz ± 12
semitones). Because the result is a proportion (numerator and denominator are
summed over the same modulation-frequency columns), positive and negative
temporal modulation frequencies do not need to be folded: any mirroring
cancels out.
getRoughness(m, modRange = NULL, modMean = 100, modSD = 8, plot = FALSE)
m |
numeric matrix of non-negative values with column names giving temporal modulation frequencies (Hz). Row names, if present, are used as the frequency-band labels in the output. |
modRange, modMean, modSD |
like "roughRange, roughMean, roughSD" or "fluctRange, fluctMean, fluctSD" in modulationSpectrum() |
plot |
if TRUE, plots a one-sided AM spectrum with the selected frequency range and weighting function |
A list with two components:
prop: the proportion of MS in the target range of modulation
frequencies, in percent (NA if no valid modRange or weighting
parameters, empty input, or no energy in the spectrum).
details: a data.frame with one row per frequency band and columns
freq (band label), prop (band-wise contribution to total
proportion, %), and amp (mean band amplitude, normalized to the
maximum band).
modulationSpectrum
s = soundgen(jitterDep = 2, amFreq = 80, amDep = 70, addSilence = 0)
m = modulationSpectrum(s, 16000, amRes = NULL, plot = FALSE)$detailed$original
## Ex. 1: simple proportion within modRange
r = soundgen:::getRoughness(m, modRange = c(30, Inf), plot = TRUE)
r = soundgen:::getRoughness(m, modRange = c(30, 150), plot = TRUE)
plot(r$details$freq, r$details$prop, type = 'b')
r$prop == sum(r$details$prop)
## Ex. 2: lognormal weighting function instead of modRange
# narrow
soundgen:::getRoughness(m, modRange = NULL, modMean = 75,
modSD = 3, plot = TRUE)
# broad
soundgen:::getRoughness(m, modRange = NULL, modMean = 75,
modSD = 10, plot = TRUE)
# truncated at modRange
soundgen:::getRoughness(m, modRange = c(30, 200), modMean = 75,
modSD = 10, plot = TRUE)
# NB: a very large modSD means we essentially revert to a simple proportion
## Ex. 3: measure low-frequency AM fluctuation instead of prop
# (just use a different weighting function)
s2 = sinpi(2*440*(1:16000)/16000) * (1 - cospi(2*5*(1:16000)/16000))
osc(s2, 16000)
m2 = modulationSpectrum(s2, 16000, amRes = NULL, plot = FALSE)$detailed$original
fl = soundgen:::getRoughness(m2, modRange = c(0.25, 30), modMean = 4,
modSD = 12, plot = TRUE)
fl$prop # in this case, a measure of slow fluctuation
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.