Mercurial > hg > emotion-detection-top-level
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Code/Descriptors/Matlab/MPEG7/detect_HNR.m Wed Feb 13 11:02:39 2013 +0000 @@ -0,0 +1,46 @@ +function [HNR] = detect_HNR( sampleWavFileName, OVERWRITE ) + +sampleFileName = sampleWavFileName( 1 : length( sampleWavFileName ) - 4 ); +[x, fs, frameLength, noOfFrames] = openFile( sampleWavFileName ); + +%---------------- GET THE SILENT FRAME VALUES ------------------- + +% only wish to consider pitch values from voiced frames. +% silent and unvoiced frames will produce pitch values that +% are random and therefore will bias our results + +segmentFrames = detect_Silence( sampleWavFileName, 0 ); +[ silentFrames ] = getSilentDataArray( segmentFrames, noOfFrames ); + + +%---------------- GET THE PITCH VALUES -------------------------- + +[ pitch ] = detect_pitch( sampleWavFileName, 0 ); + +% calculate the HNR + +% open original calculation +fileName = [ sampleFileName '_HNR.txt']; +% read pitch metrics from file +fileID = fopen( fileName ); + +if(( fileID <= 0 ) || ( OVERWRITE )) %does the file exist? + % no + disp('WARNING: MISSING HNR FILE'); + %calculate it +% [x, fs, frameLength, noOfFrames] = openFile( [ sampleFileName '.wav' ] ); + y = buffer(x,frameLength); + harmonicToNoiseRatio = calculate_HNR( y, fs, noOfFrames, silentFrames, pitch ); + + fileID = fopen( fileName, 'w'); + for i = 1 : (noOfFrames-1) + fprintf(fileID, '%d %s \n' , i, num2str( harmonicToNoiseRatio(i) )); + end + fclose( fileID ); + fileID = fopen( fileName ); +end + + +HNR = fscanf( fileID, '%f', inf ); +HNR = HNR(2:2:end); +fclose(fileID);