For classification, we're going to be using the new features in our arsenal: cherishing those "spectral moments" (centroid, bandwidth, skewness, kurtosis) and also examining other spectral statistics.
Moments is a term used in physics and statistics. There are raw moments and central moments. The first raw moment is known as the mean. The second central moment is known as the variance.
essentia.standard.Centroid
¶To compute the spectral centroid, we will use essentia.standard.Centroid
:
import essentia
from essentia.standard import Spectrum, Centroid
spectrum = Spectrum()
centroid = Centroid()
x = essentia.array(randn(1024))
X = spectrum(x)
spectral_centroid = centroid(X)
print spectral_centroid
This value is normalized between 0 and 1. If 0, then the centroid is at zero. If 1, then the centroid is all the way to the "right", i.e., equal to fs/2
, the Nyquist frequency, or the highest frequency a digital signal can possibly have.
Here is a sanity check:
sum((X/sum(X))*linspace(0, 1, len(X)))
essentia.standard.CentralMoments
¶The first step to computing the other three spectral moments (spread, skewness, and kurtosis) is to compute the central moments of a spectrum:
from essentia.standard import CentralMoments
central_moments = CentralMoments()
print central_moments(X)
essentia.standard.DistributionShape
¶To compute the spectral spread, skewness, and kurtosis, we use essentia.standard.DistributionShape
:
from essentia.standard import DistributionShape
distributionshape = DistributionShape()
spectral_moments = distributionshape(central_moments(X))
print spectral_moments