0001 function pitchmarks = pitchmarkMIN(y, fs, maxPeriod, minPeriod, SFS_pitchcurve, plotopt)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 if nargin <6, plotopt = 0; end;
0018 if nargin <4, maxPeriod = 0.007; minPeriod = 0.0065; SFS_pitchcurve = 200; plotopt = 1; end;
0019 if nargin==0, selfdemo; return; end;
0020
0021 pitch = 1/((maxPeriod+minPeriod)/2);
0022
0023
0024 [junk, pitchmarks] = min(y);
0025
0026 while (1),
0027 currentIndex = pitchmarks(end);
0028 minIndex = currentIndex+floor(minPeriod*fs);
0029 maxIndex = currentIndex+ceil(maxPeriod*fs);
0030 if maxIndex >= length(y) ,
0031 if (length(y)- pitchmarks(end)) > (fs/pitch),
0032 begin = pitchmarks(end)+ round((fs/pitch)/2);
0033 candidateY = y(begin : end);
0034 [junk, newIndex] = min(candidateY);
0035 pitchmarks = [pitchmarks, begin+newIndex-1];
0036 end;
0037 break;
0038 end;
0039 candidateY = y(minIndex:maxIndex);
0040 [junk, newIndex] = min(candidateY);
0041 pitchmarks = [pitchmarks, minIndex+newIndex-1];
0042 end
0043
0044 while (1)
0045 currentIndex = pitchmarks(1);
0046 maxIndex = currentIndex-floor(minPeriod*fs);
0047 minIndex = currentIndex-ceil(maxPeriod*fs);
0048 if minIndex <= 0 ,
0049 if pitchmarks(1) > (fs/pitch),
0050 tail = pitchmarks(1) - round((fs/pitch)/2);
0051 candidateY = y(1:tail);
0052 [junk, newIndex] = min(candidateY);
0053 pitchmarks = [newIndex, pitchmarks];
0054 end;
0055 break;
0056 end;
0057 candidateY = y(minIndex:maxIndex);
0058 [junk, newIndex] = min(candidateY);
0059 pitchmarks = [minIndex+newIndex-1, pitchmarks];
0060 end
0061
0062
0063 pitchmarks((diff(pitchmarks)==0)) = [];
0064
0065 if plotopt,
0066 plotpitchmarks(y, fs, pitchmarks, SFS_pitchcurve);
0067 end;
0068
0069
0070
0071
0072
0073 function selfdemo
0074 wavefile = 'E:\test.wav';
0075 plotopt = 1;
0076 [y, fs] = wavread(wavefile);
0077
0078
0079 SFS_pitchcurve = wave2pitch_SFS(wavefile);
0080 SFS_pitchcurve((SFS_pitchcurve<50 | SFS_pitchcurve>600)) = [];
0081 if isempty(SFS_pitchcurve), error('Pitch is not available!'); end;
0082
0083
0084 PitchMean = mean(SFS_pitchcurve);
0085 a = (1/PitchMean);
0086 b = a*0.5;
0087 maxPeriod = a + b;
0088 minPeriod = a - b;
0089 pitchmarks = feval(mfilename, y, fs, maxPeriod, minPeriod, SFS_pitchcurve, plotopt);