Dawn@4: function [] = get_HNR( dirName, statsFileID ) Dawn@4: Dawn@4: DEBUG=1; Dawn@4: % this function collates the results of all HNR values Dawn@4: Dawn@4: % identify the speaker in the stats file Dawn@4: fprintf( statsFileID, '%s ', dirName ); Dawn@4: Dawn@4: metricName = '_HNR'; Dawn@4: metricFileName = [ dirName metricName '.txt']; Dawn@4: metrics = readValuesFromFile( statsFileID, metricFileName, metricName ); Dawn@4: Dawn@4: if(DEBUG) Dawn@4: subplot(211); Dawn@4: if( strfind( dirName, 'neg') ) Dawn@4: plot(metrics, 'b'); hold on; Dawn@4: elseif( strfind( dirName, 'pos') ) Dawn@4: plot(metrics, 'r'); hold on; Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: % get basic metric set Dawn@4: [ basicSet ] = basicMetricSet( metrics, statsFileID ); Dawn@4: Dawn@4: Dawn@4: if(DEBUG) Dawn@4: subplot(212); Dawn@4: if( strfind( dirName, 'neg') ) Dawn@4: plot(basicSet, 'xb'); hold on; Dawn@4: elseif( strfind( dirName, 'pos') ) Dawn@4: plot(basicSet, 'xr'); hold on; Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: % calculate the ratio of voiced (HNR > 0) to unvoiced frames (HNR <= 0) Dawn@4: noOfUnvoicedFrames = length( find( metrics <= 0 )); Dawn@4: noOfVoicedFrames = length( find( metrics > 0 )); Dawn@4: unvoicedToVoicedRatio = ( noOfUnvoicedFrames / noOfVoicedFrames ); Dawn@4: fprintf( statsFileID, '\t %f ', unvoicedToVoicedRatio); Dawn@4: Dawn@4: % calculate the average duration of the voiced and unvoiced periods Dawn@4: Dawn@4: tsig = ( metrics > 0); Dawn@4: dsig = diff([1 tsig' 1]); Dawn@4: startIndex = find(dsig < 0); Dawn@4: endIndex = find(dsig > 0)-1; Dawn@4: unvoicedDuration = endIndex-startIndex+1; Dawn@4: meanUnvoicedDuration = mean( unvoicedDuration ) Dawn@4: fprintf( statsFileID, '\t %f ', meanUnvoicedDuration); Dawn@4: Dawn@4: Dawn@4: startIndex = find(dsig > 0); Dawn@4: startIndex = startIndex(1:end-1); Dawn@4: endIndex = find(dsig < 0)-1; Dawn@4: endIndex = endIndex(2:end); Dawn@4: voicedDuration = endIndex-startIndex+1; Dawn@4: meanVoicedDuration = mean( voicedDuration ) Dawn@4: fprintf( statsFileID, '\t %f ', meanVoicedDuration); Dawn@4: Dawn@4: Dawn@4: fprintf( statsFileID, '\n');