Home > pitchmark > pitchmarkdp.m

pitchmarkdp

PURPOSE ^

PITCHMARKDP Pitch marking based on Dynamic Programming.

SYNOPSIS ^

function pitchmarks = pitchmarkdp(y, fs, plotopt, pmarkParam)

DESCRIPTION ^

 PITCHMARKDP Pitch marking based on Dynamic Programming.
   Usage : pitchmarks = pitchmarkdp(y, fs, plotopt, pmarkParam)

   pmarkParam is a struct variable.
   You can type 'pmarkParam = getpmarkParam(y, fs);' to get this variable.
   or use 'pmarkParam = getpmarkParam(y, fs, plotopt, SFS_pitchcurve);' to get more precise parameters.

   Selfedemo : pitchmarkdp

 Cheng-Yuan Lin 2004, April, 5

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function pitchmarks = pitchmarkdp(y, fs, plotopt, pmarkParam)
0002 % PITCHMARKDP Pitch marking based on Dynamic Programming.
0003 %   Usage : pitchmarks = pitchmarkdp(y, fs, plotopt, pmarkParam)
0004 %
0005 %   pmarkParam is a struct variable.
0006 %   You can type 'pmarkParam = getpmarkParam(y, fs);' to get this variable.
0007 %   or use 'pmarkParam = getpmarkParam(y, fs, plotopt, SFS_pitchcurve);' to get more precise parameters.
0008 %
0009 %   Selfedemo : pitchmarkdp
0010 %
0011 % Cheng-Yuan Lin 2004, April, 5
0012 
0013 if nargin == 0, selfdemo; return; end;
0014 if nargin <4, pmarkParam = getpmarkParam(y, fs); end;
0015 
0016 %Setting Parameters.
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 %Main Program.
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 %                Sub function: getstateprob                    %
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);  %dist is from 0 ~ 2, and prob is from 1 ~ 0.
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    %probmatrix(:, c) = prob';
0048 end;
0049 
0050 % ============================================================ %
0051 %                   Sub function: rundp                        %
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 %差一個pitch points
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       %根據pitch curve算出與目前pitch的機率值
0068       %logprob = -(abs(temp-SFS_pitchcurve(c+1))./temp);
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       %logprob = prob';
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 %Back tracking.
0085 backIndex = ones(1, col); %backIndex紀錄的是前一個index的值, 例如Indexmatrix 第17行紀錄的是 第16個pamrk的index
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 % selfdemo
0096 % ============================================================== %
0097 function selfdemo
0098 [y, fs] = wavread('la.wav'); y = y(4000:7400);
0099 %[y, fs] = wavread('E:\ProgramCode\DataSet\TTS_wavedata\CSWaveFiles\11021.wav');
0100 plotopt = 1;
0101 pmarkParam = getpmarkParam(y, fs, plotopt);
0102 pitchmarks = feval(mfilename, y, fs, plotopt, pmarkParam);

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