Home > pitchmark > pitchmarkMAX.m

pitchmarkMAX

PURPOSE ^

PITCHMARKMAX Pitch Mark

SYNOPSIS ^

function pitchmarks = pitchmarkMAX(y, fs, maxPeriod, minPeriod, SFS_pitchcurve, plotopt)

DESCRIPTION ^

PITCHMARKMAX Pitch Mark
   Usage : pitchmarks = pitchmarkMAX(y, fs, maxPeriod, minPeriod, SFS_pitchcurve, plotopt)
   Selfdemo : pitchmarkMAX;

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function pitchmarks = pitchmarkMAX(y, fs, maxPeriod, minPeriod, SFS_pitchcurve, plotopt)
0002 
0003 %PITCHMARKMAX Pitch Mark
0004 %   Usage : pitchmarks = pitchmarkMAX(y, fs, maxPeriod, minPeriod, SFS_pitchcurve, plotopt)
0005 %   Selfdemo : pitchmarkMAX;
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); %︳衡ㄓpitch
0012 
0013 % ===== т程y
0014 [maximum, pitchmarks] = max(y);
0015 % ┕тN pitch marks
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), %安程pitch markび
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 %┕玡тM pitch marks
0034 while (1)
0035    currentIndex = pitchmarks(1);
0036    maxIndex = currentIndex-floor(minPeriod*fs);
0037    minIndex = currentIndex-ceil(maxPeriod*fs);
0038    if minIndex <= 0 , %临Τ程pitch mark
0039       if pitchmarks(1) > (fs/pitch), %安ヘ玡材pitch mark
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 %タpitch mark岿粇
0053 pitchmarks((diff(pitchmarks)==0)) = [];
0054 
0055 if plotopt,
0056    plotpitchmarks(y, fs, pitchmarks, SFS_pitchcurve);
0057 end;
0058 
0059 
0060 % ============================================================== %
0061 % selfdemo
0062 % ============================================================== %
0063 function selfdemo
0064 wavefile = 'test.wav';
0065 plotopt = 1;
0066 [y, fs] = wavread(wavefile);
0067 
0068 % 璸衡 pitch
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 % 倒﹚ pitchmarkMIN 把计
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);

Generated on Tue 21-Aug-2007 22:52:24 by m2html © 2003