Home > ACA-Code > PitchTimeAcf.m

PitchTimeAcf

PURPOSE ^

computes the lag of the autocorrelation function

SYNOPSIS ^

function [f_0, t] = PitchTimeAcf(x, iBlockLength, iHopLength, f_s)

DESCRIPTION ^

computes the lag of the autocorrelation function
> called by ::ComputePitch
>
> @param x: audio signal
> @param iBlockLength: block length in samples
> @param iHopLength: hop length in samples
> @param f_s: sample rate of audio data 
>
> @retval f_0 acf lag (in Hz)
> @retval t time stamp of f_0 estimate (in s)
 ======================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %computes the lag of the autocorrelation function
0002 %> called by ::ComputePitch
0003 %>
0004 %> @param x: audio signal
0005 %> @param iBlockLength: block length in samples
0006 %> @param iHopLength: hop length in samples
0007 %> @param f_s: sample rate of audio data
0008 %>
0009 %> @retval f_0 acf lag (in Hz)
0010 %> @retval t time stamp of f_0 estimate (in s)
0011 % ======================================================================
0012 function [f_0, t] = PitchTimeAcf(x, iBlockLength, iHopLength, f_s)
0013 
0014     % blocking
0015     [x_b, t] = ToolBlockAudio(x, iBlockLength, iHopLength, f_s);
0016     iNumOfBlocks = size(x_b, 1);
0017     
0018     % allocate memory
0019     f_0 = zeros(1, iNumOfBlocks);
0020 
0021     %initialization
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         % calculate the acf maximum
0033         afCorr = xcorr(x_b(n, :), 'coeff');
0034         afCorr = afCorr((ceil((length(afCorr)/2))+1):end);
0035 
0036         % ignore values until threshold was crossed
0037         eta_tmp = find (afCorr < fMinThresh, 1);
0038         if (~isempty(eta_tmp))
0039             eta_min = max(eta_min, eta_tmp);
0040         end
0041         
0042         % only take into account values after the first minimum
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         % convert to Hz
0052         f_0(n) = f_s ./ (T_0(n) + eta_min);
0053     end
0054 end

Generated on Fri 22-Apr-2022 20:59:51 by m2html © 2005