def stSpectralCentroidAndSpread(X, fs):
 ind = (numpy.arange(1, (len(X) + 1)) * (fs / (2.0 * len(X))))
 Xt = X.copy()
 Xt = (Xt / Xt.max())
 NUM = numpy.sum((ind * Xt))
 DEN = (numpy.sum(Xt) + eps)
 C = (NUM / DEN)
 S = numpy.sqrt((numpy.sum((((ind - C) ** 2) * Xt)) / DEN))
 C = (C / (fs / 2.0))
 S = (S / (fs / 2.0))
 return (C, S)

def stSpectralCentroidAndSpread ( X , fs ) : ind = ( numpy . arange ( 1 , ( len ( X ) + 1 ) ) * ( fs / ( 2.0 * len ( X ) ) ) ) Xt = X . copy ( ) Xt = ( Xt / Xt . max ( ) ) NUM = numpy . sum ( ( ind * Xt ) ) DEN = ( numpy . sum ( Xt ) + eps ) C = ( NUM / DEN ) S = numpy . sqrt ( ( numpy . sum ( ( ( ( ind - C ) ** 2 ) * Xt ) ) / DEN ) ) C = ( C / ( fs / 2.0 ) ) S = ( S / ( fs / 2.0 ) ) return ( C , S )
computes spectral centroid of frame (given abs) .