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