comparison Code/Classifiers/SVM_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 [] = SVM_Formants_Singing( varargin )
2
3 cd 'C:\Users\dawn\Dropbox\TestResults'
4
5 DEBUG = 0;
6 % output results file name
7 masterFileOutputID = fopen( 'SVM_paper_SingingFormantsStats.txt', 'a' );
8 % input results file name
9 inputFileName = 'paper_singingFormantsStats.txt';
10
11 % This function allows the user to stipulate which Singing voice LLD's they
12 % wish to forward to a k-means classifier and produces a file of
13 % performance characteristics. Input arguments stipulate the LLD's and
14 % there is a choice of:-
15 %
16 % ---- PRAAT FORMANT MEASUREMENTS ----
17 % '_Formant_Burg'
18 % '_Formant_all'
19 % '_Formant_robust'
20 %
21 % A text file entitled kmeans_Singing_LLD1name_LLD2name_ ... LLDNname.txt
22 % is produced that contains the results of the k-mean classification for
23 % the LLD's specified and named in the result document title.
24
25 fprintf( masterFileOutputID, '\n RESULTS FILE NAME: %s\n', inputFileName);
26 inputFileID = fopen( inputFileName );
27
28 % get the column numbers of the results that we want to classify
29
30 % COLUMN NUMBER : METRIC
31 %
32 % ------------- BURG FORMANTS ---------------
33 % 11 : Number of BURG formants listed = nBF
34 %
35 % THERE ARE CURRENTLY 24 MEASUREMENTS TAKEN FOR EACH FORMANT
36 nMetrics = 24;
37 %
38 % 12 : mean frequency of the first BURG formant
39 % 13 : variance of the first BURG formant
40 % 14 : minimum frequency of the first BURG formant
41 % 15 : maximum frequency of the first BURG formant
42 % 16 : mean Frequency Derivative of the first BURG formant
43 % 17 : varience of the Frequency Derivative of the first BURG formant
44 % 18 : min of the Frequency Derivative of the first BURG formant
45 % 19 : max of the Frequency Derivative of the first BURG formant
46 % 20 : mean of the Frequency 2nd Derivative of the first BURG formant
47 % 21 : varience of the Frequency 2nd Derivative of the first BURG formant
48 % 22 : min of the Frequency 2nd Derivative of the first BURG formant
49 % 23 : max of the Frequency 2nd Derivative of the first BURG formant
50 % 24 : mean of the Bandwidth of the first BURG formant
51 % 25 : varience of the Bandwidth of the first BURG formant
52 % 26 : min of the Bandwidth of the first BURG formant
53 % 27 : max of the Bandwidth of the first BURG formant
54 % 28 : mean of the Bandwidth Derivative of the first BURG formant
55 % 29 : varience of the Bandwidth Derivative of the first BURG formant
56 % 30 : min of the Bandwidth Derivative of the first BURG formant
57 % 31 : max of the Bandwidth Derivative of the first BURG formant
58 % 32 : mean of the Bandwidth 2nd Derivative of the first BURG formant
59 % 33 : var of the Bandwidth 2nd Derivative of the first BURG formant
60 % 34 : min of the Bandwidth 2nd Derivative of the first BURG formant
61 % 35 : max of the Bandwidth 2nd Derivative of the first BURG formant
62 %
63 % ....... there are nMetrics for each formant in nBF formants, so cycle
64 % through until the last is reached ......
65 %
66 % 36 + ((nBF-1)*nMetrics) : mean frequency of the nBF BURG formant
67 % 36 + ((nBF-1)*nMetrics) + 1 : variance of the nBF BURG formant
68 % 36 + ((nBF-1)*nMetrics) + 2 : minimum frequency of the nBF BURG formant
69 % 36 + ((nBF-1)*nMetrics) + 3 : maximum frequency of the nBF BURG formant
70 % 36 + ((nBF-1)*nMetrics) + 4 : mean Frequency Derivative of the nBF BURG formant
71 % 36 + ((nBF-1)*nMetrics) + 5 : varience of the Frequency Derivative of the nBF BURG formant
72 % 36 + ((nBF-1)*nMetrics) + 6 : min of the Frequency Derivative of the nBF BURG formant
73 % 36 + ((nBF-1)*nMetrics) + 7 : max of the Frequency Derivative of the nBF BURG formant
74 % 36 + ((nBF-1)*nMetrics) + 8 : mean of the Frequency 2nd Derivative of the nBF BURG formant
75 % 36 + ((nBF-1)*nMetrics) + 9 : varience of the Frequency 2nd Derivative of the nBF BURG formant
76 % 36 + ((nBF-1)*nMetrics) + 10 : min of the Frequency 2nd Derivative of the nBF BURG formant
77 % 36 + ((nBF-1)*nMetrics) + 11 : max of the Frequency 2nd Derivative of the nBF BURG formant
78 % 36 + ((nBF-1)*nMetrics) + 12 : mean of the Bandwidth of the nBF BURG formant
79 % 36 + ((nBF-1)*nMetrics) + 13 : varience of the Bandwidth of the nBF BURG formant
80 % 36 + ((nBF-1)*nMetrics) + 14 : min of the Bandwidth of the nBF BURG formant
81 % 36 + ((nBF-1)*nMetrics) + 15 : max of the Bandwidth of the nBF BURG formant
82 % 36 + ((nBF-1)*nMetrics) + 16 : mean of the Bandwidth Derivative of the nBF BURG formant
83 % 36 + ((nBF-1)*nMetrics) + 17 : variece of the Bandwidth Derivative of the nBF BURG formant
84 % 36 + ((nBF-1)*nMetrics) + 18 : min of the Bandwidth Derivative of the nBF BURG formant
85 % 36 + ((nBF-1)*nMetrics) + 19 : max of the Bandwidth Derivative of the nBF BURG formant
86 % 36 + ((nBF-1)*nMetrics) + 20 : mean of the Bandwidth 2nd Derivative of the nBF BURG formant
87 % 36 + ((nBF-1)*nMetrics) + 21 : var of the Bandwidth 2nd Derivative of the nBF BURG formant
88 % 36 + ((nBF-1)*nMetrics) + 22 : min of the Bandwidth 2nd Derivative of the nBF BURG formant
89 % 36 + ((nBF-1)*nMetrics) + 23 : max of the Bandwidth 2nd Derivative of the nBF BURG formant
90 %
91 % FOR THE MEAN OF ALL BURG FORMANTS
92 % 36 + (nBF*nMetrics) : mean of all formants Frequency
93 % 36 + (nBF*nMetrics) + 1 : varience of the mean of all formants Frequency
94 % 36 + (nBF*nMetrics) + 2 : minimum of the mean of all formants Frequency
95 % 36 + (nBF*nMetrics) + 3 : maximum of the mean of all formants Frequency
96 % 36 + (nBF*nMetrics) + 4 : mean of all formants mean Frequency Derivative
97 % 36 + (nBF*nMetrics) + 5 : mean of all formants varience Frequency Derivative
98 % 36 + (nBF*nMetrics) + 6 : min of the mean of all formants Frequency Derivative
99 % 36 + (nBF*nMetrics) + 7 : max of the mean of all formants Frequency Derivative
100 % 36 + (nBF*nMetrics) + 8 : mean of the mean of all formants Frequency 2nd Derivative
101 % 36 + (nBF*nMetrics) + 9 : varience of the mean of all formants Frequency 2nd Derivative
102 % 36 + (nBF*nMetrics) + 10 : min of the mean of all formants Frequency 2nd Derivative
103 % 36 + (nBF*nMetrics) + 11 : max of the mean of all formants Frequency 2nd Derivative
104 %
105 % ------------- ALL FORMANTS ---------------
106 %
107 % 36 + (nBF*nMetrics) + 12 : Number of ALL formants listed = nAF
108 %
109 % startOfALLMeasurements = 36 + (nBF*nMetrics) + 13;
110 %
111 % startOfALLMeasurements : mean frequency of the first ALL formant
112 % startOfALLMeasurements + 1 : variance of the first ALL formant
113 % startOfALLMeasurements + 2 : minimum frequency of the first ALL formant
114 % startOfALLMeasurements + 3 : maximum frequency of the first ALL formant
115 % startOfALLMeasurements + 4 : mean Frequency Derivative of the first ALL formant
116 % startOfALLMeasurements + 5 : varience of the Frequency Derivative of the first ALL formant
117 % startOfALLMeasurements + 6 : min of the Frequency Derivative of the first ALL formant
118 % startOfALLMeasurements + 7 : max of the Frequency Derivative of the first ALL formant
119 % startOfALLMeasurements + 8 : mean of the Frequency 2nd Derivative of the first ALL formant
120 % startOfALLMeasurements + 9 : varience of the Frequency 2nd Derivative of the first ALL formant
121 % startOfALLMeasurements + 10 : min of the Frequency 2nd Derivative of the first ALL formant
122 % startOfALLMeasurements + 11 : max of the Frequency 2nd Derivative of the first ALL formant
123 % startOfALLMeasurements + 12 : mean of the Bandwidth of the first ALL formant
124 % startOfALLMeasurements + 13 : varience of the Bandwidth of the first ALL formant
125 % startOfALLMeasurements + 14 : min of the Bandwidth of the first ALL formant
126 % startOfALLMeasurements + 15 : max of the Bandwidth of the first ALL formant
127 % startOfALLMeasurements + 16 : mean of the Bandwidth Derivative of the first ALL formant
128 % startOfALLMeasurements + 17 : varience of the Bandwidth Derivative of the first ALL formant
129 % startOfALLMeasurements + 18 : min of the Bandwidth Derivative of the first ALL formant
130 % startOfALLMeasurements + 19 : max of the Bandwidth Derivative of the first ALL formant
131 % startOfALLMeasurements + 20 : mean of the Bandwidth 2nd Derivative of the first ALL formant
132 % startOfALLMeasurements + 21 : var of the Bandwidth 2nd Derivative of the first ALL formant
133 % startOfALLMeasurements + 22 : min of the Bandwidth 2nd Derivative of the first ALL formant
134 % startOfALLMeasurements + 23 : max of the Bandwidth 2nd Derivative of the first ALL formant
135 %
136 % ....... there are nMetrics for each formant in nAF formants, so cycle
137 % through until the last is reached ......
138 %
139 % startOfALLMeasurements + ((nAF-1)*nMetrics) : mean frequency of the nAF ALL formant
140 % startOfALLMeasurements + ((nAF-1)*nMetrics) : variance of the nAF ALL formant
141 % startOfALLMeasurements + ((nAF-1)*nMetrics) : minimum frequency of the nAF ALL formant
142 % startOfALLMeasurements + ((nAF-1)*nMetrics) : maximum frequency of the nAF ALL formant
143 % startOfALLMeasurements + ((nAF-1)*nMetrics) : mean Frequency Derivative of the nAF ALL formant
144 % startOfALLMeasurements + ((nAF-1)*nMetrics) : varience of the Frequency Derivative of the nAF ALL formant
145 % startOfALLMeasurements + ((nAF-1)*nMetrics) : min of the Frequency Derivative of the nAF ALL formant
146 % startOfALLMeasurements + ((nAF-1)*nMetrics) : max of the Frequency Derivative of the nAF ALL formant
147 % startOfALLMeasurements + ((nAF-1)*nMetrics) : mean of the Frequency 2nd Derivative of the nAF ALL formant
148 % startOfALLMeasurements + ((nAF-1)*nMetrics) : varience of the Frequency 2nd Derivative of the nAF ALL formant
149 % startOfALLMeasurements + ((nAF-1)*nMetrics) : min of the Frequency 2nd Derivative of the nAF ALL formant
150 % startOfALLMeasurements + ((nAF-1)*nMetrics) : max of the Frequency 2nd Derivative of the nAF ALL formant
151 % startOfALLMeasurements + ((nAF-1)*nMetrics) : mean of the Bandwidth of the nAF ALL formant
152 % startOfALLMeasurements + ((nAF-1)*nMetrics) : varience of the Bandwidth of the nAF ALL formant
153 % startOfALLMeasurements + ((nAF-1)*nMetrics) : min of the Bandwidth of the nAF ALL formant
154 % startOfALLMeasurements + ((nAF-1)*nMetrics) : max of the Bandwidth of the nAF ALL formant
155 % startOfALLMeasurements + ((nAF-1)*nMetrics) : mean of the Bandwidth Derivative of the nAF ALL formant
156 % startOfALLMeasurements + ((nAF-1)*nMetrics) : variece of the Bandwidth Derivative of the nAF ALL formant
157 % startOfALLMeasurements + ((nAF-1)*nMetrics) : min of the Bandwidth Derivative of the nAF ALL formant
158 % startOfALLMeasurements + ((nAF-1)*nMetrics) : max of the Bandwidth Derivative of the nAF ALL formant
159 % startOfALLMeasurements + ((nAF-1)*nMetrics) : mean of the Bandwidth 2nd Derivative of the nAF ALL formant
160 % startOfALLMeasurements + ((nAF-1)*nMetrics) : var of the Bandwidth 2nd Derivative of the nAF ALL formant
161 % startOfALLMeasurements + ((nAF-1)*nMetrics) : min of the Bandwidth 2nd Derivative of the nAF ALL formant
162 % startOfALLMeasurements + ((nAF-1)*nMetrics) : max of the Bandwidth 2nd Derivative of the nAF ALL formant
163 %
164 % FOR THE MEAN OF ALL ALL FORMANTS
165 % startOfALLMeasurements + (nAF*nMetrics) : mean of all formants Frequency
166 % startOfALLMeasurements + (nAF*nMetrics) + 1 : varience of the mean of all formants Frequency
167 % startOfALLMeasurements + (nAF*nMetrics) + 2 : minimum of the mean of all formants Frequency
168 % startOfALLMeasurements + (nAF*nMetrics) + 3 : maximum of the mean of all formants Frequency
169 % startOfALLMeasurements + (nAF*nMetrics) + 4 : mean of all formants mean Frequency Derivative
170 % startOfALLMeasurements + (nAF*nMetrics) + 5 : mean of all formants varience Frequency Derivative
171 % startOfALLMeasurements + (nAF*nMetrics) + 6 : min of the mean of all formants Frequency Derivative
172 % startOfALLMeasurements + (nAF*nMetrics) + 7 : max of the mean of all formants Frequency Derivative
173 % startOfALLMeasurements + (nAF*nMetrics) + 8 : mean of the mean of all formants Frequency 2nd Derivative
174 % startOfALLMeasurements + (nAF*nMetrics) + 9 : varience of the mean of all formants Frequency 2nd Derivative
175 % startOfALLMeasurements + (nAF*nMetrics) + 10 : min of the mean of all formants Frequency 2nd Derivative
176 % startOfALLMeasurements + (nAF*nMetrics) + 11 : max of the mean of all formants Frequency 2nd Derivative
177 %
178 % ------------- ROBUST FORMANTS ---------------
179 %
180 % startOfALLMeasurements + (nAF*nMetrics) + 12 : Number of ROBUST formants listed = nRF
181 %
182 % startOfROBUSTMeasurements = startOfALLMeasurements + (nAF*nMetrics) + 13;
183 %
184 % startOfROBUSTMeasurements : mean frequency of the first ROBUST formant
185 % startOfROBUSTMeasurements + 1 : variance of the first ROBUST formant
186 % startOfROBUSTMeasurements + 2 : minimum frequency of the first ROBUST formant
187 % startOfROBUSTMeasurements + 3 : maximum frequency of the first ROBUST formant
188 % startOfROBUSTMeasurements + 4 : mean Frequency Derivative of the first ROBUST formant
189 % startOfROBUSTMeasurements + 5 : varience of the Frequency Derivative of the first ROBUST formant
190 % startOfROBUSTMeasurements + 6 : min of the Frequency Derivative of the first ROBUST formant
191 % startOfROBUSTMeasurements + 7 : max of the Frequency Derivative of the first ROBUST formant
192 % startOfROBUSTMeasurements + 8 : mean of the Frequency 2nd Derivative of the first ROBUST formant
193 % startOfROBUSTMeasurements + 9 : varience of the Frequency 2nd Derivative of the first ROBUST formant
194 % startOfROBUSTMeasurements + 10 : min of the Frequency 2nd Derivative of the first ROBUST formant
195 % startOfROBUSTMeasurements + 11 : max of the Frequency 2nd Derivative of the first ROBUST formant
196 % startOfROBUSTMeasurements + 12 : mean of the Bandwidth of the first ROBUST formant
197 % startOfROBUSTMeasurements + 13 : varience of the Bandwidth of the first ROBUST formant
198 % startOfROBUSTMeasurements + 14 : min of the Bandwidth of the first ROBUST formant
199 % startOfROBUSTMeasurements + 15 : max of the Bandwidth of the first ROBUST formant
200 % startOfROBUSTMeasurements + 16 : mean of the Bandwidth Derivative of the first ROBUST formant
201 % startOfROBUSTMeasurements + 17 : varience of the Bandwidth Derivative of the first ROBUST formant
202 % startOfROBUSTMeasurements + 18 : min of the Bandwidth Derivative of the first ROBUST formant
203 % startOfROBUSTMeasurements + 19 : max of the Bandwidth Derivative of the first ROBUST formant
204 % startOfROBUSTMeasurements + 20 : mean of the Bandwidth 2nd Derivative of the first ROBUST formant
205 % startOfROBUSTMeasurements + 21 : var of the Bandwidth 2nd Derivative of the first ROBUST formant
206 % startOfROBUSTMeasurements + 22 : min of the Bandwidth 2nd Derivative of the first ROBUST formant
207 % startOfROBUSTMeasurements + 23 : max of the Bandwidth 2nd Derivative of the first ROBUST formant
208 %
209 % ....... there are nMetrics for each formant in nRF formants, so cycle
210 % through until the last is reached ......
211 %
212 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : mean frequency of the nRF ROBUST formant
213 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : variance of the nRF ROBUST formant
214 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : minimum frequency of the nRF ROBUST formant
215 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : maximum frequency of the nRF ROBUST formant
216 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : mean Frequency Derivative of the nRF ROBUST formant
217 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : varience of the Frequency Derivative of the nRF ROBUST formant
218 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : min of the Frequency Derivative of the nRF ROBUST formant
219 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : max of the Frequency Derivative of the nRF ROBUST formant
220 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : mean of the Frequency 2nd Derivative of the nRF ROBUST formant
221 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : varience of the Frequency 2nd Derivative of the nRF ROBUST formant
222 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : min of the Frequency 2nd Derivative of the nRF ROBUST formant
223 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : max of the Frequency 2nd Derivative of the nRF ROBUST formant
224 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : mean of the Bandwidth of the nRF ROBUST formant
225 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : varience of the Bandwidth of the nRF ROBUST formant
226 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : min of the Bandwidth of the nRF ROBUST formant
227 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : max of the Bandwidth of the nRF ROBUST formant
228 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : mean of the Bandwidth Derivative of the nRF ROBUST formant
229 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : variece of the Bandwidth Derivative of the nRF ROBUST formant
230 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : min of the Bandwidth Derivative of the nRF ROBUST formant
231 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : max of the Bandwidth Derivative of the nRF ROBUST formant
232 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : mean of the Bandwidth 2nd Derivative of the nRF ROBUST formant
233 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : var of the Bandwidth 2nd Derivative of the nRF ROBUST formant
234 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : min of the Bandwidth 2nd Derivative of the nRF ROBUST formant
235 % startOfROBUSTMeasurements + ((nRF-1)*nMetrics) : max of the Bandwidth 2nd Derivative of the nRF ROBUST formant
236 %
237 % FOR THE MEAN OF ALL ROBUST FORMANTS
238 % startOfROBUSTMeasurements + (nRF*nMetrics) : mean of all formants Frequency
239 % startOfROBUSTMeasurements + (nRF*nMetrics) + 1 : varience of the mean of all formants Frequency
240 % startOfROBUSTMeasurements + (nRF*nMetrics) + 2 : minimum of the mean of all formants Frequency
241 % startOfROBUSTMeasurements + (nRF*nMetrics) + 3 : maximum of the mean of all formants Frequency
242 % startOfROBUSTMeasurements + (nRF*nMetrics) + 4 : mean of all formants mean Frequency Derivative
243 % startOfROBUSTMeasurements + (nRF*nMetrics) + 5 : mean of all formants varience Frequency Derivative
244 % startOfROBUSTMeasurements + (nRF*nMetrics) + 6 : min of the mean of all formants Frequency Derivative
245 % startOfROBUSTMeasurements + (nRF*nMetrics) + 7 : max of the mean of all formants Frequency Derivative
246 % startOfROBUSTMeasurements + (nRF*nMetrics) + 8 : mean of the mean of all formants Frequency 2nd Derivative
247 % startOfROBUSTMeasurements + (nRF*nMetrics) + 9 : varience of the mean of all formants Frequency 2nd Derivative
248 % startOfROBUSTMeasurements + (nRF*nMetrics) + 10 : min of the mean of all formants Frequency 2nd Derivative
249 % startOfROBUSTMeasurements + (nRF*nMetrics) + 11 : max of the mean of all formants Frequency 2nd Derivative
250 %
251
252 noOfArguments = length(varargin);
253 columnIndices = [];
254
255 getBURGFormants = 0;
256 getAllFormants=0;
257 getRobustFormants=0;
258
259 for i=1 : noOfArguments
260 if( strcmp( varargin{i}, 'formant_Burg' ))
261 getBURGFormants = 1;
262 elseif( strcmp( varargin{i}, 'formant_all' ))
263 getAllFormants=1;
264 elseif( strcmp( varargin{i}, 'formant_robust' ))
265 getRobustFormants=1;
266 end
267 end
268
269 titleName = '';
270 for i=1 : noOfArguments
271 titleName = [ titleName varargin{i} '_'];
272 fprintf( masterFileOutputID, '%s_', varargin{i} );
273 end
274
275 fprintf( masterFileOutputID, '\t' );
276
277 % -------------------- get the data from the results file ---------------
278 lineCount = 0;
279 fileCount = 0;
280 data = [];
281 groups = [];
282
283 while( ~(feof(inputFileID)) )
284
285 outputValues = [];
286
287 thestr = fgetl(inputFileID);
288 if( lineCount > 10 ) % skip the file header
289 fileCount = fileCount + 1;
290
291 % determine whether we have a positive or negative sample
292 sampleEmotion( fileCount ) = 'U';
293 if( ~(isempty(strfind(thestr,'pos'))))
294 % sample is positive
295 sampleEmotion( fileCount ) = 'P';
296 groups( fileCount ) = 1;
297 elseif( ~(isempty(strfind(thestr,'neg'))))
298 % sample is negative
299 sampleEmotion( fileCount ) = 'N';
300 groups( fileCount ) = 0;
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
376
377 % ------------ apply the SVM classifier ------------------------
378
379 resultMatrix = [];
380
381 noOfIterations = 10;
382
383 for n = 1:noOfIterations
384 % Randomly select training and test sets, perhaps we should try all and
385 % choose the best?
386 [train, test] = crossvalind('holdOut',groups);
387 cp = classperf(groups);
388
389 % Use a linear support vector machine classifier
390 svmStruct = svmtrain(data(train,:),groups(train));
391 classes = svmclassify(svmStruct,data(test,:));
392 % See how well the classifier performed
393 classperf(cp,classes,test);
394 numbers = cp.CountingMatrix;
395
396 resultMatrix (n,:,:) = cp.DiagnosticTable;
397 %
398 end
399
400
401
402
403 % for emotion detection give the confusion matrix as
404 % -----------------------------------------------------------------
405 % positive correctly identified | positive incorrectly identified (1,2)
406 % negative incorrectly identified (2,1) | negative correctly identified
407 % ------------------------------------------------------------------
408
409 % takes the average of 10 iterations - do we want to take the best?
410
411 meanResults(1,1) = mean( resultMatrix(:,1,1) );
412 meanResults(1,2) = mean( resultMatrix(:,2,1) );
413 meanResults(2,1) = mean( resultMatrix(:,1,2) );
414 meanResults(2,2) = mean( resultMatrix(:,2,2) );
415
416 meanResults(3,:)=0;
417 meanResults(:,3)=0;
418
419 meanResults(3,3) = (meanResults(1,1) + meanResults(2,2));% / sum(sum(meanResults));
420
421 % convert to percentages
422 % how many of each sample do we have?
423 groupNumbers = unique( groups( test ));
424 groupNames = unique( sampleEmotion( test ));
425 sampleEmotionTest = sampleEmotion( test );
426 % which group is which emotion?
427 thisGroupNumber = groupNumbers(1);
428 thisGroup = find( groups( test ) == thisGroupNumber );
429 thisGroupName = unique( sampleEmotionTest( thisGroup ));
430
431 thatGroupNumber = groupNumbers(2);
432 thatGroup = find( groups( test ) == thatGroupNumber );
433 thatGroupName = unique( sampleEmotionTest( thatGroup ));
434
435 if(length( thisGroupName ) ~= 1 )
436 disp('ARGH!');
437 pause;
438 end
439
440 thisGroupNumberOfSamples = length( thisGroup );
441 thatGroupNumberOfSamples = length( thatGroup );
442
443 if( thisGroupName == 'P' )
444 %swap all the variables ready for checking
445 temp = thisGroupNumberOfSamples;
446 thisGroupNumberOfSamples = thatGroupNumberOfSamples;
447 thatGroupNumberOfSamples = temp;
448
449 temp = thisGroupName;
450 thisGroupName = thatGroupName
451 thatGroupName = temp;
452 disp('CHECK ME!');
453 end
454
455 if( thisGroupName == 'N' )
456 % group 0 is negative
457 if( sum( meanResults(1,:) ) == thisGroupNumberOfSamples )
458 %if the elements in the first row add up to the number of negative
459 %samples, then swap the rows because we want the top row to be the
460 %results for the positive samples
461 temp(:,1) = meanResults(1:2,2);
462 temp(:,2) = meanResults(1:2,1);
463 temp2(1,:) = temp(2,:);
464 temp2(2,:) = temp(1,:);
465
466 meanResults(1:2,1) = temp2(:,1);
467 meanResults(1:2,2) = temp2(:,2);
468
469 % check the number of positive samples
470 if(( sum( meanResults(1,:) ) == thatGroupNumberOfSamples ) ...
471 && ( thatGroupName == 'P' ) )
472 % row 1 is positive
473 disp('matrix correct');
474 else
475 disp('ARGH!');
476 pause;
477 end
478
479 elseif( sum( meanResults(2,:) ) == thisGroupNumberOfSamples )
480
481 % the elements in the second row add up to the number of negative
482 % samples, so the matrix is the correct way around
483
484 % check the number of positive samples
485 if(( sum( meanResults(1,:) ) == thatGroupNumberOfSamples ) ...
486 && ( thatGroupName == 'P' ) )
487 % row 0 is positive
488 disp('matrix correct');
489 else
490 disp('ARGH!');
491 pause;
492 end
493 end
494 end
495
496 % calculate the percentages
497 numberOfSamples = sum(sum( meanResults(1:2,1:2)));
498 percentageResults = meanResults;
499 percentageResults(1,1) = meanResults(1,1) / numberOfSamples;
500 percentageResults(1,2) = meanResults(1,2) / numberOfSamples;
501 percentageResults(2,1) = meanResults(2,1) / numberOfSamples;
502 percentageResults(2,2) = meanResults(2,2) / numberOfSamples;
503 percentageResults(3,3) = meanResults(3,3) / numberOfSamples;
504
505 percentageResults = percentageResults * 100
506
507 confusionMatrix = percentageResults;
508 fprintf( masterFileOutputID, '\n %f \t %f \n %f \t %f \n %f \t %f \t %f \n', confusionMatrix(1,1), confusionMatrix(1,2), confusionMatrix(2,1), confusionMatrix(2,2), 0, 0, confusionMatrix(3,3));
509
510 % print latex results to the screen
511 str1 = sprintf(' & %2.2f & %2.2f & \\\\', percentageResults(1,1), percentageResults(1,2) );
512 disp(str1);
513 str1 = sprintf(' & %2.2f & %2.2f & \\\\', percentageResults(2,1), percentageResults(2,2) );
514 disp(str1);
515 str1 = sprintf(' & & & %2.2f \\\\',percentageResults(3,3) );
516 disp(str1);
517
518 fprintf( masterFileOutputID, '\n' );
519 fclose( masterFileOutputID );
520
521 end
522
523 %------------------------------------------------------------------
524
525 function [ outputValues ] = stripOutFormantValues( vars, outputValues )
526
527 noOfFormantValues = length( vars ) - 1; % gives the number of formant arguments only
528 noOfFormants = vars(1);
529 % there are 12 measurements for the mean of all formants (so the number
530 % of formants is not important) for each formant measurement.
531 if( noOfFormants ~= (noOfFormantValues-12)/24 )
532 disp('EEK!');
533 pause;
534 else
535 outputValues = [ outputValues vars( 2:end )' ];
536 end
537
538 end
539
540 %-------------------------------------------------------------------