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

Functions

 FeatureSpectralSkewness (X, f_s, UseBookDefinition=False)
 computes the spectral skewness from the magnitude spectrum
 

Function Documentation

◆ FeatureSpectralSkewness()

FeatureSpectralSkewness ( X,
f_s,
UseBookDefinition = False )

computes the spectral skewness from the magnitude spectrum

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

Definition at line 15 of file FeatureSpectralSkewness.py.

15def FeatureSpectralSkewness(X, f_s, UseBookDefinition=False):
16
17 isSpectrum = X.ndim == 1
18 if isSpectrum:
19 X = np.expand_dims(X, axis=1)
20
21 if UseBookDefinition: # not recommended
22 # compute mean and standard deviation
23 mu_x = np.mean(X, axis=0, keepdims=True)
24 std_x = np.std(X, axis=0)
25
26 # remove mean
27 X = X - mu_x
28
29 # compute kurtosis
30 vssk = np.sum(X**3, axis=0) / (std_x**3 * X.shape[0])
31 else:
32 f = np.arange(0, X.shape[0]) / (X.shape[0] - 1) * f_s / 2
33 # get spectral centroid and spread (mean and std of dist)
34 vsc = FeatureSpectralCentroid(X, f_s)
35 vss = FeatureSpectralSpread(X, f_s)
36
37 norm = X.sum(axis=0)
38 norm[norm == 0] = 1
39 vss[vss == 0] = 1
40
41 # compute spread
42 vssk = np.zeros(X.shape[1])
43 for n in range(0, X.shape[1]):
44 vssk[n] = np.dot((f - vsc[n])**3, X[:, n]) / (vss[n]**3 * norm[n] )
45
46 return np.squeeze(vssk) if isSpectrum else vssk