forked from alexanderlerch/ACA-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PitchSpectralAcf.m
34 lines (28 loc) · 1.03 KB
/
PitchSpectralAcf.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
% ======================================================================
%> @brief 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 (in Hz)
% ======================================================================
function [f] = PitchSpectralAcf (X, f_s)
% initialize
iOrder = 4;
f_min = 300;
eta_min = round(f_min/f_s * 2 * size(X,1));
% allocate
f = zeros(1, size(X,2));
% use spectral symmetry for robustness
X(1,:) = max(max(X));
X = [flipud(X); X];
% compute the ACF
for (n = 1: size(X,2))
afCorr = xcorr(X(:,n),'coeff');
afCorr = afCorr((ceil((length(afCorr)/2))+1):end);
[fDummy, f(n)] = max(afCorr(1+eta_min:end));
end
% find max index and convert to Hz (note: X has double length)
f = (f + eta_min - 1) / size(X,1) * f_s;
end