Dawn@4: function [] = readFormantValueFromFile( statsFileID, metricFileName, metricName, vuv ) Dawn@4: Dawn@4: DEBUG=0; Dawn@4: Dawn@4: FileID = fopen( metricFileName ); Dawn@4: Dawn@4: if( FileID <= 0 ) %does the file exist? Dawn@4: % if not Dawn@4: Dawn@4: message = ['WARNING: MISSING ' metricName ' FILE']; Dawn@4: disp( message ); Dawn@4: fprintf( statsFileID, '\t \s missing', metricName ); Dawn@4: Dawn@4: else Dawn@4: % file format is not straight forward Dawn@4: noOfValues = 0; Dawn@4: formants = []; Dawn@4: while( ~(feof(FileID)) ) Dawn@4: Dawn@4: % search for numberOfFormants Dawn@4: thestr = fgetl(FileID); Dawn@4: Dawn@4: if( strfind( thestr , 'numberOfFormants' ) > 0 ) Dawn@4: noOfValues = noOfValues + 1; Dawn@4: %numberOfFormants found Dawn@4: pos = find( thestr == '=' ); Dawn@4: numberOfFormants = str2num(thestr(pos+2:end)); Dawn@4: formants( noOfValues, 1 ) = numberOfFormants; Dawn@4: % discard the 'formant []' line Dawn@4: thestr = fgetl(FileID); Dawn@4: % now read the formant positions Dawn@4: for (i=0:numberOfFormants-1) Dawn@4: thestr = fgetl(FileID); Dawn@4: pos = find( thestr == '=' ); Dawn@4: formants( noOfValues, i+2 ) = str2num(thestr( pos+2 : end )); Dawn@4: end Dawn@4: Dawn@4: % discard the 'bandwidth []' line Dawn@4: thestr = fgetl(FileID); Dawn@4: % now read the formant bandwidths Dawn@4: for (i=0:numberOfFormants-1) Dawn@4: thestr = fgetl(FileID); Dawn@4: pos = find( thestr == '=' ); Dawn@4: formants( noOfValues, i+2+numberOfFormants ) = str2num(thestr( pos+2 : end )); Dawn@4: end Dawn@4: Dawn@4: end Dawn@4: end Dawn@4: fclose(FileID); Dawn@4: Dawn@4: Dawn@4: if(DEBUG) Dawn@4: timeShift = length(formants) / length(vuv); Dawn@4: subplot(211); hold off; Dawn@4: subplot(212); hold off; Dawn@4: for( idx = 1: length( formants )/10 ) Dawn@4: frameIdx = floor( idx / timeShift ) + 1; Dawn@4: if( frameIdx <= length(vuv) ) Dawn@4: if( vuv( frameIdx ) == 0 ) Dawn@4: % frame is silent Dawn@4: subplot(211); plot( idx, formants( idx,2 ), 'w.' ); hold on; Dawn@4: subplot(211); plot( idx, formants( idx,3 ), 'w.' ); Dawn@4: subplot(211); plot( idx, formants( idx,4 ), 'w.' ); Dawn@4: % plot bandwidths Dawn@4: subplot(212); plot( idx, formants( idx,5 ), 'w.' ); hold on; Dawn@4: subplot(212); plot( idx, formants( idx,6 ), 'w.' ); Dawn@4: subplot(212); plot( idx, formants( idx,7 ), 'w.' ); Dawn@4: elseif( vuv( frameIdx ) == 1 ) Dawn@4: % frame is voiced Dawn@4: subplot(211); plot( idx, formants( idx,2 ), 'y.' ); hold on; Dawn@4: subplot(211); plot( idx, formants( idx,3 ), 'c.' ); Dawn@4: subplot(211); plot( idx, formants( idx,4 ), 'g.' ); Dawn@4: % plot bandwidths Dawn@4: subplot(212); plot( idx, formants( idx,5 ), 'y.' ); hold on; Dawn@4: subplot(212); plot( idx, formants( idx,6 ), 'c.' ); Dawn@4: subplot(212); plot( idx, formants( idx,7 ), 'g.' ); Dawn@4: else Dawn@4: %frame is unvoiced Dawn@4: subplot(211); plot( idx, formants( idx,2 ), 'r.' ); hold on; Dawn@4: subplot(211); plot( idx, formants( idx,3 ), 'r.' ); Dawn@4: subplot(211); plot( idx, formants( idx,4 ), 'r.' ); Dawn@4: % plot bandwidths Dawn@4: subplot(212); plot( idx, formants( idx,5 ), 'r.' ); hold on; Dawn@4: subplot(212); plot( idx, formants( idx,6 ), 'r.' ); Dawn@4: subplot(212); plot( idx, formants( idx,7 ), 'r.' ); Dawn@4: end Dawn@4: else Dawn@4: frameIdx Dawn@4: end Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: [ noOfSamples formantDataSize ] = size( formants ); Dawn@4: maxNoOfFormants = (formantDataSize - 1)/2; % the array contains the number of formants, then the position of each formant, then the bandwidth of each formant. Dawn@4: voicedFormant = []; Dawn@4: voicedBandwidth = []; Dawn@4: % find the basic metric set for the voiced frames only Dawn@4: validSamples = min( noOfSamples, length(vuv) ); Dawn@4: for( idx = 1: validSamples ) Dawn@4: if( vuv( idx ) == 1 ) Dawn@4: % frame is voiced Dawn@4: formantsThisFrame = formants(idx,1); Dawn@4: theFormants = formants( idx, 2 : formantsThisFrame+1 ); Dawn@4: theBandwidths = formants( idx, formantsThisFrame+2 : (formantsThisFrame*2)+1 ); Dawn@4: % we want to ignore any results that contain less than the Dawn@4: % max number of formants as then one of the formants is set to Dawn@4: % zero and the detection is not reliable Dawn@4: % DON'T THINK THIS IS STILL VALID Dawn@4: % DO WE WANT TO DISCARD FORMANT SETS THAT CONTAIN '0' FORMANT Dawn@4: % POSITIONS FOR VOICED SEGMENTS? Dawn@4: if( formantsThisFrame == maxNoOfFormants ) Dawn@4: voicedFormant = [ voicedFormant ; theFormants ]; Dawn@4: voicedBandwidth = [ voicedBandwidth; theBandwidths ]; Dawn@4: else Dawn@4: % pad with zeros Dawn@4: diff = maxNoOfFormants - formantsThisFrame; Dawn@4: theFormants = [ theFormants zeros( 1, diff )]; Dawn@4: voicedFormant = [ voicedFormant ; theFormants ]; Dawn@4: theBandwidths = [ theBandwidths zeros( 1, diff )]; Dawn@4: voicedBandwidth = [ voicedBandwidth; theBandwidths ]; Dawn@4: end Dawn@4: Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: % get the basic formant metrics Dawn@4: formantFrequencyMeans = []; Dawn@4: formantGradientMean = []; Dawn@4: formantBandwidthMean = []; Dawn@4: Dawn@4: fprintf( statsFileID, '\t %s %d ', 'maxNoOfFormants', maxNoOfFormants ); Dawn@4: Dawn@4: for( formantIdx = 1:maxNoOfFormants ) Dawn@4: % formant position Dawn@4: [ metrics ] = basicMetricSet( voicedFormant(:,formantIdx), statsFileID ); Dawn@4: formantFrequencyMeans = [ formantFrequencyMeans metrics(1) ]; Dawn@4: % formant gradient Dawn@4: formantGradient = gradient( voicedFormant(:,formantIdx) ); Dawn@4: [ metrics ] = basicMetricSet( formantGradient, statsFileID ); Dawn@4: formantGradientMean = [formantGradientMean metrics(1)]; Dawn@4: % formant second derivative Dawn@4: formantGradient = gradient( formantGradient ); Dawn@4: [ metrics ] = basicMetricSet( formantGradient, statsFileID ); Dawn@4: % formant bandwidth Dawn@4: [ metrics ] = basicMetricSet( voicedBandwidth(:,formantIdx), statsFileID ); Dawn@4: formantBandwidthMean = [formantBandwidthMean metrics(1)]; Dawn@4: % formant bandwidth gradient Dawn@4: formantGradient = gradient( voicedBandwidth(:,formantIdx)); Dawn@4: [ metrics ] = basicMetricSet( formantGradient, statsFileID ); Dawn@4: % formant bandwidth second derivative Dawn@4: formantGradient = gradient( formantGradient ); Dawn@4: [ metrics ] = basicMetricSet( formantGradient, statsFileID ); Dawn@4: end Dawn@4: Dawn@4: % calculate the basic metrics set for the ... Dawn@4: % ... mean of all formant frequencies Dawn@4: meanMetrics = basicMetricSet( formantFrequencyMeans, statsFileID ); Dawn@4: % ... mean of all formant frequency gradients Dawn@4: meanMetrics = basicMetricSet( formantGradientMean, statsFileID ); Dawn@4: % ... mean of all formant bandwidths Dawn@4: meanMetrics = basicMetricSet( formantBandwidthMean, statsFileID ); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: