computes the maximum of the Harmonic Product Spectrum > called by ::ComputePitch > > @param X: spectrogram (dimension FFTLength X Observations) > @param f_s: sample rate of audio data > > @retval f HPS maximum (in Hz) ======================================================================
0001 %computes the maximum of the Harmonic Product Spectrum 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 HPS maximum (in Hz) 0008 % ====================================================================== 0009 function [f] = PitchSpectralHps (X, f_s) 0010 0011 % initialize 0012 iOrder = 4; 0013 f_min = 300; 0014 k_min = round(f_min/f_s * 2 * (size(X, 1)-1)) + 1; 0015 0016 afHps = X; 0017 0018 % compute the HPS 0019 for j = 2:iOrder 0020 afHps = afHps .* [X(1:j:end, :); zeros(size(X, 1)-size(X(1:j:end,:), 1), size(X, 2))]; 0021 end 0022 0023 % find max index and convert to Hz 0024 [fDummy, f] = max(afHps(k_min:end, :), [], 1); 0025 f = (f + k_min - 2) / (size(X, 1)-1) * f_s / 2; 0026 f(sum(afHps, 1) == 0) = 0; 0027 end