
Last chance! 50% off unlimited learning
Sale ends in
Internal soundgen function.
getFormantDispersion(formants, speedSound = 35400, method = c("fast",
"accurate")[2])
a vector of formant frequencies, Hz
speed of sound in warm air, cm/s. Stevens (2000) "Acoustic phonetics", p. 138
method of calculating formant dispersion: fast
for
simple averaging of inter-formant difference, accurate
for fitting a
linear regression to formant frequencies
Estimates formant dispersion based on one or more formant frequencies.
# NOT RUN {
nIter = 100 # nIter = 10000 for better results
speedSound = 35400
out = data.frame(vtl = runif(nIter, 5, 70),
nFormants = round(runif(nIter, 1, 10)),
noise = runif(nIter, 0, .2),
vtl_est = rep(NA, nIter),
error = rep(NA, nIter))
for (i in 1:nIter) {
a = 1:out$nFormants[i]
formants = sort(speedSound * (2 * a - 1) / (4 * out$vtl[i]) * rnorm(n = length(a),
mean = 1,
sd = out$noise[i]))
disp = soundgen:::getFormantDispersion(formants, method = 'fast')
out$vtl_est[i] = speedSound / 2 / disp
out$error[i] = (out$vtl[i] - out$vtl_est[i]) / out$vtl[i]
}
# }
# NOT RUN {
library(ggplot2)
ggplot(out, aes(x = nFormants, y = error)) +
geom_point(alpha = .1) +
geom_smooth() +
theme_bw()
ggplot(out, aes(x = noise, y = error)) +
geom_point(alpha = .1) +
geom_smooth() +
theme_bw()
# }
Run the code above in your browser using DataLab