-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeatureTimePredictivityRatio.m
executable file
·38 lines (31 loc) · 1.31 KB
/
FeatureTimePredictivityRatio.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
% ======================================================================
%> @brief computes the zero crossing rate from 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 vtp predictivity ratio
%> @retval t time stamp
% ======================================================================
function [vtp, t] = FeatureTimePredictivityRatio(x, iBlockLength, iHopLength, f_s)
% initialize
iNumPredCoeffs = 12;
% number of results
iNumOfBlocks = ceil (length(x)/iHopLength);
% compute time stamps
t = ((0:iNumOfBlocks-1) * iHopLength + (iBlockLength/2))/f_s;
% allocate memory
vtp = zeros(1,iNumOfBlocks);
for (n = 1:iNumOfBlocks)
i_start = (n-1)*iHopLength + 1;
i_stop = min(length(x),i_start + iBlockLength - 1);
afBlock = x(i_start:i_stop);
% compute prediction coefficients
b = lpc(afBlock, iNumPredCoeffs);
% compute the predictivity ratio
vtp(n) = sqrt(mean((afBlock-filter([0 -b(2:end)],1,afBlock)).^2)/mean(afBlock.^2));
end
end