pyACA: Documentation 0.3.1
Source Code for Audio Content Analysis
Loading...
Searching...
No Matches
Functions
pyACA.FeatureSpectralSpread Namespace Reference

Functions

 FeatureSpectralSpread (X, f_s)
 computes the spectral spread from the magnitude spectrum
 

Function Documentation

◆ FeatureSpectralSpread()

FeatureSpectralSpread ( X,
f_s )

computes the spectral spread from the magnitude spectrum

Parameters
Xspectrogram (dimension FFTLength X Observations)
f_ssample rate of audio data
Returns
vss: spectral spread

Definition at line 13 of file FeatureSpectralSpread.py.

13def FeatureSpectralSpread(X, f_s):
14
15 isSpectrum = X.ndim == 1
16 if isSpectrum:
17 X = np.expand_dims(X, axis=1)
18
19 # get spectral centroid as index
20 vsc = FeatureSpectralCentroid(X, f_s) * 2 / f_s * (X.shape[0] - 1)
21
22 # X = X**2 removed for consistency with book
23
24 norm = X.sum(axis=0)
25 norm[norm == 0] = 1
26
27 # compute spread
28 vss = np.zeros(X.shape[1])
29 indices = np.arange(0, X.shape[0])
30 for n in range(0, X.shape[1]):
31 vss[n] = np.dot((indices - vsc[n])**2, X[:, n]) / norm[n]
32
33 vss = np.sqrt(vss)
34
35 # convert from index to Hz
36 vss = vss / (X.shape[0] - 1) * f_s / 2
37
38 return np.squeeze(vss) if isSpectrum else vss