view Code/Descriptors/Matlab/Common/calculate_VoicedUnvoicedDecision.m @ 4:92ca03a8fa99 tip

Update to ICASSP 2013 benchmark
author Dawn Black
date Wed, 13 Feb 2013 11:02:39 +0000
parents ea0c737c6323
children
line wrap: on
line source
function [ vuv ] = calculate_VoicedUnvoicedDecision( sampleName, x, fs, frameLength, noOfFrames, silentFrames )

DEBUG = 1; % do we want to plot the output?

y = buffer( x, frameLength );

% % open original annotation file for PhD speech
% fileName = [sampleName '.txt'];
% % read metrics from file
% fileID = fopen( fileName );
% data = fscanf( fileID, '%d', inf );
% annotatedPitch = data(3:4:end);
% fclose( fileID );

% open HNR file
fileName = [sampleName '_HNR.txt'];
% read metrics from file
fileID = fopen( fileName );
data = fscanf( fileID, '%f', inf );
harmonic2noise = data(2:2:end);
fclose( fileID );

largestH2NValue = max( [max(harmonic2noise) abs(min(harmonic2noise))] );
%normalise
harmonic2noise = harmonic2noise/largestH2NValue;
%round to 1dp
harmonic2noise= (round(harmonic2noise*10))/10;

% open audio power file
fileName = [sampleName '_AP.txt'];
% read metrics from file
fileID = fopen( fileName );
data = fscanf( fileID, '%f', inf );
audioPower = data(2:2:end);
fclose( fileID );
maxPower = max(audioPower);


minFreq = ceil(fs/getVariables('getMinFreq')); %default minimum fundatmental frequency
maxFreq = ceil(fs/getVariables('getMaxFreq')); %default maximum fundamental frequency
    
% open pitch file
fileName = [sampleName '_YIN_pitch.txt'];
% read metrics from file
fileID = fopen( fileName );
data = fscanf( fileID, '%f', inf );
pitch = data(2:2:end);
fclose( fileID );

% open band power file
% fileName = [sampleName '_ASBP_norm.txt'];
% % read metrics from file
% fileID = fopen( fileName );
% data = fscanf( fileID, '%f', inf );
% bandPowerRatio = data(2:2:end);
% fclose( fileID );
% bandPowerRatioRMS =   sqrt( mean(( bandPowerRatio/max(bandPowerRatio) ).^2 ));
% 


HNRThresh = 0;
if(DEBUG) hold off; end
minLength = min([length(harmonic2noise) length(audioPower) length(pitch)]);
for( i=1:minLength )


     if( silentFrames(i) == 0 ) % harmonic2noise(i) == 0 )
         %silent
        if(DEBUG) plot( ((i-1)*frameLength)+1:(i*frameLength), y(:,i), 'y' );hold on; end;
        vuv(i) = 0;
     elseif( ((harmonic2noise(i) <= HNRThresh))... %|| (bandPowerRatio(i)/max(bandPowerRatio) < 0.001)) ...
            || (pitch(i) > minFreq) ...
            || (pitch(i) < maxFreq)) %...
%             || (audioPower(i)/maxPower < 0.0005))
        % unvoiced
        if(DEBUG) plot( ((i-1)*frameLength)+1:(i*frameLength), y(:,i), 'r' );hold on; end
        vuv(i) = 2;
     else
         %voiced
        if(DEBUG) plot( ((i-1)*frameLength)+1:(i*frameLength), y(:,i), 'g' );hold on; end
        vuv(i) = 1;
    end
end

if(DEBUG)
    
    plot( frameLength/2:frameLength:(frameLength*length(harmonic2noise)), harmonic2noise, 'b' );hold on;
%     plot( frameLength/2:frameLength:(frameLength*length(audioPower)), audioPower/maxPower, 'm' );hold on;
    plot( frameLength/2:frameLength:(frameLength*length(pitch)), pitch/max(pitch), 'w' );hold on;
%     plot( frameLength/2:frameLength:(frameLength*length(bandPowerRatio)), bandPowerRatio/max(bandPowerRatio), 'c' );hold on;

    L=line([0 length(x)], [maxFreq/max(pitch) maxFreq/max(pitch)]);
    set(L,'color',[1 0 0]);
    L=line([0 length(x)], [minFreq/max(pitch) minFreq/max(pitch)]);
    set(L,'color',[1 0 0]);
%     L=line([0 length(x)], [0.0001 0.0005]);
%     set(L, 'color', [0 1 1] );
    %HNR threshold
    L=line([0 length(x)], [HNRThresh HNRThresh]);
    set(L, 'color', [0 0 1] );
end