diff Code/Collation/get_Pitch.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/Collation/get_Pitch.m	Wed Feb 13 11:02:39 2013 +0000
@@ -0,0 +1,90 @@
+function [] = get_Pitch( dirName, statsFileID )
+
+DEBUG=0;
+% this function collates the results of all HNR values
+
+% identify the speaker in the stats file
+fprintf( statsFileID, '%s ', dirName );
+
+metricName = '_YIN_pitch';
+metricFileName = [ dirName metricName '.txt'];
+[ metrics, nanValues ] = readValuesFromFile( statsFileID, metricFileName, metricName );
+
+%---------------- GET THE VOICED FRAME VALUES -------------------
+
+% only wish to consider values from voiced frames.
+
+% going to disregard all unvoiced frames as these produce outliers
+[vuv] = detect_VoicedUnvoiced( [ dirName '.wav' ], 0 );
+% if vuv is longer than the pitch array, truncate.
+if( length(vuv) ~= length(nanValues) )
+    if( (length(vuv) - length(nanValues)) > 1 )
+        disp('EEEK!');
+    end
+    if( length(vuv) > length(nanValues) )
+        %increase metrics
+        nanValues = [ nanValues; 0 ];
+    else
+        vuv = [vuv; 0];
+    end
+end
+
+
+% remove any NaN pitch values from the voicing information
+i=1;
+while( i <= length(vuv) )
+
+    if( nanValues(i) == 1 )
+        if( i == 1 )
+            vuv = vuv(2:length(vuv));
+            nanValues = nanValues(2:length(nanValues));
+        elseif(i == length(vuv) )
+            vuv = vuv(1:length(vuv)-1);
+            nanValues = nanValues(1:length(nanValues)-1);
+        else
+            vuv = [ vuv(1: i-1); vuv(i+1:end) ];
+            nanValues = [ nanValues(1: i-1); nanValues(i+1:end) ];
+        end
+    else
+        i=i+1;
+    end
+    
+end
+    
+% remove the non-voiced frames (includes unvoiced and silent frames) from the metrics
+
+voicedFrames = find( vuv == 1 );
+metrics = metrics( voicedFrames );
+
+
+if(DEBUG)
+    subplot(211);hold on;
+    if( strfind( dirName, 'neg') ) 
+        plot(metrics,'b');
+    elseif( strfind( dirName, 'pos') ) 
+        plot(metrics,'r');
+    end
+end
+
+% get basic metric set
+[ metricSet ] = basicMetricSet( metrics, statsFileID );
+
+if(DEBUG)
+    subplot(212); 
+    if( strfind( dirName, 'neg') )
+        plot(metrics, 'xb'); hold on;
+    elseif( strfind( dirName, 'pos') )
+        plot(metrics, 'xr'); hold on;
+    end
+end
+
+
+% get basic metric set for the first derivative
+firstDerivative = gradient( metrics );
+[ firstDerivativeMetricSet ] = basicMetricSet( firstDerivative, statsFileID );
+
+% get basic metric set for the second derivative
+secondDerivative = gradient( firstDerivative );
+[ secondDerivativeMetricSet ] = basicMetricSet( secondDerivative, statsFileID );
+
+fprintf( statsFileID, '\n');
\ No newline at end of file