-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeatureSpectralSpread.m
More file actions
executable file
·32 lines (25 loc) · 953 Bytes
/
FeatureSpectralSpread.m
File metadata and controls
executable file
·32 lines (25 loc) · 953 Bytes
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
% ======================================================================
%> @brief computes the spectral spread from the magnitude spectrum
%> called by ::ComputeFeature
%>
%> @param X: spectrogram (dimension FFTLength X Observations)
%> @param f_s: sample rate of audio data
%>
%> @retval v spectral spread (in Hz)
% ======================================================================
function [vss] = FeatureSpectralSpread (X, f_s)
% get spectral centroid as index
vsc = FeatureSpectralCentroid (X, f_s)*2/f_s * size(X,1);
% allocate memory
vss = zeros(size(vsc));
% compute spread
X = X.^2;
for (n = 1:size(X,2))
vss(n) = (([0:size(X,1)-1]-vsc(n)).^2*X(:,n))./sum(X(:,n));
end
vss = sqrt(vss);
% convert from index to Hz
vss = vss / size(X,1) * f_s/2;
% avoid NaN for silence frames
vss (sum(X,1) == 0) = 0;
end