# plotVowels.R # Script for plotting vowel formants in a hertz space and then # in an ERB space, making the x- and y-axes cover the same range. # Start by setting the working directory to the directory where # you have the txt file containing the vowel formant values that # you want to plot (and where you want to store the output pictures. # Change the path name as below. setwd('c:/Lx600.01') # Read in the data as a data frame. This assumes that you have # a file with three tab-separated columns, that looks something # like this, which is the contents of the sampleVowels.txt file # that is linked into the course web page. Change the file name # as appropriate. # # vowel F1_Hz F2_Hz # [i] 360 2400 # [e] 680 1900 # [a] 800 1300 # [o] 590 900 # [u] 390 900 formants=data.frame(read.table("sampleVowels.txt",header=TRUE,sep="\t")) # Make two new columns that are the ERB values for these formants, # and name them appropriately. The formula for calculating ERB here # is taken from the following locus classicus: # Moore, B., & Glasberg, B.R. (1987). "Formulae describing frequency # selectivity as a function of frequency and level, and their use # in calculating excitation patterns." Hearing Research, 28, 209-225. # ERB stands for "equivalent rectangular bandwidth" and is a slightly # modified timbre scale that is close to Barks, differing mostly in # low frequencies. formants$F1_ERB= 11.17*log(((formants$F1_Hz/1000)+0.312)/((formants$F1_Hz/1000)+14.675))+43 formants$F2_ERB= 11.17*log(((formants$F2_Hz/1000)+0.312)/((formants$F2_Hz/1000)+14.675))+43 # Set up a window that is 6" wide by 6" high, using 12point type. windows(w=6,h=6,pointsize=12) # Specify plotting parameters to make the font be a serif font and # make the plot be square, and have no outside margin around the plot. par(family="serif",pty="s",oma=rep(0,4)) # Plot the formants in hertz space, with the x-axis going from # 2500 to 900 and the y-axis going from 1400 to 0. plot(formants$F2_Hz,formants$F1_Hz,xlim=c(2500,900),ylim=c(1500,0), xlab="second formant measured at vowel mid point (Hz)", ylab="first formant measured at vowel mid point (Hz)",pch=19) # Add text to label the points. text(formants$F2_Hz,formants$F1_Hz,formants$vowel,adj=c(1.5,0)) # Save the plot to a file of type "wmf" (for Windows Metafile). # Specify "ps" if you want to a Postscript file, "pdf" if you # want a PDF file, and so on. Type help(savePlot) to get more # options and to understand the syntax of this command. savePlot("formantsHz",type="wmf") # Now plot the formants in ERB # space, with the x-axis going from # 23 to 14 and the y-axis going from 15 to 6. plot(formants$F2_ERB,formants$F1_ERB,xlim=c(23,14),ylim=c(15,6), xlab="second formant measured at vowel mid point (ERB)", ylab="first formant measured at vowel mid point (ERB)",pch=19) # Add text to label the points. text(formants$F2_ERB,formants$F1_ERB,formants$vowel,adj=c(1.5,0)) # Save the plot to a file of type "wmf" (for Windows Metafile). # Specify "ps" if you want to a Postscript file, "pdf" if you # want a PDF file, and so on. Type help(savePlot) to get more # options and to understand the syntax of this command. savePlot("formantsERB",type="wmf")