comparison Code/ProcessDatabase.m @ 4:92ca03a8fa99 tip

Update to ICASSP 2013 benchmark
author Dawn Black
date Wed, 13 Feb 2013 11:02:39 +0000
parents a3d62264030c
children
comparison
equal deleted inserted replaced
3:e1cfa7765647 4:92ca03a8fa99
1 function [] = ProcessDatabase( databaseName, functionName, sampleStartNum, OVERWRITE ) 1 function [] = ProcessDatabase( databaseName, functionName, sampleStartNum, OVERWRITE )
2 % run from D:\Dropbox\BUPTResearch2011\EmotionDetectionCode\Code 2 % run from D:\Dropbox\BUPTResearch2011\EmotionDetectionCode\Code
3 machineName = getenv('COMPUTERNAME'); 3 machineName = getenv('COMPUTERNAME');
4 fclose('all');
4 5
5 switch machineName 6 switch machineName
6 case 'LAPTOP' 7 case 'LAPTOP'
7 % for Dawn's laptop 8 % for Dawn's laptop
8 root = 'D:\Dropbox\' 9 root = 'D:\Dropbox\'
17 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code']) 18 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code'])
18 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\Matlab\MPEG7']) 19 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\Matlab\MPEG7'])
19 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\Matlab\Common']) 20 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\Matlab\Common'])
20 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\Matlab\MPEG7\FromWeb']) 21 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\Matlab\MPEG7\FromWeb'])
21 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\PRAAT']) 22 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\PRAAT'])
23 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\Matlab\Speech'])
24 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Descriptors\yin\'])
22 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Collation']) 25 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\Collation'])
23 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\General']) 26 addpath ([root 'BUPTResearch2011\emotionDetectionCode\Code\General'])
24 27
25 switch databaseName 28 switch databaseName
26 case 'ChineseOpera' 29 case 'ChineseOperaTest'
27 cd([root 'BUPTResearch2011/Data/Opera/TestDatabase']) 30 cd([root 'BUPTResearch2011/Data/Opera/TestDatabase'])
28 startEmotion = 4; 31 startEmotion = 4;
32 case 'ChineseOperaFull'
33 cd([root 'BUPTResearch2011/Data/Opera/FullDatabase'])
34 startEmotion = 3;
35 case 'ChineseOperaPaper'
36 cd([root 'BUPTResearch2011/Data/Opera/PaperDatabase'])
37 startEmotion = 3;
29 case 'MandarinSpeech' 38 case 'MandarinSpeech'
30 cd([root 'BUPTResearch2011/Data/Database/EditedRecording']) 39 cd([root 'BUPTResearch2011/Data/Database/EditedRecording'])
31 startEmotion = 3; 40 startEmotion = 3;
32 case 'SpeechTestFiles' 41 case 'SpeechTestFiles'
33 cd([root 'BUPTResearch2011\Data\SpeechTestFiles\MyAnnotatedFiles']) 42 cd([root 'BUPTResearch2011\Data\SpeechTestFiles\MyAnnotatedFiles'])
49 if( fileStructure(sampleNum).isdir == 1 ) % only directories 58 if( fileStructure(sampleNum).isdir == 1 ) % only directories
50 cd( sampleDirName ); 59 cd( sampleDirName );
51 % how many emotions for that sample? 60 % how many emotions for that sample?
52 validEmotionList = dir; 61 validEmotionList = dir;
53 noOfEmotions = size( validEmotionList ); 62 noOfEmotions = size( validEmotionList );
54 63 % figure;
55 for emotionNum = startEmotion : noOfEmotions(1) 64 for emotionNum = startEmotion : noOfEmotions(1)
56 emotionName = validEmotionList(emotionNum).name; 65 emotionName = validEmotionList(emotionNum).name;
57 cd( emotionName ); 66 cd( emotionName );
58 % how many samples for that emotion? 67 % how many samples for that emotion?
59 sampleNames = dir; 68 sampleNames = dir;
60 noOfSamples = size( sampleNames ); 69 noOfSamples = size( sampleNames );
70
61 71
62 for sampleNumber = 3 : noOfSamples(1) 72 for sampleNumber = 3 : noOfSamples(1)
63 if( sampleNames(sampleNumber).isdir == 0 ) % skip directories 73 if( sampleNames(sampleNumber).isdir == 0 ) % skip directories
64 currentSampleName = sampleNames(sampleNumber).name 74 currentSampleName = sampleNames(sampleNumber).name
65 % get the file type 75 % get the file type
111 % spectralCentroidThreshold = [spectralCentroidThreshold st]; 121 % spectralCentroidThreshold = [spectralCentroidThreshold st];
112 % energyThreshold = [energyThreshold et]; 122 % energyThreshold = [energyThreshold et];
113 % oldDirName = newDirName; 123 % oldDirName = newDirName;
114 % 124 %
115 % fclose( statsFileID ); 125 % fclose( statsFileID );
116 % case 'getPitchStatistics' 126 case 'getPitchStatistics'
117 % statsHeaderFileName = '../../../../FeatureSets/singingHeaderPitchStats.txt'; 127
118 % statsHeaderFileID = fopen( statsHeaderFileName, 'w' ); 128 switch databaseName
119 % if( firstfileOpen == 1 ) 129 case 'ChineseOperaTest'
120 % fprintf( statsHeaderFileID, 'name \t unvoiced to voiced frame ratio \t mean voiced pitch \t median voiced pitch \t stdev voiced pitch \t variance voiced pitch \t min voiced pitch \t max voiced pitch \t range voiced pitch \t mean voiced pitch grad \t median voiced pitch grad \t stdev pitch grad \t variance voiced pitch grad \t min voiced pitch grad \t max voiced pitch grad \t range voiced pitch grad \n'); 130 statsFileName = '../../../../../../../TestResults/test_singingPitchStats_Voiced.txt';
121 % firstfileOpen = 0; 131 case 'ChineseOperaFull'
122 % end 132 statsFileName = '../../../../../../../TestResults/full_singingPitchStats.txt';
123 % fclose(statsHeaderFileID); 133 case 'ChineseOperaPaper'
124 % 134 statsFileName = '../../../../../../../TestResults/paper_singingPitchStats_Voiced.txt';
125 % statsFileName = '../../../../FeatureSets/singingPitchStats.txt'; 135 case 'MandarinSpeech'
126 % statsFileID = fopen( statsFileName, 'a' ); 136 statsFileName = '../../../../../../../TestResults/mandarinPitchStats.txt';
127 % 137 case 'SpeechTestFiles'
128 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName ); 138 statsFileName = '../../../../../../../TestResults/speechPitchStats.txt';
129 % getPitchStatistics( newDirName, x, fs, statsFileID, frameLength, noOfFrames ); 139 end
130 % fclose( statsFileID ); 140
131 % 141 statsFileID = fopen( statsFileName, 'a' );
132 % 142 get_Pitch( newDirName, statsFileID );
133 % 143 fclose( statsFileID );
134 % 144
135 % 145 case 'getHNRStatistics'
136 % %%%%%%%%%%%%%%% careful %%%%%%%%%%%%%%% 146 switch databaseName
137 % case 'getHNRStatistics' 147 case 'ChineseOperaTest'
138 % statsHeaderFileName = '../../../../FeatureSets/singingHeaderHNRStats.txt'; 148 statsFileName = '../../../../../../../TestResults/test_singingHNRStats.txt';
139 % statsHeaderFileID = fopen( statsHeaderFileName, 'w' ); 149 case 'ChineseOperaPaper'
140 % if( firstfileOpen == 1 ) 150 statsFileName = '../../../../../../../TestResults/paper_singingHNRStats.txt';
141 % fprintf( statsHeaderFileID, 'name \t \t \t \t \t \n'); 151 case 'ChineseOperaFull'
142 % firstfileOpen = 0; 152 statsFileName = '../../../../../../../TestResults/full_singingHNRStats.txt'
143 % end 153 case 'MandarinSpeech'
144 % fclose(statsHeaderFileID); 154 statsFileName = '../../../../../../../TestResults/mandarinHNRStats.txt';
145 % 155 case 'SpeechTestFiles'
146 % statsFileName = '../../../../FeatureSets/singingHNRStats.txt'; 156 statsFileName = '../../../../../../../TestResults/speechHNRStats.txt';
147 % statsFileID = fopen( statsFileName, 'a' ); 157 end
148 % 158
149 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName ); 159 statsFileID = fopen( statsFileName, 'a' );
150 % getHNRStatistics( newDirName, x, fs, statsFileID, frameLength, noOfFrames ); 160 get_HNR( newDirName, statsFileID );
151 % fclose( statsFileID ); 161 fclose( statsFileID );
152 % 162
153 % 163 case 'getEnergyStatistics'
154 % 164 switch databaseName
165 case 'ChineseOperaTest'
166 statsFileName = '../../../../../../../TestResults/test_singingEnergyStats.txt';
167 case 'ChineseOperaPaper'
168 statsFileName = '../../../../../../../TestResults/paper_singingEnergyStats.txt';
169 case 'ChineseOperaFull'
170 statsFileName = '../../../../../../../TestResults/full_singingEnergyStats.txt'
171 case 'MandarinSpeech'
172 statsFileName = '../../../../../../../TestResults/mandarinEnergyStats.txt';
173 case 'SpeechTestFiles'
174 statsFileName = '../../../../../../../TestResults/speechEnergyStats.txt';
175 end
176 statsFileID = fopen( statsFileName, 'a' );
177 if( firstfileOpen == 1 )
178 fprintf( statsFileID, 'name \t mean energy \t energy variance \t min \t max \t mean voiced energy \t mean unvoiced energy \n');
179 firstfileOpen = 0;
180 end
181
182 get_AudioPower( newDirName, statsFileID );
183 fclose( statsFileID );
184
155 % 185 %
156 % case 'getEnergyStatistics' 186 % case 'getEnergyStatistics'
157 % statsFileName = '../../../../FeatureSets/singingEnergyStats.txt'; 187 % statsFileName = '../../../../FeatureSets/singingEnergyStats.txt';
158 % statsFileID = fopen( statsFileName, 'a' ); 188 % statsFileID = fopen( statsFileName, 'a' );
159 % if( firstfileOpen == 1 ) 189 % if( firstfileOpen == 1 )
233 % firstfileOpen = 0; 263 % firstfileOpen = 0;
234 % end 264 % end
235 % 265 %
236 % getSpectralTimbralDescriptors( newDirName, statsFileID ); 266 % getSpectralTimbralDescriptors( newDirName, statsFileID );
237 % fclose( statsFileID ); 267 % fclose( statsFileID );
238 % case 'getMFCCs' 268 case 'getMFCCs'
239 % if( firstfileOpen ) 269
240 % statsFileName = '../../../../FeatureSets/singingMFCCDescriptorsHeader.txt'; 270 switch databaseName
241 % statsFileID = fopen( statsFileName, 'w' ); 271 case 'ChineseOperaTest'
242 % 272 statsFileName = '../../../../../../../TestResults/test_singingMFCCStats_VoicedAndUnvoiced_Unsmoothed.txt';
243 % % Add a header file 273 case 'ChineseOperaFull'
244 % % putMFCCHeader( statsFileID ); 274 statsFileName = '../../../../../../../TestResults/full_singingMFCCStats_VoicedAndUnvoiced_Unsmoothed.txt';
245 % fclose( statsFileID ); 275 case 'ChineseOperaPaper'
246 % end 276 statsFileName = '../../../../../../../TestResults/paper_singingMFCCStats.txt';
247 % 277 case 'MandarinSpeech'
248 % statsFileName = '../../../../FeatureSets/singingMFCCDescriptors.txt'; 278 statsFileName = '../../../../../../../TestResults/mandarinMFCCStats.txt';
249 % statsFileID = fopen( statsFileName, 'a' ); 279 case 'SpeechTestFiles'
250 % 280 statsFileName = '../../../../../../../TestResults/speechMFCCStats.txt';
251 % getMFCCStatistics( newDirName, statsFileID ); 281 end
252 % fclose( statsFileID ); 282
253 % 283 if( firstfileOpen == 1 )
254 % %lin 284 statsFileID = fopen( statsFileName, 'w' );
285 firstfileOpen = 0;
286 else
287 statsFileID = fopen( statsFileName, 'a' );
288 end
289
290 get_MFCCS( newDirName, statsFileID );
291 fclose( statsFileID );
292
293
255 case 'getPRAAT' 294 case 'getPRAAT'
256 % collate all Shimmer values 295 % collate all PRAAT values
257 statsFileName = '../../../../../../../TestResults/singingPRAATStats.txt'; 296 switch databaseName
297 case 'ChineseOperaTest'
298 statsFileName = '../../../../../../../TestResults/test_singingPRAATStats.txt';
299 case 'ChineseOperaFull'
300 statsFileName = '../../../../../../../TestResults/full_singingPRAATStats.txt';
301 case 'ChineseOperaPaper'
302 statsFileName = '../../../../../../../TestResults/paper_singingPRAATStats.txt';
303 case 'MandarinSpeech'
304 statsFileName = '../../../../../../../TestResults/mandarinPRAATStats.txt';
305 case 'SpeechTestFiles'
306 statsFileName = '../../../../../../../TestResults/speechPRAATStats.txt';
307 end
258 308
259 % Add a header row 309 % Add a header row
260 if( firstfileOpen == 1 ) 310 if( firstfileOpen == 1 )
261 statsFileID = fopen( statsFileName, 'w' ); 311 statsFileID = fopen( statsFileName, 'w' );
262 fprintf( statsFileID, 'Metrics calculated using the PRAAT software. \n' ); 312 fprintf( statsFileID, 'Metrics calculated using the PRAAT software. \n' );
276 end 326 end
277 327
278 get_PRAAT( newDirName, statsFileID ); 328 get_PRAAT( newDirName, statsFileID );
279 fclose( statsFileID ); 329 fclose( statsFileID );
280 330
281 % case 'getJitter' 331 case 'getJitter'
282 % % collate Jitter 332 % collate all Jitter values
283 % statsFileName = '../../../../FeatureSets/singingJitterStats.txt'; 333 switch databaseName
284 % statsFileID = fopen( statsFileName, 'a' ); 334 case 'ChineseOperaTest'
285 % 335 statsFileName = '../../../../../../../TestResults/test_singingJitterStats.txt';
286 % getJitter( newDirName, statsFileID ); 336 case 'ChineseOperaFull'
287 % fclose( statsFileID ); 337 statsFileName = '../../../../../../../TestResults/full_singingJitterStats.txt';
288 % 338 case 'ChineseOperaPaper'
289 % 339 statsFileName = '../../../../../../../TestResults/paper_singingJitterStats.txt';
340 case 'MandarinSpeech'
341 statsFileName = '../../../../../../../TestResults/mandarinJitterStats.txt';
342 case 'SpeechTestFiles'
343 statsFileName = '../../../../../../../TestResults/speechJitterStats.txt';
344 end
345
346 % Add a header row
347 if( firstfileOpen == 1 )
348 statsFileID = fopen( statsFileName, 'w' );
349 fprintf( statsFileID, 'Metrics calculated using the PRAAT software. \n' );
350 fprintf( statsFileID, ' name \t JITTER: ddp \t local \t ppq5 \t rap \n');
351 firstfileOpen = 0;
352 else
353 statsFileID = fopen( statsFileName, 'a' );
354 end
355
356 get_Jitter( newDirName, statsFileID );
357 fclose( statsFileID );
358
359 case 'getShimmer'
360 % collate all Shimmer values
361 switch databaseName
362 case 'ChineseOperaTest'
363 statsFileName = '../../../../../../../TestResults/test_singingShimmerStats.txt';
364 case 'ChineseOperaFull'
365 statsFileName = '../../../../../../../TestResults/full_singingShimmerStats.txt';
366 case 'ChineseOperaPaper'
367 statsFileName = '../../../../../../../TestResults/paper_singingShimmerStats.txt';
368 case 'MandarinSpeech'
369 statsFileName = '../../../../../../../TestResults/mandarinShimmerStats.txt';
370 case 'SpeechTestFiles'
371 statsFileName = '../../../../../../../TestResults/speechShimmerStats.txt';
372 end
373
374 % Add a header row
375 if( firstfileOpen == 1 )
376 statsFileID = fopen( statsFileName, 'w' );
377 fprintf( statsFileID, 'Metrics calculated using the PRAAT software. \n' );
378 fprintf( statsFileID, ' name \t SHIMMER: local \t dda \t apq3 \t apq5 \t apq11 \n');
379 firstfileOpen = 0;
380 else
381 statsFileID = fopen( statsFileName, 'a' );
382 end
383
384 get_Shimmer( newDirName, statsFileID );
385 fclose( statsFileID );
386
387 case 'getFormants'
388 % collate all Formants values
389 switch databaseName
390 case 'ChineseOperaTest'
391 statsFileName = '../../../../../../../TestResults/test_singingFormantsStats.txt';
392 case 'ChineseOperaFull'
393 statsFileName = '../../../../../../../TestResults/full_singingFormantsStats.txt';
394 case 'ChineseOperaPaper'
395 statsFileName = '../../../../../../../TestResults/paper_singingFormantsStats.txt';
396 case 'MandarinSpeech'
397 statsFileName = '../../../../../../../TestResults/mandarinFormantsStats.txt';
398 case 'SpeechTestFiles'
399 statsFileName = '../../../../../../../TestResults/speechFormantsStats.txt';
400 end
401
402 % Add a header row
403 if( firstfileOpen == 1 )
404 statsFileID = fopen( statsFileName, 'w' );
405 fprintf( statsFileID, 'Metrics calculated using the PRAAT software. \n' );
406 fprintf( statsFileID, 'For each of the BURG FORMANTS: numberOfFormants \t meanFrequency \t varFrequency \t minFrequency \t maxFrequency \n');
407 fprintf( statsFileID, 'meanFrequencyDerivative \t varienceFrequencyDerivative \t minFrequencyDerivative \t max FrequencyDerivative \n');
408 fprintf( statsFileID, 'meanFrequency2ndDerivative \t varienceFrequency2ndDerivative \t minFrequency2ndDerivative \t max Frequency2ndDerivative \n');
409 fprintf( statsFileID, 'meanBandwidth \t varBandwidth \t minBandwidth \t maxBandwidth \n');
410 fprintf( statsFileID, 'meanBandwidthDerivative \t varBandwidthDerivative \t minBandwidthDerivative \t maxBandwidthDerivative \n');
411 fprintf( statsFileID, 'meanBandwidth2ndDerivative \t varBandwidth2ndDerivative \t minBandwidth2ndDerivative \t maxBandwidth2ndDerivative \n');
412 fprintf( statsFileID, 'For the mean of all three formants: meanFrequency \t varFrequency \t minFrequency \t maxFrequency \n');
413 fprintf( statsFileID, 'meanFrequencyDerivative \t varienceFrequencyDerivative \t minFrequencyDerivative \t max FrequencyDerivative \n');
414 fprintf( statsFileID, 'meanFrequency2ndDerivative \t varienceFrequency2ndDerivative \t minFrequency2ndDerivative \t max Frequency2ndDerivative \n');
415 firstfileOpen = 0;
416 else
417 statsFileID = fopen( statsFileName, 'a' );
418 end
419
420 get_Formants( newDirName, statsFileID );
421 fclose( statsFileID )
422
423
290 % 424 %
291 % %%%%% get all the pitch and energy related features 425 % %%%%% get all the pitch and energy related features
292 426
293 427
294 % case 'getFeaturesOfDuration' 428 % case 'getFeaturesOfDuration'
320 % 454 %
321 case 'calculatePitch' 455 case 'calculatePitch'
322 detect_pitch( currentSampleName, OVERWRITE ); 456 detect_pitch( currentSampleName, OVERWRITE );
323 457
324 case 'calculateSilence' 458 case 'calculateSilence'
325 detect_silence( currentSampleName, OVERWRITE ); 459 detect_Silence( currentSampleName, OVERWRITE );
326 460
327 case 'calculateVUV' 461 case 'calculateVUV'
328 % find the voiced and unvoiced frames using 462 % find the voiced and unvoiced frames using
329 % the harmonic ratio and pitch information 463 % the harmonic ratio and pitch information
330 detect_VoicedUnvoiced( currentSampleName, OVERWRITE ); 464 detect_VoicedUnvoiced( currentSampleName, OVERWRITE );
348 % 482 %
349 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName ); 483 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
350 % ASB_ASP_Detection( currentSampleName, x, fs, frameLength, noOfFrames ); 484 % ASB_ASP_Detection( currentSampleName, x, fs, frameLength, noOfFrames );
351 % 485 %
352 case 'calculateAudioPower' 486 case 'calculateAudioPower'
353 487 detect_AudioPower( currentSampleName, OVERWRITE );
354 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
355 detect_AudioPower( currentSampleName, x, fs, frameLength, noOfFrames );
356 % 488 %
357 % case 'calculateLogAttackTIme' 489 % case 'calculateLogAttackTIme'
358 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName ); 490 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
359 % LAT_Detection( currentSampleName, x, fs, frameLength, noOfFrames ); 491 % LAT_Detection( currentSampleName, x, fs, frameLength, noOfFrames );
360 % 492 %
376 % 508 %
377 % % these are best calculated together. 509 % % these are best calculated together.
378 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName ); 510 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
379 % spectralTimbralDescriptors( currentSampleName, x, fs, frameLength, noOfFrames ); 511 % spectralTimbralDescriptors( currentSampleName, x, fs, frameLength, noOfFrames );
380 512
381 case 'calculateAudioSpectrumFlatness' 513 % case 'calculateAudioSpectrumFlatness'
382 514 %
383 [x, fs, frameLength, noOfFrames] = openFile( currentSampleName ); 515 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
384 AudioSpectralFlatness_Detection( currentSampleName, x, fs, frameLength, noOfFrames ); 516 % AudioSpectralFlatness_Detection( currentSampleName, x, fs, frameLength, noOfFrames );
385 517
386 % case 'calculateMFCCs' 518 case 'calculateMFCCs'
387 % 519 detect_MFCC( currentSampleName, OVERWRITE );
388 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
389 % MFCC_Detection( currentSampleName, x, fs, frameLength, noOfFrames );
390 % 520 %
391 % case 'calculatesampleDependantThresholds' 521 % case 'calculatesampleDependantThresholds'
392 % 522 %
393 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName ); 523 % [x, fs, frameLength, noOfFrames] = openFile( currentSampleName );
394 % sampleDependantThresholds( currentSampleName, x, fs, frameLength, noOfFrames ); 524 % sampleDependantThresholds( currentSampleName, x, fs, frameLength, noOfFrames );