0001 function pitchmarks = pitchmarkdp(y, fs, plotopt, pmarkParam)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 if nargin == 0, selfdemo; return; end;
0014 if nargin <4, pmarkParam = getpmarkParam(y, fs); end;
0015
0016
0017 meanPitch = pmarkParam.meanPitch;
0018 maxPeriod = pmarkParam.maxPeriod;
0019 minPeriod = pmarkParam.minPeriod;
0020 candNum = pmarkParam.candNum;
0021 PorV = pmarkParam.PorV;
0022 SFS_pitchcurve = pmarkParam.pitchcurve;
0023
0024
0025 sampleIndex = getlocation(y, fs, meanPitch, candNum, PorV, maxPeriod, minPeriod, 0);
0026 probmatrix = getstateprob(y, sampleIndex);
0027 pitchmarks = rundp(probmatrix, sampleIndex, SFS_pitchcurve, fs);
0028
0029 if plotopt,
0030 plotpitchmarks(y, fs, pitchmarks, SFS_pitchcurve);
0031 end;
0032
0033
0034
0035
0036 function probmatrix = getstateprob(y, sampleIndex)
0037 row = size(sampleIndex, 1);
0038 col = size(sampleIndex, 2);
0039 probmatrix = ones(row, col);
0040 dist = zeros(1, row);
0041 scale = 1;
0042 for c = 1 : col,
0043 dist(2:3) = y(sampleIndex(2:end, c)) - y(sampleIndex(1, c));
0044 dist(2:3) = dist(2:3)*scale;
0045 prob = 1-abs(dist/2);
0046 probmatrix(:, c) = log10(prob)';
0047
0048 end;
0049
0050
0051
0052
0053 function pmarkdp = rundp(probmatrix, sampleIndex, SFS_pitchcurve, fs)
0054 row = size(sampleIndex, 1);
0055 col = size(sampleIndex, 2);
0056 Indexmatrix = ones(row, col);
0057 maxDist = mean(SFS_pitchcurve);
0058
0059
0060 if (length(SFS_pitchcurve) == col-1 ), SFS_pitchcurve = [SFS_pitchcurve SFS_pitchcurve(end)]; end;
0061 if col > length(SFS_pitchcurve), col = length(SFS_pitchcurve); end;
0062
0063 for c = 1 : col-1,
0064 for r = 1 : row,
0065 temp = sampleIndex(r, c+1) - sampleIndex(:, c);
0066 pitch = fs./temp;
0067
0068
0069
0070 dist = abs(pitch - SFS_pitchcurve(c+1));
0071 dist(find(dist>maxDist)) = maxDist;
0072 prob = -(dist/maxDist)+1;
0073 logprob = log10(prob)';
0074
0075
0076 logprob = logprob + probmatrix(:, c)';
0077 [cumvalue, index] = max(logprob);
0078
0079 probmatrix(r, c+1) = probmatrix(r, c+1) + cumvalue;
0080 Indexmatrix(r, c+1) = index;
0081 end;
0082 end;
0083
0084
0085 backIndex = ones(1, col);
0086 pmarkdp = ones(1, col);
0087 [junk, backIndex(end)] = max(probmatrix(:,end));
0088 pmarkdp(end) = sampleIndex(backIndex(end), end);
0089 for k = col-1 : -1 : 1,
0090 pmarkdp(k) = sampleIndex(backIndex(k+1), k);
0091 backIndex(k) = Indexmatrix(backIndex(k+1), k);
0092 end;
0093
0094
0095
0096
0097 function selfdemo
0098 [y, fs] = wavread('la.wav'); y = y(4000:7400);
0099
0100 plotopt = 1;
0101 pmarkParam = getpmarkParam(y, fs, plotopt);
0102 pitchmarks = feval(mfilename, y, fs, plotopt, pmarkParam);