spectrum = ess.Spectrum()
centroid = ess.Centroid()
x = essentia.array(scipy.randn(1024))
X = spectrum(x)
spectral_centroid = centroid(X)
print spectral_centroid

"""
Explanation: &larr; Back to Index
Spectral Features in Essentia
For classification, we're going to be using new features in our arsenal: spectral moments (centroid, bandwidth, skewness, kurtosis) and other spectral statistics.
[Moments](https://en.wikipedia.org/wiki/Moment_(mathematics) is a term used in physics and statistics. There are raw moments and central moments. 
You are probably already familiar with two examples of moments: mean and variance. 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 in Essentia, we will use essentia.standard.Centroid:
End of explanation
"""


sum((X/sum(X))*numpy.linspace(0, 1, len(X)))

"""
Explanation: 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:
End of explanation
"""


central_moments = ess.CentralMoments()
print central_moments(X)

"""
Explanation: 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:
End of explanation
"""


distributionshape = ess.DistributionShape()
spectral_moments = distributionshape(central_moments(X))
print spectral_moments

"""
Explanation: essentia.standard.DistributionShape
To compute the spectral spread, skewness, and kurtosis, we use essentia.standard.DistributionShape:
End of explanation
"""


