|
| 1 | +% JAS: this script simulates consonant cluster data based upon the Simplex |
| 2 | +% Onset Hypothesis and identifies the SD of the anchor that best |
| 3 | +% fits the data. |
| 4 | +% Output is a graph which plots R^2, goodness of fit, statistic by anchor |
| 5 | + |
| 6 | + |
| 7 | +close all; clear all; |
| 8 | +randn('state',0); % Reset the random number generator |
| 9 | + |
| 10 | +simN = 1000; %number of times simulation is repeated |
| 11 | +for count=1:simN %loops through iterations of the simulation |
| 12 | + |
| 13 | + |
| 14 | + N = 30; % number of datapoints; divisible by 3 |
| 15 | + stdv = 20; |
| 16 | + p = 30; % plateau duration |
| 17 | + ipi = 40; % inter-plateau interval |
| 18 | + |
| 19 | + % generate timestamps for C3 (the prevocalic consonant) |
| 20 | + % preallocate arrays for efficiency |
| 21 | + CL3 = zeros(1,N); %left edge of C3 |
| 22 | + CM3 = zeros(1,N); %right edge of C3 |
| 23 | + CR3 = zeros(1,N); %right edge of C3 |
| 24 | + |
| 25 | + % generate R(ight plateau edge = Release) of prevocalic consonant |
| 26 | + CR3 = sqrt(400).*randn(1,N) + 500; % generate N Gaussian distributed numbers with mean 500, variance 400 |
| 27 | + |
| 28 | + % generate L(eft plateau edge = Target) of prevocalic consonant |
| 29 | + for n=1:N; |
| 30 | + e = stdv * randn; % normally distributed random error, 0 mean |
| 31 | + CL3(n) = CR3(n) - (p + e); % generate L3 corresponding to R3 by assuming a plateau duration of 10 ms |
| 32 | + end; |
| 33 | + |
| 34 | + % calculate midpoint of prevocalic consonant |
| 35 | + for n=1:N; |
| 36 | + CM3(n) = (CR3(n) + CL3(n))/2; % |
| 37 | + end; |
| 38 | + |
| 39 | + %plot timestamps for C3 |
| 40 | + nbins = 20; |
| 41 | +% [CL3h,CL3out] = hist(CL3,nbins); % returns vectors Lh and Lout containing the frequency counts and the bin locations. |
| 42 | +% [CR3h,CR3out] = hist(CR3,nbins); % returns vectors Lh and Lout containing the frequency counts and the bin locations. |
| 43 | +% subplot(5,2,1); |
| 44 | +% bar(CL3out,CL3h); % plot the histogram |
| 45 | +% subplot(5,2,2); |
| 46 | +% bar(CR3out,CR3h); % plot the histogram |
| 47 | + |
| 48 | + % generate timestamps for C2 |
| 49 | + % preallocate arrays for efficiency |
| 50 | + CL2 = zeros(1,(2*(N/3))); %left edge of C2 |
| 51 | + CM2 = zeros(1,(2*(N/3))); %right edge of C2 |
| 52 | + CR2 = zeros(1,(2*(N/3))); %right edge of C2 |
| 53 | + |
| 54 | + % generate R(ight plateau edge = Release) of C2 from left edge of C3 |
| 55 | + % for C tokens |
| 56 | + %for n=1:(N/3) |
| 57 | + % CR2(n) = CR3(n); % the right edge of the cluster is the same as the right edge of the prevocalic consonant |
| 58 | + %end; |
| 59 | + |
| 60 | + % for CC/CCC tokens |
| 61 | + for n=1:(2*(N/3)); % alternative, use ceiling function |
| 62 | + e = stdv * randn; % normally distributed random error |
| 63 | + CR2(n) = CL3(n) - (ipi + e); % generate right edge of C2 from left edge of C2 assuming an ipi of 40 ms |
| 64 | + end; |
| 65 | + |
| 66 | + |
| 67 | + % generate L(eft plateau edge = Target) of C2 |
| 68 | + % for C tokens |
| 69 | + %for n=1:(N/3) |
| 70 | + % CL2(n) = CL3(n); % the left edge of the cluster is the same as the left edge of the prevocalic consonant |
| 71 | + %end; |
| 72 | + |
| 73 | + % for CC/CCC tokens |
| 74 | + for n=1:(2*(N/3)); |
| 75 | + e = stdv * randn; % normally distributed random error based on relation with CR3 |
| 76 | + CL2(n) = CR2(n) - (p + e); % generate L2 corresponding to CR3 by assuming a plateau duration |
| 77 | + end; |
| 78 | + |
| 79 | + % calculate midpoint of C2 |
| 80 | + % C tokens have no C2 and therefore no C2 midpoint |
| 81 | + for n=1:(2*(N/3)); |
| 82 | + CM2(n) = (CR2(n) + CL2(n))/2; % |
| 83 | + end; |
| 84 | + |
| 85 | + %plot timestamps for C2 |
| 86 | +% [CL2h,CL2out] = hist(CL2,nbins) % returns vectors Lh and Lout containing the frequency counts and the bin locations. |
| 87 | +% [CR2h,CR2out] = hist(CR2,nbins) % returns vectors Lh and Lout containing the frequency counts and the bin locations. |
| 88 | +% subplot(5,2,3); |
| 89 | +% bar(CL2out,CL2h); % plot the histogram |
| 90 | +% subplot(5,2,4); |
| 91 | +% bar(CR2out,CR2h); % plot the histogram |
| 92 | + |
| 93 | + % generate timestamps for C1 |
| 94 | + % preallocate arrays for efficiency |
| 95 | + CL1 = zeros(1, N); %left edge of C1 |
| 96 | + CM1 = zeros(1,(N/3)); %right edge of C1 |
| 97 | + CR1 = zeros(1,(N/3)); %right edge of C1 |
| 98 | + |
| 99 | + % generate R(ight plateau edge = Release) of C1 |
| 100 | + % for C tokens |
| 101 | + % for n=1:(N/3) |
| 102 | + % CR1(n) = CR2(n); % the right edge of the cluster is the same as the right edge of the prevocalic consonant |
| 103 | + % end; |
| 104 | + |
| 105 | + % % for CC tokens |
| 106 | + % for n=(N/3):(2*(N/3)) |
| 107 | + % CR1(n) = CR3(n); % the right edge of C1 equals the right edge of C3 |
| 108 | + % end; |
| 109 | + |
| 110 | + % for CCC tokens |
| 111 | + for n=1:(N/3); |
| 112 | + e = stdv * randn; % normally distributed random error |
| 113 | + CR1(n) = CL2(n) - (ipi + e); % generate right edge of C1 from left edge of C2 assuming ipi of 40ms |
| 114 | + end; |
| 115 | + |
| 116 | + % generate L(eft plateau edge = Target) of C1 |
| 117 | + % for CCC tokens |
| 118 | + for n=1:(N/3); |
| 119 | + e = stdv * randn; % normally distributed random error based on relation with CR3 |
| 120 | + CL1(n) = CR1(n) - (p + e); % generate L2 corresponding to CR1 by assuming a plateau of 10ms |
| 121 | + end; |
| 122 | + % for CC tokens |
| 123 | + for k=n+1:n+(N/3); |
| 124 | + CL1(k) = CL2(k); % left edge of C2 is the left edge of the cluster for CC |
| 125 | + end; |
| 126 | + % for C tokens |
| 127 | + for j=k+1:k+(N/3); |
| 128 | + CL1(j) = CL3(j); % the left edge of the cluster is the same as the left edge of the prevocalic consonant |
| 129 | + end; |
| 130 | + |
| 131 | + % calculate midpoint of prevocalic consonant |
| 132 | + % for CCC only |
| 133 | + for n=1:N/3; |
| 134 | + CM1(n) = (CR1(n) + CL1(n))/2; % |
| 135 | + end; |
| 136 | + |
| 137 | + %plot timestamps for C1 |
| 138 | +% [CL1h,CL1out] = hist(CL1,nbins) % returns vectors Lh and Lout containing the frequency counts and the bin locations. |
| 139 | +% [CR1h,CR1out] = hist(CR1,nbins) % returns vectors Lh and Lout containing the frequency counts and the bin locations. |
| 140 | +% subplot(5,2,5); |
| 141 | +% bar(CL1out,CL1h); % plot the histogram |
| 142 | +% subplot(5,2,6); |
| 143 | +% bar(CR1out,CR1h); % plot the histogram |
| 144 | + |
| 145 | + % generate timestamps for CCGlobal |
| 146 | + % preallocate array for efficiency |
| 147 | + CCglobal = zeros(1, N); %mean of midpoints |
| 148 | + |
| 149 | + %for CCC clusters |
| 150 | + for n=1:(N/3); |
| 151 | + CCglobal(n) = 1/3 * (CM1(n) + CM2(n) + CM3(n)); % mean of consonant midpoints |
| 152 | + end; |
| 153 | + |
| 154 | + %for CC clusters |
| 155 | + for k=n+1:n+(N/3); |
| 156 | + CCglobal(k) = 1/2 * (CM2(k) + CM3(k)); % mean of consonant midpoints |
| 157 | + end; |
| 158 | + |
| 159 | + %for C clusters |
| 160 | + for j=k+1:k+(N/3); |
| 161 | + CCglobal(j) = CM3(j); % CCglobal synchronous with prevocalic midpoint |
| 162 | + end; |
| 163 | + |
| 164 | + % generate series of anchor points increasing in distance from the prevocalic consonant |
| 165 | + AN = 20; %number of anchor points |
| 166 | + AD = 250; %interval from prevocalic consonant to closest anchor point |
| 167 | + DI = 0; % interval added to each subsequent anchor point |
| 168 | + VI = 5; % stepwise increase in variability |
| 169 | + |
| 170 | + % preallocate array for efficiency |
| 171 | + A = zeros(AN,N); %one column for each anchor (AN) and one row for each token |
| 172 | + |
| 173 | + %cycle loop produces new anchor for each token |
| 174 | + for cycle = 1: AN; %creates multiple anchor points for each token |
| 175 | + for m=1:N; %creates anchor point for each token from the right edge of the token |
| 176 | + Ae = stdv * randn; % normally distributed random error, assuming mean of 0 |
| 177 | + A(cycle, m) = CR3(m) + AD + Ae; % generate anchor A corresponding to CR3 by assuming a period of 200 ms |
| 178 | + end; |
| 179 | + AD = AD + DI; %increases distance for each anchor point by interval DI |
| 180 | + stdv = stdv + VI; %creates new anchor point |
| 181 | + end; |
| 182 | + |
| 183 | + % plot anchor points |
| 184 | +% [Ah,Aout] = hist(A(1,:),nbins) % returns vectors Lh and Lout containing the frequency counts and the bin locations. |
| 185 | +% subplot(5,2,7); |
| 186 | +% bar(Aout,Ah); % plot the histogram |
| 187 | +% ylabel('Anchor 1'); |
| 188 | + |
| 189 | +% [Ah,Aout] = hist(A(4,:),nbins) % returns vectors Lh and Lout containing the frequency counts and the bin locations. |
| 190 | +% subplot(5,2,8); |
| 191 | +% bar(Aout,Ah); % plot the histogram |
| 192 | +% ylabel('Anchor 4'); |
| 193 | + |
| 194 | + |
| 195 | +%Note about consonantal landmarks: they are replaced with each cycle of the simulation |
| 196 | +%in constrast, RSD values for each landmark are stored across simulations. |
| 197 | + |
| 198 | + for cycle = 1: AN; %cycles through for each anchor point |
| 199 | + %if CoV==0 % if 1, then coefficient of variance; if 0, standard deviation |
| 200 | + |
| 201 | + %xv = [std(A(cycle)-CL1) std(A(cycle)-CCglobal) std(A(cycle)-CR3)]; |
| 202 | + %else |
| 203 | + %xd(1, cycle) = [(mean(A(cycle,:)))]; %xd = average distance of prevocalic consonant to a given anchor |
| 204 | + |
| 205 | + LE_RSD(count, cycle) = std(A(cycle,:)-CL1)/(mean(A(cycle,:))-mean(CL1)); |
| 206 | + RE_RSD(count, cycle) = std(A(cycle,:)-CR3)/(mean(A(cycle,:))-mean(CR3)); |
| 207 | + CC_RSD(count, cycle) = std(A(cycle,:)-CCglobal)/(mean(A(cycle,:))-mean(CCglobal)); |
| 208 | + |
| 209 | + LE_SD(count, cycle) = std(A(cycle,:)-CL1); |
| 210 | + RE_SD(count, cycle) = std(A(cycle,:)-CR3); |
| 211 | + CC_SD(count, cycle) = std(A(cycle,:)-CCglobal); |
| 212 | + |
| 213 | + %end; |
| 214 | + |
| 215 | + end; |
| 216 | + |
| 217 | + end %main simulation loop |
| 218 | + |
| 219 | +%Plot RSD across simulations |
| 220 | + % plot mean RSD across simulations as a function of anchor distance |
| 221 | + % subplot(5,2,10); |
| 222 | + % plot(xd, LE_RSD, 'b-', xd, RE_RSD, 'g-', xd, CC_RSD, 'r:') |
| 223 | + |
| 224 | + % plot mean RSD across simulations for each anchor point as a function of anchor number |
| 225 | + |
| 226 | + x = 1:1:AN; %establishes x-axis as anchor |
| 227 | + plot(x, mean(LE_RSD(:,x)), 'b-',x, mean(RE_RSD(:,x)), 'g-',x, mean(CC_RSD(:,x)), 'r:'); |
| 228 | + |
| 229 | + |
| 230 | + |
| 231 | + |
| 232 | + |
| 233 | + |
| 234 | + |
| 235 | + |
| 236 | + |
| 237 | + |
| 238 | + |
| 239 | + |
| 240 | + |
| 241 | + |
0 commit comments