diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Code/Classifiers/SVM_Formants_Singing.m	Wed Feb 13 11:02:39 2013 +0000
@@ -0,0 +1,540 @@
+function [] = SVM_Formants_Singing( varargin )
+
+cd 'C:\Users\dawn\Dropbox\TestResults'
+
+DEBUG = 0;
+% output results file name
+masterFileOutputID = fopen( 'SVM_paper_SingingFormantsStats.txt', 'a' );
+% input results file name
+inputFileName = 'paper_singingFormantsStats.txt';
+
+% This function allows the user to stipulate which Singing voice LLD's they
+% wish to forward to a k-means classifier and produces a file of
+% performance characteristics. Input arguments stipulate the LLD's and
+% there is a choice of:-
+%
+% ---- PRAAT FORMANT MEASUREMENTS ----
+%     '_Formant_Burg'
+%     '_Formant_all'
+%     '_Formant_robust'
+%
+% A text file entitled kmeans_Singing_LLD1name_LLD2name_ ... LLDNname.txt
+% is produced that contains the results of the k-mean classification for
+% the LLD's specified and named in the result document title.
+
+fprintf( masterFileOutputID, '\n RESULTS FILE NAME: %s\n', inputFileName);
+inputFileID = fopen( inputFileName );
+
+% get the column numbers of the results that we want to classify
+
+% COLUMN NUMBER     :   METRIC
+%
+% ------------- BURG FORMANTS ---------------
+%   11   : Number of BURG formants listed = nBF
+%
+%   THERE ARE CURRENTLY 24 MEASUREMENTS TAKEN FOR EACH FORMANT
+nMetrics = 24;
+%
+%   12   : mean frequency of the first BURG formant
+%   13   : variance of the first BURG formant
+%   14   : minimum frequency of the first BURG formant
+%   15   : maximum frequency of the first BURG formant
+%   16   : mean Frequency Derivative of the first BURG formant
+%   17   : varience of the Frequency Derivative of the first BURG formant
+%   18   : min of the Frequency Derivative of the first BURG formant
+%   19   : max  of the Frequency Derivative of the first BURG formant
+%   20   : mean of the Frequency 2nd Derivative of the first BURG formant
+%   21   : varience of the Frequency 2nd Derivative of the first BURG formant
+%   22   : min of the Frequency 2nd Derivative of the first BURG formant
+%   23   :  max of the Frequency 2nd Derivative of the first BURG formant
+%   24   : mean of the Bandwidth of the first BURG formant
+%   25   :  varience of the Bandwidth of the first BURG formant
+%   26   : min of the Bandwidth of the first BURG formant
+%   27   : max of the Bandwidth of the first BURG formant
+%   28   : mean of the Bandwidth Derivative of the first BURG formant
+%   29   : varience of the Bandwidth Derivative of the first BURG formant
+%   30   : min of the Bandwidth Derivative of the first BURG formant
+%   31   : max of the Bandwidth Derivative of the first BURG formant
+%   32   : mean of the Bandwidth 2nd Derivative of the first BURG formant
+%   33   : var of the Bandwidth 2nd Derivative of the first BURG formant
+%   34   : min of the Bandwidth 2nd Derivative of the first BURG formant
+%   35   : max of the Bandwidth 2nd Derivative of the first BURG formant
+%
+%    ....... there are nMetrics for each formant in nBF formants, so cycle
+%    through until the last is reached ......
+%
+%   36 + ((nBF-1)*nMetrics)       : mean frequency of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 1   : variance of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 2   : minimum frequency of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 3   : maximum frequency of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 4   : mean Frequency Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 5   : varience of the Frequency Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 6   : min of the Frequency Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 7   : max of the Frequency Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 8   : mean of the Frequency 2nd Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 9   : varience of the Frequency 2nd Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 10  : min of the Frequency 2nd Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 11  : max of the Frequency 2nd Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 12  : mean of the Bandwidth of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 13  : varience of the Bandwidth of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 14  : min of the Bandwidth of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 15  : max of the Bandwidth of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 16  : mean of the Bandwidth Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 17  : variece of the Bandwidth Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 18  : min of the Bandwidth Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 19  : max of the Bandwidth Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 20  : mean of the Bandwidth 2nd Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 21  : var of the Bandwidth 2nd Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 22  : min of the Bandwidth 2nd Derivative of the nBF BURG formant
+%   36 + ((nBF-1)*nMetrics) + 23  : max of the Bandwidth 2nd Derivative of the nBF BURG formant
+%
+%   FOR THE MEAN OF ALL BURG FORMANTS
+%   36 + (nBF*nMetrics)           : mean of all formants Frequency 
+%   36 + (nBF*nMetrics) + 1       : varience of the mean of all formants Frequency 
+%   36 + (nBF*nMetrics) + 2       : minimum of the mean of all formants Frequency 
+%   36 + (nBF*nMetrics) + 3       : maximum of the mean of all formants Frequency
+%   36 + (nBF*nMetrics) + 4       :  mean of all formants mean Frequency Derivative 
+%   36 + (nBF*nMetrics) + 5       :  mean of all formants varience Frequency Derivative 
+%   36 + (nBF*nMetrics) + 6       :  min of the mean of all formants Frequency Derivative
+%   36 + (nBF*nMetrics) + 7       :  max of the mean of all formants Frequency Derivative 
+%   36 + (nBF*nMetrics) + 8       :  mean of the mean of all formants Frequency 2nd Derivative 
+%   36 + (nBF*nMetrics) + 9       :  varience of the mean of all formants Frequency 2nd Derivative 
+%   36 + (nBF*nMetrics) + 10      :  min of the mean of all formants Frequency 2nd Derivative
+%   36 + (nBF*nMetrics) + 11      :  max of the mean of all formants Frequency 2nd Derivative
+%
+% ------------- ALL FORMANTS ---------------
+%
+%   36 + (nBF*nMetrics) + 12   : Number of ALL formants listed = nAF
+%
+%   startOfALLMeasurements = 36 + (nBF*nMetrics) + 13;
+%
+%   startOfALLMeasurements      : mean frequency of the first ALL formant
+%   startOfALLMeasurements + 1     : variance of the first ALL formant
+%   startOfALLMeasurements + 2     : minimum frequency of the first ALL formant
+%   startOfALLMeasurements + 3     : maximum frequency of the first ALL formant
+%   startOfALLMeasurements + 4     : mean Frequency Derivative of the first ALL formant
+%   startOfALLMeasurements + 5     : varience of the Frequency Derivative of the first ALL formant
+%   startOfALLMeasurements + 6     : min of the Frequency Derivative of the first ALL formant
+%   startOfALLMeasurements + 7     : max  of the Frequency Derivative of the first ALL formant
+%   startOfALLMeasurements + 8     : mean of the Frequency 2nd Derivative of the first ALL formant
+%   startOfALLMeasurements + 9     : varience of the Frequency 2nd Derivative of the first ALL formant
+%   startOfALLMeasurements + 10    : min of the Frequency 2nd Derivative of the first ALL formant
+%   startOfALLMeasurements + 11    :  max of the Frequency 2nd Derivative of the first ALL formant
+%   startOfALLMeasurements + 12    : mean of the Bandwidth of the first ALL formant
+%   startOfALLMeasurements + 13    :  varience of the Bandwidth of the first ALL formant
+%   startOfALLMeasurements + 14    : min of the Bandwidth of the first ALL formant
+%   startOfALLMeasurements + 15    : max of the Bandwidth of the first ALL formant
+%   startOfALLMeasurements + 16    : mean of the Bandwidth Derivative of the first ALL formant
+%   startOfALLMeasurements + 17    : varience of the Bandwidth Derivative of the first ALL formant
+%   startOfALLMeasurements + 18    : min of the Bandwidth Derivative of the first ALL formant
+%   startOfALLMeasurements + 19    : max of the Bandwidth Derivative of the first ALL formant
+%   startOfALLMeasurements + 20    : mean of the Bandwidth 2nd Derivative of the first ALL formant
+%   startOfALLMeasurements + 21    : var of the Bandwidth 2nd Derivative of the first ALL formant
+%   startOfALLMeasurements + 22    : min of the Bandwidth 2nd Derivative of the first ALL formant
+%   startOfALLMeasurements + 23    : max of the Bandwidth 2nd Derivative of the first ALL formant
+%
+%    ....... there are nMetrics for each formant in nAF formants, so cycle
+%    through until the last is reached ......
+%
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : mean frequency of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : variance of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : minimum frequency of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : maximum frequency of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : mean Frequency Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : varience of the Frequency Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : min of the Frequency Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : max of the Frequency Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : mean of the Frequency 2nd Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : varience of the Frequency 2nd Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : min of the Frequency 2nd Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : max of the Frequency 2nd Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : mean of the Bandwidth of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : varience of the Bandwidth of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : min of the Bandwidth of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : max of the Bandwidth of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : mean of the Bandwidth Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : variece of the Bandwidth Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : min of the Bandwidth Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : max of the Bandwidth Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : mean of the Bandwidth 2nd Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : var of the Bandwidth 2nd Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : min of the Bandwidth 2nd Derivative of the nAF ALL formant
+%   startOfALLMeasurements + ((nAF-1)*nMetrics)       : max of the Bandwidth 2nd Derivative of the nAF ALL formant
+%
+%   FOR THE MEAN OF ALL ALL FORMANTS
+%   startOfALLMeasurements + (nAF*nMetrics)           : mean of all formants Frequency 
+%   startOfALLMeasurements + (nAF*nMetrics) + 1       : varience of the mean of all formants Frequency 
+%   startOfALLMeasurements + (nAF*nMetrics) + 2       : minimum of the mean of all formants Frequency 
+%   startOfALLMeasurements + (nAF*nMetrics) + 3       : maximum of the mean of all formants Frequency
+%   startOfALLMeasurements + (nAF*nMetrics) + 4       :  mean of all formants mean Frequency Derivative 
+%   startOfALLMeasurements + (nAF*nMetrics) + 5       :  mean of all formants varience Frequency Derivative 
+%   startOfALLMeasurements + (nAF*nMetrics) + 6       :  min of the mean of all formants Frequency Derivative
+%   startOfALLMeasurements + (nAF*nMetrics) + 7       :  max of the mean of all formants Frequency Derivative 
+%   startOfALLMeasurements + (nAF*nMetrics) + 8       :  mean of the mean of all formants Frequency 2nd Derivative 
+%   startOfALLMeasurements + (nAF*nMetrics) + 9       :  varience of the mean of all formants Frequency 2nd Derivative 
+%   startOfALLMeasurements + (nAF*nMetrics) + 10      :  min of the mean of all formants Frequency 2nd Derivative
+%   startOfALLMeasurements + (nAF*nMetrics) + 11      :  max of the mean of all formants Frequency 2nd Derivative
+%
+% ------------- ROBUST FORMANTS ---------------
+%
+%   startOfALLMeasurements + (nAF*nMetrics) + 12    : Number of ROBUST formants listed = nRF
+%
+%   startOfROBUSTMeasurements = startOfALLMeasurements + (nAF*nMetrics) + 13;
+%
+%   startOfROBUSTMeasurements         : mean frequency of the first ROBUST formant
+%   startOfROBUSTMeasurements + 1     : variance of the first ROBUST formant
+%   startOfROBUSTMeasurements + 2     : minimum frequency of the first ROBUST formant
+%   startOfROBUSTMeasurements + 3     : maximum frequency of the first ROBUST formant
+%   startOfROBUSTMeasurements + 4     : mean Frequency Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 5     : varience of the Frequency Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 6     : min of the Frequency Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 7     : max  of the Frequency Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 8     : mean of the Frequency 2nd Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 9     : varience of the Frequency 2nd Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 10    : min of the Frequency 2nd Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 11    :  max of the Frequency 2nd Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 12    : mean of the Bandwidth of the first ROBUST formant
+%   startOfROBUSTMeasurements + 13    :  varience of the Bandwidth of the first ROBUST formant
+%   startOfROBUSTMeasurements + 14    : min of the Bandwidth of the first ROBUST formant
+%   startOfROBUSTMeasurements + 15    : max of the Bandwidth of the first ROBUST formant
+%   startOfROBUSTMeasurements + 16    : mean of the Bandwidth Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 17    : varience of the Bandwidth Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 18    : min of the Bandwidth Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 19    : max of the Bandwidth Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 20    : mean of the Bandwidth 2nd Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 21    : var of the Bandwidth 2nd Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 22    : min of the Bandwidth 2nd Derivative of the first ROBUST formant
+%   startOfROBUSTMeasurements + 23    : max of the Bandwidth 2nd Derivative of the first ROBUST formant
+%
+%    ....... there are nMetrics for each formant in nRF formants, so cycle
+%    through until the last is reached ......
+%
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : mean frequency of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : variance of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : minimum frequency of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : maximum frequency of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : mean Frequency Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : varience of the Frequency Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : min of the Frequency Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : max of the Frequency Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : mean of the Frequency 2nd Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : varience of the Frequency 2nd Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : min of the Frequency 2nd Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : max of the Frequency 2nd Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : mean of the Bandwidth of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : varience of the Bandwidth of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : min of the Bandwidth of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : max of the Bandwidth of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : mean of the Bandwidth Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : variece of the Bandwidth Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : min of the Bandwidth Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : max of the Bandwidth Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : mean of the Bandwidth 2nd Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : var of the Bandwidth 2nd Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : min of the Bandwidth 2nd Derivative of the nRF ROBUST formant
+%   startOfROBUSTMeasurements + ((nRF-1)*nMetrics)       : max of the Bandwidth 2nd Derivative of the nRF ROBUST formant
+%
+%   FOR THE MEAN OF ALL ROBUST FORMANTS
+%   startOfROBUSTMeasurements + (nRF*nMetrics)           : mean of all formants Frequency 
+%   startOfROBUSTMeasurements + (nRF*nMetrics) + 1       : varience of the mean of all formants Frequency 
+%   startOfROBUSTMeasurements + (nRF*nMetrics) + 2       : minimum of the mean of all formants Frequency 
+%   startOfROBUSTMeasurements + (nRF*nMetrics) + 3       : maximum of the mean of all formants Frequency
+%   startOfROBUSTMeasurements + (nRF*nMetrics) + 4       :  mean of all formants mean Frequency Derivative 
+%   startOfROBUSTMeasurements + (nRF*nMetrics) + 5       :  mean of all formants varience Frequency Derivative 
+%   startOfROBUSTMeasurements + (nRF*nMetrics) + 6       :  min of the mean of all formants Frequency Derivative
+%   startOfROBUSTMeasurements + (nRF*nMetrics) + 7       :  max of the mean of all formants Frequency Derivative 
+%   startOfROBUSTMeasurements + (nRF*nMetrics) + 8       :  mean of the mean of all formants Frequency 2nd Derivative 
+%   startOfROBUSTMeasurements + (nRF*nMetrics) + 9       :  varience of the mean of all formants Frequency 2nd Derivative 
+%   startOfROBUSTMeasurements + (nRF*nMetrics) + 10      :  min of the mean of all formants Frequency 2nd Derivative
+%   startOfROBUSTMeasurements + (nRF*nMetrics) + 11      :  max of the mean of all formants Frequency 2nd Derivative
+%
+
+noOfArguments = length(varargin);
+columnIndices = [];
+
+getBURGFormants = 0;
+getAllFormants=0;
+getRobustFormants=0;
+
+for i=1 : noOfArguments
+    if( strcmp( varargin{i}, 'formant_Burg' ))
+        getBURGFormants = 1;
+    elseif( strcmp( varargin{i}, 'formant_all' ))
+        getAllFormants=1;
+    elseif( strcmp( varargin{i}, 'formant_robust' ))
+        getRobustFormants=1;
+    end
+end
+
+titleName = '';
+for i=1 : noOfArguments
+    titleName = [ titleName varargin{i} '_'];
+    fprintf( masterFileOutputID, '%s_', varargin{i} );
+end
+
+fprintf( masterFileOutputID, '\t' );
+
+% -------------------- get the data from the results file ---------------
+lineCount = 0;
+fileCount = 0;
+data = [];
+groups = [];
+
+while( ~(feof(inputFileID)) )
+    
+    outputValues = [];
+
+    thestr = fgetl(inputFileID);
+    if( lineCount > 10 )    % skip the file header
+        fileCount = fileCount + 1;
+        
+        % determine whether we have a positive or negative sample
+        sampleEmotion( fileCount ) = 'U';
+        if( ~(isempty(strfind(thestr,'pos'))))
+            % sample is positive
+            sampleEmotion( fileCount ) = 'P';
+            groups( fileCount ) = 1;
+        elseif( ~(isempty(strfind(thestr,'neg'))))
+            % sample is negative
+            sampleEmotion( fileCount ) = 'N';
+            groups( fileCount ) = 0;
+        else
+            disp('EEEK!');
+            pause;
+        end
+        
+%         % determine whether we have a male, female or trans sample
+%         gender( fileCount ) = '?';
+%         if( ~(isempty(strfind(thestr,'fem'))))
+%             % gender is female
+%             gender( fileCount ) = 'F';
+%         elseif( ~(isempty(strfind(thestr,'male'))))
+%             % gender is male
+%             gender( fileCount ) = 'M';
+%         elseif( ~(isempty(strfind(thestr,'trans'))))
+%             % gender is trans
+%             gender( fileCount ) = 'T';
+%         else
+%             disp('EEEK!');
+%             pause;
+%         end
+
+        %how many values are in the string?
+        spaces = strfind( thestr, ' ' );
+        numberstr = thestr( spaces(1) : end ); % chop off the file name
+        frmtpos = strfind( numberstr, 'maxNoOfFormants'); % find the position of the label for number of formants
+        
+%         str1 = numberstr( 1 : frmtpos(1)-1 ); % string contains jitter and shimmer values
+        str2 = numberstr( frmtpos(1) : frmtpos(2)-1 ); % string contains all BURG formant information
+        str3 = numberstr( frmtpos(2) : frmtpos(3)-1 ); % string contains all ALL formant information
+        str4 = numberstr( frmtpos(3) : end ); % string contains all ROBUST formant information
+        
+        
+%         vars = sscanf( str1, '%f', inf );
+%         % extract the shimmer and jitter values
+%         outputValues = [ outputValues vars( columnIndices )'];
+        
+        if( getBURGFormants )
+            spaces = strfind( str2, ' ' ); % remove the string 'maxNoOfFormants'
+            vars = sscanf( str2( spaces(1) : end ), '%f', inf );
+            outputValues = stripOutFormantValues( vars, outputValues );
+        end
+        
+        if( getAllFormants )
+            spaces = strfind( str3, ' ' ); % remove the string 'maxNoOfFormants'
+            vars = sscanf( str3( spaces(1) : end ), '%f', inf );
+            outputValues = stripOutFormantValues( vars, outputValues );
+        end
+        
+        if( getRobustFormants )
+            spaces = strfind( str4, ' ' ); % remove the string 'maxNoOfFormants'
+            vars = sscanf( str4( spaces(1) : end ), '%f', inf );
+            outputValues = stripOutFormantValues( vars, outputValues );
+        end
+        
+        [m n] = size( data );
+        % sometimes the 'all' formants command gives us fewer formants than
+        % usual. If this is the case,then we will have to pad with zeros
+        % for now.
+        if( n > length( outputValues ) )
+            lenDiff = n - length( outputValues );
+            outputValues = [ outputValues zeros( 1, lenDiff ) ];
+        elseif( n < length( outputValues ) )
+            lenDiff = length( outputValues ) - n;
+            outputValues = [ outputValues zeros( 1, lenDiff ) ];
+        end
+        
+        data( fileCount, : ) = outputValues;
+        
+    end
+    lineCount = lineCount + 1;
+    
+end
+fclose(inputFileID);
+
+
+
+% ------------  apply the SVM classifier  ------------------------
+
+resultMatrix = [];
+
+noOfIterations = 10;
+
+for n = 1:noOfIterations
+    % Randomly select training and test sets, perhaps we should try all and
+    % choose the best?
+    [train, test] = crossvalind('holdOut',groups);
+    cp = classperf(groups);
+    
+    % Use a linear support vector machine classifier
+    svmStruct = svmtrain(data(train,:),groups(train));
+    classes = svmclassify(svmStruct,data(test,:));
+    % See how well the classifier performed
+    classperf(cp,classes,test);
+    numbers = cp.CountingMatrix;
+
+    resultMatrix (n,:,:) = cp.DiagnosticTable;
+%     
+end
+
+
+
+
+% for emotion detection give the confusion matrix as 
+    % -----------------------------------------------------------------
+    % positive correctly identified         | positive incorrectly identified (1,2)
+    % negative incorrectly identified (2,1) | negative correctly identified
+    % ------------------------------------------------------------------
+    
+% takes the average of 10 iterations - do we want to take the best?  
+
+meanResults(1,1) = mean( resultMatrix(:,1,1) );
+meanResults(1,2) = mean( resultMatrix(:,2,1) );
+meanResults(2,1) = mean( resultMatrix(:,1,2) );
+meanResults(2,2) = mean( resultMatrix(:,2,2) );
+
+meanResults(3,:)=0;
+meanResults(:,3)=0;
+
+meanResults(3,3) = (meanResults(1,1) + meanResults(2,2));% / sum(sum(meanResults));
+
+% convert to percentages
+% how many of each sample do we have?
+groupNumbers = unique( groups( test ));
+groupNames = unique( sampleEmotion( test ));
+sampleEmotionTest = sampleEmotion( test );
+% which group is which emotion?
+thisGroupNumber = groupNumbers(1);
+thisGroup = find( groups( test ) == thisGroupNumber );
+thisGroupName = unique( sampleEmotionTest( thisGroup ));
+
+thatGroupNumber = groupNumbers(2);
+thatGroup = find( groups( test ) == thatGroupNumber );
+thatGroupName = unique( sampleEmotionTest( thatGroup ));
+
+if(length( thisGroupName ) ~= 1 )
+    disp('ARGH!');
+    pause;
+end
+
+thisGroupNumberOfSamples = length( thisGroup );
+thatGroupNumberOfSamples = length( thatGroup );
+
+if( thisGroupName == 'P' )
+    %swap all the variables ready for checking
+    temp = thisGroupNumberOfSamples;
+    thisGroupNumberOfSamples = thatGroupNumberOfSamples;
+    thatGroupNumberOfSamples = temp;
+    
+    temp = thisGroupName;
+    thisGroupName = thatGroupName
+    thatGroupName = temp;
+    disp('CHECK ME!');
+end
+
+if( thisGroupName == 'N' )
+     % group 0 is negative
+    if( sum( meanResults(1,:) ) == thisGroupNumberOfSamples )
+        %if the elements in the first row add up to the number of negative
+        %samples, then swap the rows because we want the top row to be the
+        %results for the positive samples
+        temp(:,1) = meanResults(1:2,2);
+        temp(:,2) = meanResults(1:2,1);
+        temp2(1,:) = temp(2,:);
+        temp2(2,:) = temp(1,:);
+        
+        meanResults(1:2,1) = temp2(:,1);
+        meanResults(1:2,2) = temp2(:,2);
+
+        % check the number of positive samples
+        if(( sum( meanResults(1,:) ) == thatGroupNumberOfSamples ) ...
+            && ( thatGroupName == 'P' ) )
+            % row 1 is positive
+            disp('matrix correct');
+        else
+            disp('ARGH!');
+            pause;
+        end
+
+    elseif( sum( meanResults(2,:) ) == thisGroupNumberOfSamples  )
+
+        % the elements in the second row add up to the number of negative
+        % samples, so the matrix is the correct way around
+
+        % check the number of positive samples
+        if(( sum( meanResults(1,:) ) == thatGroupNumberOfSamples ) ...
+            && ( thatGroupName == 'P' ) )
+            % row 0 is positive
+            disp('matrix correct');
+        else
+            disp('ARGH!');
+            pause;
+        end
+    end
+end
+
+% calculate the percentages
+numberOfSamples = sum(sum( meanResults(1:2,1:2)));
+percentageResults = meanResults;
+percentageResults(1,1) = meanResults(1,1) / numberOfSamples;
+percentageResults(1,2) = meanResults(1,2) / numberOfSamples;
+percentageResults(2,1) = meanResults(2,1) / numberOfSamples;
+percentageResults(2,2) = meanResults(2,2) / numberOfSamples;
+percentageResults(3,3) = meanResults(3,3) / numberOfSamples;
+
+percentageResults = percentageResults * 100
+
+confusionMatrix = percentageResults;
+ 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));
+
+ % print latex results to the screen
+str1 = sprintf(' & %2.2f & %2.2f &  \\\\', percentageResults(1,1), percentageResults(1,2) );
+disp(str1);
+str1 = sprintf(' & %2.2f & %2.2f &  \\\\', percentageResults(2,1), percentageResults(2,2) );
+disp(str1);
+str1 = sprintf(' & & & %2.2f \\\\',percentageResults(3,3) );
+disp(str1);
+
+fprintf( masterFileOutputID, '\n' );
+fclose( masterFileOutputID );
+
+end
+
+%------------------------------------------------------------------
+
+function [ outputValues ] = stripOutFormantValues( vars, outputValues )
+    
+    noOfFormantValues = length( vars ) - 1; % gives the number of formant arguments only
+    noOfFormants = vars(1);
+    % there are 12 measurements for the mean of all formants (so the number
+    % of formants is not important) for each formant measurement.
+    if( noOfFormants ~= (noOfFormantValues-12)/24 )
+        disp('EEK!');
+        pause;
+    else
+        outputValues = [ outputValues vars( 2:end )' ];
+    end
+
+end
+
+%-------------------------------------------------------------------