#! Praat script p2/simulation/createEnvironment.praat # Paul Boersma, May 8, 2001 # # form Create two vowel environment choice Environment: 1 button scot button seng button span positive Duration_stdev 0.40 positive F1_stdev 0.20 endform if environment$ = "scot" mf1_I = log2 (485) mf1_i = log2 (343) mdur_I = log2 (84.8) mdur_i = log2 (94.0) elsif environment$ = "seng" mf1_I = log2 (337) mf1_i = log2 (292) mdur_I = log2 (59.7) mdur_i = log2 (104.6) elsif environment$ = "span" mf1_I = log2 (454) mf1_i = log2 (286) mdur_I = log2 (80) mdur_i = log2 (80) endif sf1_I = f1_stdev sf1_i = f1_stdev sdur_I = duration_stdev sdur_i = duration_stdev f1min = log2 (260) f1max = log2 (500) nf1 = 21 durmin = log2 (50) durmax = log2 (120) ndur = 21 f1step = (f1max - f1min) / (nf1 - 1) ymin = f1min - f1step / 2 ymax = f1max + f1step / 2 durstep = (durmax - durmin) / (ndur - 1) xmin = durmin - durstep / 2 xmax = durmax + durstep / 2 call createProbabilityMatrix I call createProbabilityMatrix i procedure createProbabilityMatrix vowel$ mf1 = mf1_'vowel$' sf1 = sf1_'vowel$' mdur = mdur_'vowel$' sdur = sdur_'vowel$' Create Matrix... 'environment$'_'vowel$' ... xmin xmax ndur durstep durmin ymin ymax nf1 f1step f1min ... exp (- (y-'mf1')^2 / (2*'sf1'^2) - (x-'mdur')^2 / (2*'sdur'^2)) / (2 * pi * 'sf1' * 'sdur') sum_p'vowel$' = Get sum endproc grand_p = sum_pi + sum_pI p_I = sum_pI / grand_p p_i = sum_pi / grand_p echo Summary: perc_I$ = fixed$ (100 * sum_pI / grand_p, 1) perc_i$ = fixed$ (100 * sum_pi / grand_p, 1) printline The environment has 'perc_I$'% /I/, 'perc_i$'% /i/. call drawProbabilityMatrix I call drawProbabilityMatrix i procedure drawProbabilityMatrix vowel$ select Matrix 'environment$'_'vowel$' Formula... self / 'grand_p' call initPicture Paint image... xmin xmax ymin ymax 0 0 mf1 = mf1_'vowel$' sf1 = sf1_'vowel$' mdur = mdur_'vowel$' sdur = sdur_'vowel$' White Text... mdur Centre mf1 Half /'vowel$'/ Black Draw ellipse... mdur-sdur mdur+sdur mf1-sf1 mf1+sf1 call garnish pause endproc procedure initPicture Erase all Times 10 Viewport... 0 2.2 0 1.8 endproc procedure garnish One mark left... log2(260) no yes no 260 One mark left... log2(300) no yes no 300 One mark left... log2(400) no yes no 400 One mark left... log2(500) no yes no 500 One mark bottom... log2(50) no yes no 50 One mark bottom... log2(60) no yes no 60 One mark bottom... log2(90) no yes no 90 One mark bottom... log2(120) no yes no 120 Text bottom... yes Duration (ms) Viewport... 0.1 1.9 0 1.8 Text left... yes %F_1 (Hz) Viewport... 0.1 1.9 0.3 1.8 endproc printline Maximum-likelihood listener: select Matrix 'environment$'_I Copy... maximumLikelihood_I Formula... self * if Matrix_'environment$'_i [] > self then 0 else 1 fi prob_I_correct = Get sum select Matrix 'environment$'_i Copy... maximumLikelihood_i Formula... self * if Matrix_'environment$'_I [] > self then 0 else 1 fi prob_i_correct = Get sum prob_correct = prob_I_correct + prob_i_correct perc_I_correct$ = fixed$ (100 * prob_I_correct / p_I, 3) perc_i_correct$ = fixed$ (100 * prob_i_correct / p_i, 3) perc_correct$ = fixed$ (100 * prob_correct, 3) printline Percentage correct: /I/ 'perc_I_correct$'%, /i/ 'perc_i_correct$'%, total 'perc_correct$'% printline Probability-matching listener: select Matrix 'environment$'_I Copy... maximumLikelihood_I Formula... self * self / (self + Matrix_'environment$'_i []) prob_I_correct = Get sum select Matrix 'environment$'_i Copy... maximumLikelihood_i Formula... self * self / (self + Matrix_'environment$'_I []) prob_i_correct = Get sum prob_correct = prob_I_correct + prob_i_correct perc_I_correct$ = fixed$ (100 * prob_I_correct / p_I, 3) perc_i_correct$ = fixed$ (100 * prob_i_correct / p_i, 3) perc_correct$ = fixed$ (100 * prob_correct, 3) printline Percentage correct: /I/ 'perc_I_correct$'%, /i/ 'perc_i_correct$'%, total 'perc_correct$'% pause Write to file? fileName$ = "'environment$'.PairDistribution" filedelete 'fileName$' fileappend 'fileName$' "ooTextFile"'newline$'"PairDistribution"'newline$' pairs = 2 * nf1 * ndur fileappend 'fileName$' 'pairs' pairs'newline$' for if1 to nf1 for idur to ndur f1 = f1min + (if1 - 1) * (f1max - f1min) / (nf1 - 1) dur = durmin + (idur - 1) * (durmax - durmin) / (ndur - 1) select Matrix 'environment$'_I p_I = Get value in cell... if1 idur select Matrix 'environment$'_i p_i = Get value in cell... if1 idur f1$ = fixed$ (2 ^ f1, 0) dur$ = fixed$ (2 ^ dur, 0) fileappend 'fileName$' "['f1$' Hz, 'dur$' ms]" "/I/" 'p_I''newline$' fileappend 'fileName$' "['f1$' Hz, 'dur$' ms]" "/i/" 'p_i''newline$' endfor endfor