comparison Code/Classifiers/kmeans_Formants_Singing.m @ 4:92ca03a8fa99 tip

Update to ICASSP 2013 benchmark
author Dawn Black
date Wed, 13 Feb 2013 11:02:39 +0000
parents
children
comparison
equal deleted inserted replaced
3:e1cfa7765647 4:92ca03a8fa99
1 function [] = kmeans_Formants_Singing( varargin )
2
3 cd 'C:\Users\dawn\Dropbox\TestResults'
4
5 DEBUG = 0;
6 % output results file name
7 masterFileOutputID = fopen( 'kmeans_paper_SingingFormantsStats.txt', 'a' );
8 % input results file name
9 % inputFileName = 'paper_singingFormantsStats_ZhangShuo.txt';
10 % inputFileName = 'paper_singingFormantsStats_WangXinnong.txt';
11 inputFileName = 'paper_singingFormantsStats.txt';
12
13 % This function allows the user to stipulate which Singing voice LLD's they
14 % wish to forward to a k-means classifier and produces a file of
15 % performance characteristics. Input arguments stipulate the LLD's and
16 % there is a choice of:-
17 %
18 % ---- PRAAT FORMANT MEASUREMENTS ----
19 % '_Formant_Burg'
20 % '_Formant_all'
21 % '_Formant_robust'
22 %
23 % A text file entitled kmeans_Singing_LLD1name_LLD2name_ ... LLDNname.txt
24 % is produced that contains the results of the k-mean classification for
25 % the LLD's specified and named in the result document title.
26
27 fprintf( masterFileOutputID, '\n RESULTS FILE NAME: %s\n', inputFileName);
28 inputFileID = fopen( inputFileName );
29
30 % get the column numbers of the results that we want to classify
31
32 % COLUMN NUMBER : METRIC
33 %
34 % ------------- BURG FORMANTS ---------------
35 % 11 : Number of BURG formants listed = nBF
36 %
37 % THERE ARE CURRENTLY 24 MEASUREMENTS TAKEN FOR EACH FORMANT
38 nMetrics = 24;
39 %
40 % 12 : mean frequency of the first BURG formant
41 % 13 : variance of the first BURG formant
42 % 14 : minimum frequency of the first BURG formant
43 % 15 : maximum frequency of the first BURG formant
44 % 16 : mean Frequency Derivative of the first BURG formant
45 % 17 : varience of the Frequency Derivative of the first BURG formant
46 % 18 : min of the Frequency Derivative of the first BURG formant
47 % 19 : max of the Frequency Derivative of the first BURG formant
48 % 20 : mean of the Frequency 2nd Derivative of the first BURG formant
49 % 21 : varience of the Frequency 2nd Derivative of the first BURG formant
50 % 22 : min of the Frequency 2nd Derivative of the first BURG formant
51 % 23 : max of the Frequency 2nd Derivative of the first BURG formant
52 % 24 : mean of the Bandwidth of the first BURG formant
53 % 25 : varience of the Bandwidth of the first BURG formant
54 % 26 : min of the Bandwidth of the first BURG formant
55 % 27 : max of the Bandwidth of the first BURG formant
56 % 28 : mean of the Bandwidth Derivative of the first BURG formant
57 % 29 : varience of the Bandwidth Derivative of the first BURG formant
58 % 30 : min of the Bandwidth Derivative of the first BURG formant
59 % 31 : max of the Bandwidth Derivative of the first BURG formant
60 % 32 : mean of the Bandwidth 2nd Derivative of the first BURG formant
61 % 33 : var of the Bandwidth 2nd Derivative of the first BURG formant
62 % 34 : min of the Bandwidth 2nd Derivative of the first BURG formant
63 % 35 : max of the Bandwidth 2nd Derivative of the first BURG formant
64 %
65 % ....... there are nMetrics for each formant in nBF formants, so cycle
66 % through until the last is reached ......
67 %
68 % 36 + ((nBF-1)*nMetrics) : mean frequency of the nBF BURG formant
69 % 36 + ((nBF-1)*nMetrics) + 1 : variance of the nBF BURG formant
70 % 36 + ((nBF-1)*nMetrics) + 2 : minimum frequency of the nBF BURG formant
71 % 36 + ((nBF-1)*nMetrics) + 3 : maximum frequency of the nBF BURG formant
72 % 36 + ((nBF-1)*nMetrics) + 4 : mean Frequency Derivative of the nBF BURG formant
73 % 36 + ((nBF-1)*nMetrics) + 5 : varience of the Frequency Derivative of the nBF BURG formant
74 % 36 + ((nBF-1)*nMetrics) + 6 : min of the Frequency Derivative of the nBF BURG formant
75 % 36 + ((nBF-1)*nMetrics) + 7 : max of the Frequency Derivative of the nBF BURG formant
76 % 36 + ((nBF-1)*nMetrics) + 8 : mean of the Frequency 2nd Derivative of the nBF BURG formant
77 % 36 + ((nBF-1)*nMetrics) + 9 : varience of the Frequency 2nd Derivative of the nBF BURG formant
78 % 36 + ((nBF-1)*nMetrics) + 10 : min of the Frequency 2nd Derivative of the nBF BURG formant
79 % 36 + ((nBF-1)*nMetrics) + 11 : max of the Frequency 2nd Derivative of the nBF BURG formant
80 % 36 + ((nBF-1)*nMetrics) + 12 : mean of the Bandwidth of the nBF BURG formant
81 % 36 + ((nBF-1)*nMetrics) + 13 : varience of the Bandwidth of the nBF BURG formant
82 % 36 + ((nBF-1)*nMetrics) + 14 : min of the Bandwidth of the nBF BURG formant
83 % 36 + ((nBF-1)*nMetrics) + 15 : max of the Bandwidth of the nBF BURG formant
84 % 36 + ((nBF-1)*nMetrics) + 16 : mean of the Bandwidth Derivative of the nBF BURG formant
85 % 36 + ((nBF-1)*nMetrics) + 17 : variece of the Bandwidth Derivative of the nBF BURG formant
86 % 36 + ((nBF-1)*nMetrics) + 18 : min of the Bandwidth Derivative of the nBF BURG formant
87 % 36 + ((nBF-1)*nMetrics) + 19 : max of the Bandwidth Derivative of the nBF BURG formant
88 % 36 + ((nBF-1)*nMetrics) + 20 : mean of the Bandwidth 2nd Derivative of the nBF BURG formant
89 % 36 + ((nBF-1)*nMetrics) + 21 : var of the Bandwidth 2nd Derivative of the nBF BURG formant
90 % 36 + ((nBF-1)*nMetrics) + 22 : min of the Bandwidth 2nd Derivative of the nBF BURG formant
91 % 36 + ((nBF-1)*nMetrics) + 23 : max of the Bandwidth 2nd Derivative of the nBF BURG formant
92 %
93 % FOR THE MEAN OF ALL BURG FORMANTS
94 % 36 + (nBF*nMetrics) : mean of all formants Frequency
95 % 36 + (nBF*nMetrics) + 1 : varience of the mean of all formants Frequency
96 % 36 + (nBF*nMetrics) + 2 : minimum of the mean of all formants Frequency
97 % 36 + (nBF*nMetrics) + 3 : maximum of the mean of all formants Frequency
98 % 36 + (nBF*nMetrics) + 4 : mean of all formants mean Frequency Derivative
99 % 36 + (nBF*nMetrics) + 5 : mean of all formants varience Frequency Derivative
100 % 36 + (nBF*nMetrics) + 6 : min of the mean of all formants Frequency Derivative
101 % 36 + (nBF*nMetrics) + 7 : max of the mean of all formants Frequency Derivative
102 % 36 + (nBF*nMetrics) + 8 : mean of the mean of all formants Frequency 2nd Derivative
103 % 36 + (nBF*nMetrics) + 9 : varience of the mean of all formants Frequency 2nd Derivative
104 % 36 + (nBF*nMetrics) + 10 : min of the mean of all formants Frequency 2nd Derivative
105 % 36 + (nBF*nMetrics) + 11 : max of the mean of all formants Frequency 2nd Derivative
106 %
107 % ------------- ALL FORMANTS ---------------
108 %
109 % 36 + (nBF*nMetrics) + 12 : Number of ALL formants listed = nAF
110 %
111 % startOfALLMeasurements = 36 + (nBF*nMetrics) + 13;
112 %
113 % startOfALLMeasurements : mean frequency of the first ALL formant
114 % startOfALLMeasurements + 1 : variance of the first ALL formant
115 % startOfALLMeasurements + 2 : minimum frequency of the first ALL formant
116 % startOfALLMeasurements + 3 : maximum frequency of the first ALL formant
117 % startOfALLMeasurements + 4 : mean Frequency Derivative of the first ALL formant
118 % startOfALLMeasurements + 5 : varience of the Frequency Derivative of the first ALL formant
119 % startOfALLMeasurements + 6 : min of the Frequency Derivative of the first ALL formant
120 % startOfALLMeasurements + 7 : max of the Frequency Derivative of the first ALL formant
121 % startOfALLMeasurements + 8 : mean of the Frequency 2nd Derivative of the first ALL formant
122 % startOfALLMeasurements + 9 : varience of the Frequency 2nd Derivative of the first ALL formant
123 % startOfALLMeasurements + 10 : min of the Frequency 2nd Derivative of the first ALL formant
124 % startOfALLMeasurements + 11 : max of the Frequency 2nd Derivative of the first ALL formant
125 % startOfALLMeasurements + 12 : mean of the Bandwidth of the first ALL formant
126 % startOfALLMeasurements + 13 : varience of the Bandwidth of the first ALL formant
127 % startOfALLMeasurements + 14 : min of the Bandwidth of the first ALL formant
128 % startOfALLMeasurements + 15 : max of the Bandwidth of the first ALL formant
129 % startOfALLMeasurements + 16 : mean of the Bandwidth Derivative of the first ALL formant
130 % startOfALLMeasurements + 17 : varience of the Bandwidth Derivative of the first ALL formant
131 % startOfALLMeasurements + 18 : min of the Bandwidth Derivative of the first ALL formant
132 % startOfALLMeasurements + 19 : max of the Bandwidth Derivative of the first ALL formant
133 % startOfALLMeasurements + 20 : mean of the Bandwidth 2nd Derivative of the first ALL formant
134 % startOfALLMeasurements + 21 : var of the Bandwidth 2nd Derivative of the first ALL formant
135 % startOfALLMeasurements + 22 : min of the Bandwidth 2nd Derivative of the first ALL formant
136 % startOfALLMeasurements + 23 : max of the Bandwidth 2nd Derivative of the first ALL formant
137 %
138 % ....... there are nMetrics for each formant in nAF formants, so cycle
139 % through until the last is reached ......
140 %
141 % startOfALLMeasurements + ((nAF-1)*nMetrics) : mean frequency of the nAF ALL formant
142 % startOfALLMeasurements + ((nAF-1)*nMetrics) : variance of the nAF ALL formant
143 % startOfALLMeasurements + ((nAF-1)*nMetrics) : minimum frequency of the nAF ALL formant
144 % startOfALLMeasurements + ((nAF-1)*nMetrics) : maximum frequency of the nAF ALL formant
145 % startOfALLMeasurements + ((nAF-1)*nMetrics) : mean Frequency Derivative of the nAF ALL formant
146 % startOfALLMeasurements + ((nAF-1)*nMetrics) : varience of the Frequency Derivative of the nAF ALL formant
147 % startOfALLMeasurements + ((nAF-1)*nMetrics) : min of the Frequency Derivative of the nAF ALL formant
148 % startOfALLMeasurements + ((nAF-1)*nMetrics) : max of the Frequency Derivative of the nAF ALL formant
149 % startOfALLMeasurements + ((nAF-1)*nMetrics) : mean of the Frequency 2nd Derivative of the nAF ALL formant
150 % startOfALLMeasurements + ((nAF-1)*nMetrics) : varience of the Frequency 2nd Derivative of the nAF ALL formant
151 % startOfALLMeasurements + ((nAF-1)*nMetrics) : min of the Frequency 2nd Derivative of the nAF ALL formant
152 % startOfALLMeasurements + ((nAF-1)*nMetrics) : max of the Frequency 2nd Derivative of the nAF ALL formant
153 % startOfALLMeasurements + ((nAF-1)*nMetrics) : mean of the Bandwidth of the nAF ALL formant
154 % startOfALLMeasurements + ((nAF-1)*nMetrics) : varience of the Bandwidth of the nAF ALL formant
155 % startOfALLMeasurements + ((nAF-1)*nMetrics) : min of the Bandwidth of the nAF ALL formant
156 % startOfALLMeasurements + ((nAF-1)*nMetrics) : max of the Bandwidth of the nAF ALL formant
157 % startOfALLMeasurements + ((nAF-1)*nMetrics) : mean of the Bandwidth Derivative of the nAF ALL formant
158 % startOfALLMeasurements + ((nAF-1)*nMetrics) : variece of the Bandwidth Derivative of the nAF ALL formant
159 % startOfALLMeasurements + ((nAF-1)*nMetrics) : min of the Bandwidth Derivative of the nAF ALL formant
160 % startOfALLMeasurements + ((nAF-1)*nMetrics) : max of the Bandwidth Derivative of the nAF ALL formant
161 % startOfALLMeasurements + ((nAF-1)*nMetrics) : mean of the Bandwidth 2nd Derivative of the nAF ALL formant
162 % startOfALLMeasurements + ((nAF-1)*nMetrics) : var of the Bandwidth 2nd Derivative of the nAF ALL formant
163 % startOfALLMeasurements + ((nAF-1)*nMetrics) : min of the Bandwidth 2nd Derivative of the nAF ALL formant
164 % startOfALLMeasurements + ((nAF-1)*nMetrics) : max of the Bandwidth 2nd Derivative of the nAF ALL formant
165 %
166 % FOR THE MEAN OF ALL ALL FORMANTS
167 % startOfALLMeasurements + (nAF*nMetrics) : mean of all formants Frequency
168 % startOfALLMeasurements + (nAF*nMetrics) + 1 : varience of the mean of all formants Frequency
169 % startOfALLMeasurements + (nAF*nMetrics) + 2 : minimum of the mean of all formants Frequency
170 % startOfALLMeasurements + (nAF*nMetrics) + 3 : maximum of the mean of all formants Frequency
171 % startOfALLMeasurements + (nAF*nMetrics) + 4 : mean of all formants mean Frequency Derivative
172 % startOfALLMeasurements + (nAF*nMetrics) + 5 : mean of all formants varience Frequency Derivative
173 % startOfALLMeasurements + (nAF*nMetrics) + 6 : min of the mean of all formants Frequency Derivative
174 % startOfALLMeasurements + (nAF*nMetrics) + 7 : max of the mean of all formants Frequency Derivative
175 % startOfALLMeasurements + (nAF*nMetrics) + 8 : mean of the mean of all formants Frequency 2nd Derivative
176 % startOfALLMeasurements + (nAF*nMetrics) + 9 : varience of the mean of all formants Frequency 2nd Derivative
177 % startOfALLMeasurements + (nAF*nMetrics) + 10 : min of the mean of all formants Frequency 2nd Derivative
178 % startOfALLMeasurements + (nAF*nMetrics) + 11 : max of the mean of all formants Frequency 2nd Derivative
179 %
180 % ------------- ROBUST FORMANTS ---------------
181 %
182 % startOfALLMeasurements + (nAF*nMetrics) + 12 : Number of ROBUST formants listed = nRF
183 %
184 % startOfROBUSTMeasurements = startOfALLMeasurements + (nAF*nMetrics) + 13;
185 %
186 % startOfROBUSTMeasurements : mean frequency of the first ROBUST formant
187 % startOfROBUSTMeasurements + 1 : variance of the first ROBUST formant
188 % startOfROBUSTMeasurements + 2 : minimum frequency of the first ROBUST formant
189 % startOfROBUSTMeasurements + 3 : maximum frequency of the first ROBUST formant
190 % startOfROBUSTMeasurements + 4 : mean Frequency Derivative of the first ROBUST formant
191 % startOfROBUSTMeasurements + 5 : varience of the Frequency Derivative of the first ROBUST formant
192 % startOfROBUSTMeasurements + 6 : min of the Frequency Derivative of the first ROBUST formant
193 % startOfROBUSTMeasurements + 7 : max of the Frequency Derivative of the first ROBUST formant
194 % startOfROBUSTMeasurements + 8 : mean of the Frequency 2nd Derivative of the first ROBUST formant
195 % startOfROBUSTMeasurements + 9 : varience of the Frequency 2nd Derivative of the first ROBUST formant
196 % startOfROBUSTMeasurements + 10 : min of the Frequency 2nd Derivative of the first ROBUST formant
197 % startOfROBUSTMeasurements + 11 : max of the Frequency 2nd Derivative of the first ROBUST formant
198 % startOfROBUSTMeasurements + 12 : mean of the Bandwidth of the first ROBUST formant
199 % startOfROBUSTMeasurements + 13 : varience of the Bandwidth of the first ROBUST formant
200 % startOfROBUSTMeasurements + 14 : min of the Bandwidth of the first ROBUST formant
201 % startOfROBUSTMeasurements + 15 : max of the Bandwidth of the first ROBUST formant
202 % startOfROBUSTMeasurements + 16 : mean of the Bandwidth Derivative of the first ROBUST formant
203 % startOfROBUSTMeasurements + 17 : varience of the Bandwidth Derivative of the first ROBUST formant
204 % startOfROBUSTMeasurements + 18 : min of the Bandwidth Derivative of the first ROBUST formant
205 % startOfROBUSTMeasurements + 19 : max of the Bandwidth Derivative of the first ROBUST formant
206 % startOfROBUSTMeasurements + 20 : mean of the Bandwidth 2nd Derivative of the first ROBUST formant
207 % startOfROBUSTMeasurements + 21 : var of the Bandwidth 2nd Derivative of the first ROBUST formant
208 % startOfROBUSTMeasurements + 22 : min of the Bandwidth 2nd Derivative of the first ROBUST formant
209 % startOfROBUSTMeasurements + 23 : max of the Bandwidth 2nd Derivative of the first ROBUST formant
210 %
211 % ....... there are nMetrics for each formant in nRF formants, so cycle
212 % through until the last is reached ......
213 %
214 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : mean frequency of the nRF ROBUST formant
215 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : variance of the nRF ROBUST formant
216 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : minimum frequency of the nRF ROBUST formant
217 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : maximum frequency of the nRF ROBUST formant
218 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : mean Frequency Derivative of the nRF ROBUST formant
219 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : varience of the Frequency Derivative of the nRF ROBUST formant
220 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : min of the Frequency Derivative of the nRF ROBUST formant
221 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : max of the Frequency Derivative of the nRF ROBUST formant
222 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : mean of the Frequency 2nd Derivative of the nRF ROBUST formant
223 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : varience of the Frequency 2nd Derivative of the nRF ROBUST formant
224 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : min of the Frequency 2nd Derivative of the nRF ROBUST formant
225 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : max of the Frequency 2nd Derivative of the nRF ROBUST formant
226 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : mean of the Bandwidth of the nRF ROBUST formant
227 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : varience of the Bandwidth of the nRF ROBUST formant
228 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : min of the Bandwidth of the nRF ROBUST formant
229 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : max of the Bandwidth of the nRF ROBUST formant
230 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : mean of the Bandwidth Derivative of the nRF ROBUST formant
231 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : variece of the Bandwidth Derivative of the nRF ROBUST formant
232 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : min of the Bandwidth Derivative of the nRF ROBUST formant
233 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : max of the Bandwidth Derivative of the nRF ROBUST formant
234 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : mean of the Bandwidth 2nd Derivative of the nRF ROBUST formant
235 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : var of the Bandwidth 2nd Derivative of the nRF ROBUST formant
236 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : min of the Bandwidth 2nd Derivative of the nRF ROBUST formant
237 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : max of the Bandwidth 2nd Derivative of the nRF ROBUST formant
238 %
239 % FOR THE MEAN OF ALL ROBUST FORMANTS
240 % startOfROBUSTMeasurements + (nRF*nMetrics) : mean of all formants Frequency
241 % startOfROBUSTMeasurements + (nRF*nMetrics) + 1 : varience of the mean of all formants Frequency
242 % startOfROBUSTMeasurements + (nRF*nMetrics) + 2 : minimum of the mean of all formants Frequency
243 % startOfROBUSTMeasurements + (nRF*nMetrics) + 3 : maximum of the mean of all formants Frequency
244 % startOfROBUSTMeasurements + (nRF*nMetrics) + 4 : mean of all formants mean Frequency Derivative
245 % startOfROBUSTMeasurements + (nRF*nMetrics) + 5 : mean of all formants varience Frequency Derivative
246 % startOfROBUSTMeasurements + (nRF*nMetrics) + 6 : min of the mean of all formants Frequency Derivative
247 % startOfROBUSTMeasurements + (nRF*nMetrics) + 7 : max of the mean of all formants Frequency Derivative
248 % startOfROBUSTMeasurements + (nRF*nMetrics) + 8 : mean of the mean of all formants Frequency 2nd Derivative
249 % startOfROBUSTMeasurements + (nRF*nMetrics) + 9 : varience of the mean of all formants Frequency 2nd Derivative
250 % startOfROBUSTMeasurements + (nRF*nMetrics) + 10 : min of the mean of all formants Frequency 2nd Derivative
251 % startOfROBUSTMeasurements + (nRF*nMetrics) + 11 : max of the mean of all formants Frequency 2nd Derivative
252 %
253
254 noOfArguments = length(varargin);
255 columnIndices = [];
256
257 getBURGFormants = 0;
258 getAllFormants=0;
259 getRobustFormants=0;
260
261 for i=1 : noOfArguments
262 if( strcmp( varargin{i}, 'formant_Burg' ))
263 getBURGFormants = 1;
264 elseif( strcmp( varargin{i}, 'formant_all' ))
265 getAllFormants=1;
266 elseif( strcmp( varargin{i}, 'formant_robust' ))
267 getRobustFormants=1;
268 end
269 end
270
271 titleName = '';
272 for i=1 : noOfArguments
273 titleName = [ titleName varargin{i} '_'];
274 fprintf( masterFileOutputID, '%s_', varargin{i} );
275 end
276
277 fprintf( masterFileOutputID, '\t' );
278
279 % -------------------- get the data from the results file ---------------
280 lineCount = 0;
281 fileCount = 0;
282 data = [];
283 while( ~(feof(inputFileID)) )
284
285 outputValues = [];
286 % sampleEmotion = [];
287 % gender = [];
288
289 thestr = fgetl(inputFileID);
290 if( lineCount > 10 ) % skip the file header
291 fileCount = fileCount + 1;
292
293 % determine whether we have a positive or negative sample
294 sampleEmotion( fileCount ) = 'U';
295 if( ~(isempty(strfind(thestr,'pos'))))
296 % sample is positive
297 sampleEmotion( fileCount ) = 'P';
298 elseif( ~(isempty(strfind(thestr,'neg'))))
299 % sample is negative
300 sampleEmotion( fileCount ) = 'N';
301 else
302 disp('EEEK!');
303 pause;
304 end
305
306 % % determine whether we have a male, female or trans sample
307 % gender( fileCount ) = '?';
308 % if( ~(isempty(strfind(thestr,'fem'))))
309 % % gender is female
310 % gender( fileCount ) = 'F';
311 % elseif( ~(isempty(strfind(thestr,'male'))))
312 % % gender is male
313 % gender( fileCount ) = 'M';
314 % elseif( ~(isempty(strfind(thestr,'trans'))))
315 % % gender is trans
316 % gender( fileCount ) = 'T';
317 % else
318 % disp('EEEK!');
319 % pause;
320 % end
321
322 %how many values are in the string?
323 spaces = strfind( thestr, ' ' );
324 numberstr = thestr( spaces(1) : end ); % chop off the file name
325 frmtpos = strfind( numberstr, 'maxNoOfFormants'); % find the position of the label for number of formants
326
327 % str1 = numberstr( 1 : frmtpos(1)-1 ); % string contains jitter and shimmer values
328 str2 = numberstr( frmtpos(1) : frmtpos(2)-1 ); % string contains all BURG formant information
329 str3 = numberstr( frmtpos(2) : frmtpos(3)-1 ); % string contains all ALL formant information
330 str4 = numberstr( frmtpos(3) : end ); % string contains all ROBUST formant information
331
332
333 % vars = sscanf( str1, '%f', inf );
334 % % extract the shimmer and jitter values
335 % outputValues = [ outputValues vars( columnIndices )'];
336
337 if( getBURGFormants )
338 spaces = strfind( str2, ' ' ); % remove the string 'maxNoOfFormants'
339 vars = sscanf( str2( spaces(1) : end ), '%f', inf );
340 outputValues = stripOutFormantValues( vars, outputValues );
341 end
342
343 if( getAllFormants )
344 spaces = strfind( str3, ' ' ); % remove the string 'maxNoOfFormants'
345 vars = sscanf( str3( spaces(1) : end ), '%f', inf );
346 outputValues = stripOutFormantValues( vars, outputValues );
347 end
348
349 if( getRobustFormants )
350 spaces = strfind( str4, ' ' ); % remove the string 'maxNoOfFormants'
351 vars = sscanf( str4( spaces(1) : end ), '%f', inf );
352 outputValues = stripOutFormantValues( vars, outputValues );
353 end
354
355 [m n] = size( data );
356 % sometimes the 'all' formants command gives us fewer formants than
357 % usual. If this is the case,then we will have to pad with zeros
358 % for now.
359 if( n > length( outputValues ) )
360 lenDiff = n - length( outputValues );
361 outputValues = [ outputValues zeros( 1, lenDiff ) ];
362 elseif( n < length( outputValues ) )
363 lenDiff = length( outputValues ) - n;
364 outputValues = [ outputValues zeros( 1, lenDiff ) ];
365 end
366
367 data( fileCount, : ) = outputValues;
368
369 end
370 lineCount = lineCount + 1;
371
372 end
373 fclose(inputFileID);
374
375 % ------------ apply the k-means classifier ------------------------
376
377 noOfClusters = 2; % we are only trying to identify positive and negative emotions
378
379
380 [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
381 'start', 'sample', 'Distance', 'cityblock');
382
383 %display results grouped by emotion
384 fprintf( masterFileOutputID, '\n Emotion grouping \n');
385 fprintf( masterFileOutputID, 'cityblock \n');
386 [ groupStats, groupNames ] = processKMeansResults( 'cityblock', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG );
387 [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID, 'cityblock' );
388
389
390 fprintf( masterFileOutputID, 'sqEuclidean \n');
391 [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
392 'start', 'sample', 'Distance', 'sqEuclidean');
393
394 [ groupStats, groupNames ] = processKMeansResults( 'sqEuclidean', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG );
395 [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID, 'sqEuclidean' );
396
397
398 fprintf( masterFileOutputID, 'cosine \n');
399 [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
400 'start', 'sample', 'Distance', 'cosine');
401
402 [ groupStats, groupNames ] = processKMeansResults( 'cosine', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG );
403 [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID,'cosine' );
404
405
406 fprintf( masterFileOutputID, 'correlation \n');
407 [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
408 'start', 'sample', 'Distance', 'correlation');
409
410 [ groupStats, groupNames ] = processKMeansResults( 'correlation', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG );
411 [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID, 'correlation' );
412
413
414 fprintf( masterFileOutputID, '\n' );
415 fclose( masterFileOutputID );
416
417 end
418
419 %------------------------------------------------------------------
420
421 function [ outputValues ] = stripOutFormantValues( vars, outputValues )
422
423 noOfFormantValues = length( vars ) - 1; % gives the number of formant arguments only
424 noOfFormants = vars(1);
425 % there are 12 measurements for the mean of all formants (so the number
426 % of formants is not important) for each formant measurement.
427 if( noOfFormants ~= (noOfFormantValues-12)/24 )
428 disp('EEK!');
429 pause;
430 else
431 outputValues = [ outputValues vars( 2:end )' ];
432 end
433
434 end
435
436 %-------------------------------------------------------------------