comparison Code/Descriptors/Matlab/MPEG7/detect_HNR.m @ 4:92ca03a8fa99 tip

Update to ICASSP 2013 benchmark
author Dawn Black
date Wed, 13 Feb 2013 11:02:39 +0000
parents
children
comparison
equal deleted inserted replaced
3:e1cfa7765647 4:92ca03a8fa99
1 function [HNR] = detect_HNR( sampleWavFileName, OVERWRITE )
2
3 sampleFileName = sampleWavFileName( 1 : length( sampleWavFileName ) - 4 );
4 [x, fs, frameLength, noOfFrames] = openFile( sampleWavFileName );
5
6 %---------------- GET THE SILENT FRAME VALUES -------------------
7
8 % only wish to consider pitch values from voiced frames.
9 % silent and unvoiced frames will produce pitch values that
10 % are random and therefore will bias our results
11
12 segmentFrames = detect_Silence( sampleWavFileName, 0 );
13 [ silentFrames ] = getSilentDataArray( segmentFrames, noOfFrames );
14
15
16 %---------------- GET THE PITCH VALUES --------------------------
17
18 [ pitch ] = detect_pitch( sampleWavFileName, 0 );
19
20 % calculate the HNR
21
22 % open original calculation
23 fileName = [ sampleFileName '_HNR.txt'];
24 % read pitch metrics from file
25 fileID = fopen( fileName );
26
27 if(( fileID <= 0 ) || ( OVERWRITE )) %does the file exist?
28 % no
29 disp('WARNING: MISSING HNR FILE');
30 %calculate it
31 % [x, fs, frameLength, noOfFrames] = openFile( [ sampleFileName '.wav' ] );
32 y = buffer(x,frameLength);
33 harmonicToNoiseRatio = calculate_HNR( y, fs, noOfFrames, silentFrames, pitch );
34
35 fileID = fopen( fileName, 'w');
36 for i = 1 : (noOfFrames-1)
37 fprintf(fileID, '%d %s \n' , i, num2str( harmonicToNoiseRatio(i) ));
38 end
39 fclose( fileID );
40 fileID = fopen( fileName );
41 end
42
43
44 HNR = fscanf( fileID, '%f', inf );
45 HNR = HNR(2:2:end);
46 fclose(fileID);