0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 function [f_0, t] = PitchTimeAcf(x, iBlockLength, iHopLength, f_s)
0013
0014
0015 [x_b, t] = ToolBlockAudio(x, iBlockLength, iHopLength, f_s);
0016 iNumOfBlocks = size(x_b, 1);
0017
0018
0019 f_0 = zeros(1, iNumOfBlocks);
0020
0021
0022 fMaxFreq = 2000;
0023 fMinThresh = 0.35;
0024
0025 for n = 1:iNumOfBlocks
0026 eta_min = round(f_s / fMaxFreq);
0027
0028 if (sum(abs(x_b(n, :))) == 0)
0029 f_0(n) = 0;
0030 continue;
0031 end
0032
0033 afCorr = xcorr(x_b(n, :), 'coeff');
0034 afCorr = afCorr((ceil((length(afCorr)/2))+1):end);
0035
0036
0037 eta_tmp = find (afCorr < fMinThresh, 1);
0038 if (~isempty(eta_tmp))
0039 eta_min = max(eta_min, eta_tmp);
0040 end
0041
0042
0043 afDeltaCorr = diff(afCorr);
0044 eta_tmp = find(afDeltaCorr > 0, 1);
0045 if (~isempty(eta_tmp))
0046 eta_min = max(eta_min, eta_tmp);
0047 end
0048
0049 [fDummy, T_0(n)] = max(afCorr(1+eta_min:end));
0050
0051
0052 f_0(n) = f_s ./ (T_0(n) + eta_min);
0053 end
0054 end