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