# # More about this R code is available at: # <http://www.languagebits.com/?p=1057> # # Romeo Mlinar <mlinar [a] languagebits.com> Resonance <- function(tract.len, nf=5){ # Calculates the resonant frequencies of the # vocal tract. # tract.len - the length of the vocal tract in centimetres # nf - the number of formants to calculate # # Formula from: # Johnson, Keith. Acoustic and Auditory Phonetics. # 2nd ed. Malden, Mass: Blackwell Pub, 2003. # p. 96 # formants <- 1:nf cat("Tract length is", tract.len, "cm.", "\n") for (i in formants){ freq <- ((2*i-1)*35000)/(4*tract.len) cat("formant ", i, ": ", round(freq, 2), ' Hz', '\n', sep="") } } Length <- function(freq, formant){ # Calculate the length of vocal tract # freq - frequency in Hz # formant - formant number # # The above formula was "reversed" in MS Mathematica 4.0. prep <- 35000*((formant/2)-0.25) length <- (prep/freq) cat("Estimated tract length is ", length, " cm, where formant number ", formant, " has value of ", freq, " Hz.", "\n", sep="") }