annotate 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
rev   line source
Dawn@4 1 function [] = get_Pitch( dirName, statsFileID )
Dawn@4 2
Dawn@4 3 DEBUG=0;
Dawn@4 4 % this function collates the results of all HNR values
Dawn@4 5
Dawn@4 6 % identify the speaker in the stats file
Dawn@4 7 fprintf( statsFileID, '%s ', dirName );
Dawn@4 8
Dawn@4 9 metricName = '_YIN_pitch';
Dawn@4 10 metricFileName = [ dirName metricName '.txt'];
Dawn@4 11 [ metrics, nanValues ] = readValuesFromFile( statsFileID, metricFileName, metricName );
Dawn@4 12
Dawn@4 13 %---------------- GET THE VOICED FRAME VALUES -------------------
Dawn@4 14
Dawn@4 15 % only wish to consider values from voiced frames.
Dawn@4 16
Dawn@4 17 % going to disregard all unvoiced frames as these produce outliers
Dawn@4 18 [vuv] = detect_VoicedUnvoiced( [ dirName '.wav' ], 0 );
Dawn@4 19 % if vuv is longer than the pitch array, truncate.
Dawn@4 20 if( length(vuv) ~= length(nanValues) )
Dawn@4 21 if( (length(vuv) - length(nanValues)) > 1 )
Dawn@4 22 disp('EEEK!');
Dawn@4 23 end
Dawn@4 24 if( length(vuv) > length(nanValues) )
Dawn@4 25 %increase metrics
Dawn@4 26 nanValues = [ nanValues; 0 ];
Dawn@4 27 else
Dawn@4 28 vuv = [vuv; 0];
Dawn@4 29 end
Dawn@4 30 end
Dawn@4 31
Dawn@4 32
Dawn@4 33 % remove any NaN pitch values from the voicing information
Dawn@4 34 i=1;
Dawn@4 35 while( i <= length(vuv) )
Dawn@4 36
Dawn@4 37 if( nanValues(i) == 1 )
Dawn@4 38 if( i == 1 )
Dawn@4 39 vuv = vuv(2:length(vuv));
Dawn@4 40 nanValues = nanValues(2:length(nanValues));
Dawn@4 41 elseif(i == length(vuv) )
Dawn@4 42 vuv = vuv(1:length(vuv)-1);
Dawn@4 43 nanValues = nanValues(1:length(nanValues)-1);
Dawn@4 44 else
Dawn@4 45 vuv = [ vuv(1: i-1); vuv(i+1:end) ];
Dawn@4 46 nanValues = [ nanValues(1: i-1); nanValues(i+1:end) ];
Dawn@4 47 end
Dawn@4 48 else
Dawn@4 49 i=i+1;
Dawn@4 50 end
Dawn@4 51
Dawn@4 52 end
Dawn@4 53
Dawn@4 54 % remove the non-voiced frames (includes unvoiced and silent frames) from the metrics
Dawn@4 55
Dawn@4 56 voicedFrames = find( vuv == 1 );
Dawn@4 57 metrics = metrics( voicedFrames );
Dawn@4 58
Dawn@4 59
Dawn@4 60 if(DEBUG)
Dawn@4 61 subplot(211);hold on;
Dawn@4 62 if( strfind( dirName, 'neg') )
Dawn@4 63 plot(metrics,'b');
Dawn@4 64 elseif( strfind( dirName, 'pos') )
Dawn@4 65 plot(metrics,'r');
Dawn@4 66 end
Dawn@4 67 end
Dawn@4 68
Dawn@4 69 % get basic metric set
Dawn@4 70 [ metricSet ] = basicMetricSet( metrics, statsFileID );
Dawn@4 71
Dawn@4 72 if(DEBUG)
Dawn@4 73 subplot(212);
Dawn@4 74 if( strfind( dirName, 'neg') )
Dawn@4 75 plot(metrics, 'xb'); hold on;
Dawn@4 76 elseif( strfind( dirName, 'pos') )
Dawn@4 77 plot(metrics, 'xr'); hold on;
Dawn@4 78 end
Dawn@4 79 end
Dawn@4 80
Dawn@4 81
Dawn@4 82 % get basic metric set for the first derivative
Dawn@4 83 firstDerivative = gradient( metrics );
Dawn@4 84 [ firstDerivativeMetricSet ] = basicMetricSet( firstDerivative, statsFileID );
Dawn@4 85
Dawn@4 86 % get basic metric set for the second derivative
Dawn@4 87 secondDerivative = gradient( firstDerivative );
Dawn@4 88 [ secondDerivativeMetricSet ] = basicMetricSet( secondDerivative, statsFileID );
Dawn@4 89
Dawn@4 90 fprintf( statsFileID, '\n');