Dawn@4: function [] = kmeans_MFCC_Singing( inputFileName, outputFileName ) Dawn@4: Dawn@4: cd 'C:\Users\dawn\Dropbox\TestResults' Dawn@4: inputFileName Dawn@4: Dawn@4: DEBUG = 1; Dawn@4: % output results file name Dawn@4: masterFileOutputID = fopen( outputFileName, 'a' ); %fopen( 'kmeans_Singing_MFCC.txt', 'a' ); Dawn@4: % % input results file name Dawn@4: % inputFileName = 'singingMFCCStats_VoicedAndUnvoiced.txt'; Dawn@4: Dawn@4: fprintf( masterFileOutputID, '\n RESULTS FILE NAME: %s\n', inputFileName); Dawn@4: inputFileID = fopen( inputFileName ); Dawn@4: Dawn@4: % noOfArguments = length(varargin); Dawn@4: % Dawn@4: % outputFileName = 'individualResults/kmeans_Results_'; Dawn@4: % resultsFileName = 'kmeans_Results_'; Dawn@4: titleName = ''; Dawn@4: % for i=1 : noOfArguments Dawn@4: % titleName = [ titleName varargin{i} '_']; Dawn@4: % fprintf( masterFileOutputID, '%s_', varargin{i} ); Dawn@4: % end Dawn@4: % Dawn@4: % outputFileName = [ outputFileName titleName ]; Dawn@4: % resultsFileName = [ resultsFileName titleName ]; Dawn@4: Dawn@4: fprintf( masterFileOutputID, '\t' ); Dawn@4: Dawn@4: % outputFileName = [ outputFileName '.txt']; Dawn@4: % resultsFileName = [ resultsFileName '.txt']; Dawn@4: Dawn@4: % fileOutputID = fopen( outputFileName, 'w' ); Dawn@4: % fileKMeansOutputID = fopen( resultsFileName, 'w' ); Dawn@4: Dawn@4: % -------------------- get the data from the results file --------------- Dawn@4: lineCount = 0; Dawn@4: fileCount = 0; Dawn@4: data = []; Dawn@4: while( ~(feof(inputFileID)) ) Dawn@4: Dawn@4: outputValues = []; Dawn@4: thestr = fgetl(inputFileID); Dawn@4: fileCount = fileCount + 1; Dawn@4: Dawn@4: % determine whether we have a positive or negative sample Dawn@4: sampleEmotion( fileCount ) = 'U'; Dawn@4: if( ~(isempty(strfind(thestr,'pos')))) Dawn@4: % sample is positive Dawn@4: sampleEmotion( fileCount ) = 'P'; Dawn@4: elseif( ~(isempty(strfind(thestr,'neg')))) Dawn@4: % sample is negative Dawn@4: sampleEmotion( fileCount ) = 'N'; Dawn@4: else Dawn@4: disp('EEEK!'); Dawn@4: pause; Dawn@4: end Dawn@4: Dawn@4: % determine whether we have a male, female or trans sample Dawn@4: gender( fileCount ) = '?'; Dawn@4: if( ~(isempty(strfind(thestr,'fem')))) Dawn@4: % gender is female Dawn@4: gender( fileCount ) = 'F'; Dawn@4: elseif( ~(isempty(strfind(thestr,'male')))) Dawn@4: % gender is male Dawn@4: gender( fileCount ) = 'M'; Dawn@4: elseif( ~(isempty(strfind(thestr,'trans')))) Dawn@4: % gender is trans Dawn@4: gender( fileCount ) = 'T'; Dawn@4: else Dawn@4: disp('EEEK!'); Dawn@4: pause; Dawn@4: end Dawn@4: Dawn@4: %how many values are in the string? Dawn@4: spaces = strfind( thestr, ' ' ); Dawn@4: numberstr = thestr( spaces(1) : end ); % chop off the file name Dawn@4: vars = sscanf( numberstr, '%f', inf ); Dawn@4: data( fileCount, : ) = vars; Dawn@4: Dawn@4: lineCount = lineCount + 1; Dawn@4: Dawn@4: end Dawn@4: fclose(inputFileID); Dawn@4: Dawn@4: % try with and without different metrics classes Dawn@4: % data is a 162 variable array of MFCC stats Dawn@4: % first there are 6 metrics for each of the 13 frequency bands (mean, median, var, min, max, range) Dawn@4: % then there are 6 metrics for the 1st derivative of the 13 frequency bands (mean, median, var, min, max, range) Dawn@4: % then there are 6 metrics for the mean of all frequency bands Dawn@4: Dawn@4: % dataOptions = (1:1:(13*12)+6); % fprintf( masterFileOutputID, '\n try with all \n'); Dawn@4: % dataOptions = (1:1:13*6); fprintf( masterFileOutputID, '\n try with just the ordinary 13 frequency bands \n'); Dawn@4: % dataOptions = (1:1:13*6); fprintf( masterFileOutputID, '\n try with just the ordinary 13 frequency bands and without the median or range \n'); Dawn@4: Dawn@4: % ------------ apply the k-means classifier ------------------------ Dawn@4: Dawn@4: noOfClusters = 2; % we are only trying to identify positive and negative emotions Dawn@4: Dawn@4: Dawn@4: [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,... Dawn@4: 'start', 'sample', 'Distance', 'cityblock'); Dawn@4: Dawn@4: %display results grouped by emotion Dawn@4: fprintf( masterFileOutputID, '\n Emotion grouping \n'); Dawn@4: fprintf( masterFileOutputID, 'cityblock \n'); Dawn@4: [ groupStats, groupNames ] = processKMeansResults( 'cityblock', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG ); Dawn@4: [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID ); Dawn@4: % if(DEBUG == 1) Dawn@4: % disp('press space'); Dawn@4: % pause; Dawn@4: % end Dawn@4: Dawn@4: fprintf( masterFileOutputID, 'sqEuclidean \n'); Dawn@4: [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,... Dawn@4: 'start', 'sample', 'Distance', 'sqEuclidean'); Dawn@4: Dawn@4: [ groupStats, groupNames ] = processKMeansResults( 'sqEuclidean', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG ); Dawn@4: [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID ); Dawn@4: Dawn@4: % if(DEBUG == 1) Dawn@4: % disp('press space'); Dawn@4: % pause; Dawn@4: % end Dawn@4: Dawn@4: % display results grouped by gender Dawn@4: fprintf( masterFileOutputID, '\n Gender grouping \n'); Dawn@4: noOfClusters = 3; Dawn@4: Dawn@4: [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,... Dawn@4: 'start', 'sample', 'Distance', 'cityblock'); Dawn@4: Dawn@4: fprintf( masterFileOutputID, 'cityblock \n'); Dawn@4: [ groupStats, groupNames ] = processKMeansResults( 'cityblock', idx, gender, masterFileOutputID, titleName, DEBUG ); Dawn@4: [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID ); Dawn@4: Dawn@4: [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,... Dawn@4: 'start', 'sample', 'Distance', 'sqEuclidean'); Dawn@4: Dawn@4: fprintf( masterFileOutputID, 'sqEuclidean \n'); Dawn@4: [ groupStats, groupNames ] = processKMeansResults( 'sqEuclidean', idx, gender, masterFileOutputID, titleName, DEBUG ); Dawn@4: [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID ); Dawn@4: Dawn@4: Dawn@4: % fprintf( fileOutputID, '\n' ); Dawn@4: % fclose( fileOutputID ); Dawn@4: % fprintf( fileKMeansOutputID, '\n' ); Dawn@4: % fclose( fileKMeansOutputID ); Dawn@4: fprintf( masterFileOutputID, '\n' ); Dawn@4: fclose( masterFileOutputID ); Dawn@4: Dawn@4: end Dawn@4: Dawn@4: