Home > asr > uvCut.m

uvCut

PURPOSE ^

uvCut: Find the cut for unvoiced/voiced boundary

SYNOPSIS ^

function cutIndex=uvCut(y, fs, param, plotOpt)

DESCRIPTION ^

 uvCut: Find the cut for unvoiced/voiced boundary
    Usage: cutIndex=uvCut(y, fs, param, plotOpt)
        y: wave signals
        fs: sampling rate
        param: a structure of parameters
        plotOpt: 1 for plotting
        cutIndex: sample index for U/V cut

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function cutIndex=uvCut(y, fs, param, plotOpt)
0002 % uvCut: Find the cut for unvoiced/voiced boundary
0003 %    Usage: cutIndex=uvCut(y, fs, param, plotOpt)
0004 %        y: wave signals
0005 %        fs: sampling rate
0006 %        param: a structure of parameters
0007 %        plotOpt: 1 for plotting
0008 %        cutIndex: sample index for U/V cut
0009 
0010 %    Roger Jang, 20060907
0011 
0012 if nargin<1; selfdemo; return; end
0013 if nargin<2; fs=16000; end
0014 if nargin<3;
0015     param.frameSize=320;
0016     param.frameSkip=32;
0017     param.method=1;
0018 end
0019 if nargin<4; plotOpt=0; end
0020 
0021 frameSize=param.frameSize;
0022 frameSkip=param.frameSkip;
0023 method=param.method;
0024 
0025 overlap=frameSize-frameSkip;
0026 frameMat=buffer2(y, frameSize, overlap);
0027 frameNum=size(frameMat, 2);
0028 
0029 cutOffFreq=fs/2;    % fs/2 ===> 全選
0030 endIndex=min(cutOffFreq/(fs/frameSize)+1, frameSize/2+1);
0031 for i=1:frameNum
0032 %    fftOutput=fft(frameMat(:,i));
0033     fftOutput=fft(frameMat(:,i).*hamming(frameSize));
0034     fftOutput=fftOutput(1:endIndex);
0035     fftMat(:,i)=fftOutput.*conj(fftOutput);
0036 end
0037 %size(fftMat)
0038 
0039 %fftMat=dataNormalize(fftMat);
0040 
0041 shift=round(frameSize/frameSkip);
0042 time1=frame2sampleIndex(1:frameNum, frameSize, overlap)/fs;
0043 time2=(frameSize+((1:frameNum-shift)-1)*frameSkip)/fs;
0044 
0045 
0046 for i=1:frameNum-shift
0047     fftDiff(i)=sum(abs(fftMat(:, i)-fftMat(:, i+shift)));
0048 %    fftDiff(i)=sum((1:size(fftMat, 1))'.*abs(fftMat(:, i)-fftMat(:, i+shift)));
0049 end
0050 
0051 [maxValue, maxIndex]=max(fftDiff(1:round(length(fftDiff)/2)));        % 只看前一半的最大值
0052 cutIndex=round(time2(maxIndex)*fs);
0053 
0054 if plotOpt
0055     plotNum=3;
0056     subplot(plotNum,1,1);
0057     time=(1:length(y))/fs;
0058     for i=1:length(time2)
0059         line(time2(i)*[1 1], [min(y), max(y)], 'color', 'k');
0060     end
0061     line(time, y);
0062     axis([-inf inf min(y), max(y)]); box on; grid on
0063     line(time2(maxIndex)*[1 1], [min(y), max(y)], 'color', 'r', 'linewidth', 2);
0064     subplot(plotNum,1,2);
0065     specgram(y, frameSize, fs, hamming(frameSize), overlap)
0066     subplot(plotNum,1,3);
0067     plot(time2, fftDiff, '.-');
0068     line(time2(maxIndex)*[1 1], [min(fftDiff), max(fftDiff)], 'color', 'r', 'linewidth', 2);
0069     axis tight; grid on
0070 end
0071 
0072 % ====== Self demo
0073 function selfdemo
0074 waveFile='城.wav';
0075 %waveFile='在.wav';
0076 %waveFile='但.wav';
0077 %waveFile='將.wav';
0078 [y, fs, nbits]=wavread(waveFile);
0079 param.frameSize=320;
0080 param.frameSkip=160;
0081 param.method=1;
0082 plotOpt=1;
0083 cutIndex=feval(mfilename, y, fs, param, plotOpt);

Generated on Tue 01-Jun-2010 09:50:19 by m2html © 2003