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

Functions

 FeatureSpectralCentroid (X, f_s)
 computes the spectral centroid from the (squared) magnitude spectrum
 

Function Documentation

◆ FeatureSpectralCentroid()

FeatureSpectralCentroid ( X,
f_s )

computes the spectral centroid from the (squared) magnitude spectrum

Parameters
Xspectrogram (dimension FFTLength X Observations)
f_ssample rate of audio data
Returns
vsc: spectral centroid (in Hz)

Definition at line 12 of file FeatureSpectralCentroid.py.

12def FeatureSpectralCentroid(X, f_s):
13
14 isSpectrum = X.ndim == 1
15
16 # X = X**2 removed for consistency with book
17
18 norm = X.sum(axis=0, keepdims=True)
19 norm[norm == 0] = 1
20
21 vsc = np.dot(np.arange(0, X.shape[0]), X) / norm
22
23 # convert from index to Hz
24 vsc = vsc / (X.shape[0] - 1) * f_s / 2
25
26 # if input is a spectrum, output scaler else if spectrogram, output 1d array
27 vsc = np.squeeze(vsc) if isSpectrum else np.squeeze(vsc, axis=0)
28
29 return vsc