computes the maximum of the spectral autocorrelation function > called by ::ComputePitch > > @param X: spectrogram (dimension FFTLength X Observations) > @param f_s: sample rate of audio data > > @retval f acf maximum location (in Hz) ======================================================================
0001 %computes the maximum of the spectral autocorrelation function 0002 %> called by ::ComputePitch 0003 %> 0004 %> @param X: spectrogram (dimension FFTLength X Observations) 0005 %> @param f_s: sample rate of audio data 0006 %> 0007 %> @retval f acf maximum location (in Hz) 0008 % ====================================================================== 0009 function [f] = PitchSpectralAcf (X, f_s) 0010 0011 % initialize 0012 f_min = 300; 0013 0014 % allocate 0015 f = zeros(1, size(X,2)); 0016 0017 % use spectral symmetry for robustness 0018 X(1, :) = max(max(X)); 0019 X = [flipud(X); X]; 0020 0021 % compute the ACF 0022 for n = 1: size(X, 2) 0023 eta_min = round(f_min/f_s * (size(X, 1)-2)); 0024 afCorr = xcorr(X(:,n),'coeff'); 0025 afCorr = afCorr((ceil((length(afCorr)/2))+1):end); 0026 0027 % find local maxima 0028 [fDummy, eta_peak] = findpeaks(afCorr); 0029 0030 eta_min = max(eta_min, find(eta_peak > eta_min, 1)); 0031 [fDummy, f(n)] = max(afCorr(eta_min:end)); 0032 end 0033 0034 % find max index and convert to Hz (note: X has double length) 0035 f = (f + eta_min - 1) / (size(X, 1)-2) * f_s; 0036 end