Dawn@4
|
1 function [] = get_HNR( dirName, statsFileID )
|
Dawn@4
|
2
|
Dawn@4
|
3 DEBUG=1;
|
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 = '_HNR';
|
Dawn@4
|
10 metricFileName = [ dirName metricName '.txt'];
|
Dawn@4
|
11 metrics = readValuesFromFile( statsFileID, metricFileName, metricName );
|
Dawn@4
|
12
|
Dawn@4
|
13 if(DEBUG)
|
Dawn@4
|
14 subplot(211);
|
Dawn@4
|
15 if( strfind( dirName, 'neg') )
|
Dawn@4
|
16 plot(metrics, 'b'); hold on;
|
Dawn@4
|
17 elseif( strfind( dirName, 'pos') )
|
Dawn@4
|
18 plot(metrics, 'r'); hold on;
|
Dawn@4
|
19 end
|
Dawn@4
|
20 end
|
Dawn@4
|
21
|
Dawn@4
|
22 % get basic metric set
|
Dawn@4
|
23 [ basicSet ] = basicMetricSet( metrics, statsFileID );
|
Dawn@4
|
24
|
Dawn@4
|
25
|
Dawn@4
|
26 if(DEBUG)
|
Dawn@4
|
27 subplot(212);
|
Dawn@4
|
28 if( strfind( dirName, 'neg') )
|
Dawn@4
|
29 plot(basicSet, 'xb'); hold on;
|
Dawn@4
|
30 elseif( strfind( dirName, 'pos') )
|
Dawn@4
|
31 plot(basicSet, 'xr'); hold on;
|
Dawn@4
|
32 end
|
Dawn@4
|
33 end
|
Dawn@4
|
34
|
Dawn@4
|
35 % calculate the ratio of voiced (HNR > 0) to unvoiced frames (HNR <= 0)
|
Dawn@4
|
36 noOfUnvoicedFrames = length( find( metrics <= 0 ));
|
Dawn@4
|
37 noOfVoicedFrames = length( find( metrics > 0 ));
|
Dawn@4
|
38 unvoicedToVoicedRatio = ( noOfUnvoicedFrames / noOfVoicedFrames );
|
Dawn@4
|
39 fprintf( statsFileID, '\t %f ', unvoicedToVoicedRatio);
|
Dawn@4
|
40
|
Dawn@4
|
41 % calculate the average duration of the voiced and unvoiced periods
|
Dawn@4
|
42
|
Dawn@4
|
43 tsig = ( metrics > 0);
|
Dawn@4
|
44 dsig = diff([1 tsig' 1]);
|
Dawn@4
|
45 startIndex = find(dsig < 0);
|
Dawn@4
|
46 endIndex = find(dsig > 0)-1;
|
Dawn@4
|
47 unvoicedDuration = endIndex-startIndex+1;
|
Dawn@4
|
48 meanUnvoicedDuration = mean( unvoicedDuration )
|
Dawn@4
|
49 fprintf( statsFileID, '\t %f ', meanUnvoicedDuration);
|
Dawn@4
|
50
|
Dawn@4
|
51
|
Dawn@4
|
52 startIndex = find(dsig > 0);
|
Dawn@4
|
53 startIndex = startIndex(1:end-1);
|
Dawn@4
|
54 endIndex = find(dsig < 0)-1;
|
Dawn@4
|
55 endIndex = endIndex(2:end);
|
Dawn@4
|
56 voicedDuration = endIndex-startIndex+1;
|
Dawn@4
|
57 meanVoicedDuration = mean( voicedDuration )
|
Dawn@4
|
58 fprintf( statsFileID, '\t %f ', meanVoicedDuration);
|
Dawn@4
|
59
|
Dawn@4
|
60
|
Dawn@4
|
61 fprintf( statsFileID, '\n'); |