0001 function cutIndex=uvCut(y, fs, param, plotOpt)
0002
0003
0004
0005
0006
0007
0008
0009
0010
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;
0030 endIndex=min(cutOffFreq/(fs/frameSize)+1, frameSize/2+1);
0031 for i=1:frameNum
0032
0033 fftOutput=fft(frameMat(:,i).*hamming(frameSize));
0034 fftOutput=fftOutput(1:endIndex);
0035 fftMat(:,i)=fftOutput.*conj(fftOutput);
0036 end
0037
0038
0039
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
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
0073 function selfdemo
0074 waveFile='城.wav';
0075
0076
0077
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);