-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeatureTimeMaxAcf.m
executable file
·56 lines (46 loc) · 1.92 KB
/
FeatureTimeMaxAcf.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
% ======================================================================
%> @brief computes the ACF maxima of a time domain signal
%> called by ::ComputeFeature
%>
%> @param x: audio signal
%> @param iBlockLength: block length in samples
%> @param iHopLength: hop length in samples
%> @param f_s: sample rate of audio data (unused)
%>
%> @retval vta autocorrelation maximum
%> @retval t time stamp
% ======================================================================
function [vta, t] = FeatureTimeMaxAcf(x, iBlockLength, iHopLength, f_s)
% initialization
% these values are arbitrary - adapt to your use case
f_max = 2000;
fMinThresh = 0.35;
% number of results
iNumOfBlocks = ceil (length(x)/iHopLength);
% compute time stamps
t = ((0:iNumOfBlocks-1) * iHopLength + (iBlockLength/2))/f_s;
% allocate memory
vta = zeros(1,iNumOfBlocks);
for (n = 1:iNumOfBlocks)
eta_min = floor (f_s/f_max);
i_start = (n-1)*iHopLength + 1;
i_stop = min(length(x),i_start + iBlockLength - 1);
% calculate the acf
afCorr = xcorr(x(i_start:i_stop), 'coeff');
afCorr = afCorr((ceil((length(afCorr)/2))+1):end);
% ignor values until threshold was crossed
eta_tmp = find (afCorr < fMinThresh, 1);
eta_min = max(eta_min, eta_tmp);
% only take into account values after the first minimum
afDeltaCorr = diff(afCorr);
eta_tmp = find(afDeltaCorr > 0, 1);
eta_min = max(eta_min, eta_tmp);
% find the maximum in the computed range
if 1+eta_min <= length(afCorr)
vta(n) = max(afCorr(1+eta_min:end));
else
disp('WARNING: in FeatureTimeMaxAcf, 1+eta_min > end');
vta(n) = 0;
end
end
end