-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeatureSpectralTonalPowerRatio.m
More file actions
executable file
·38 lines (32 loc) · 1.06 KB
/
FeatureSpectralTonalPowerRatio.m
File metadata and controls
executable file
·38 lines (32 loc) · 1.06 KB
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 tonal power ratio from the magnitude spectrum
%> called by ::ComputeFeature
%>
%> @param X: spectrogram (dimension FFTLength X Observations)
%> @param f_s: sample rate of audio data (unused)
%> @param G_T: energy threshold
%>
%> @retval vsk tonal power ratio
% ======================================================================
function [vtpr] = FeatureSpectralTonalPowerRatio(X, f_s, G_T)
% initiliaze
if (nargin < 3)
G_T = 5e-4;
end
% allocate memory
vtpr = zeros(1,size(X,2));
X = X.^2;
fSum = sum(X,1);
for (n = 1:size(X,2))
if (fSum == 0)
% do nothing for 0-blocks
continue;
end
% find local maxima
[afPeaks] = findpeaks(X(:,n));
% find peaks above the threshold
k_peak = find(afPeaks > G_T);
% calculate the ratio
vtpr(n) = sum(afPeaks(k_peak))/fSum(n);
end
end