computes the spectral centroid from the (squared) magnitude spectrum > called by ::ComputeFeature > > @param X: spectrogram (dimension FFTLength X Observations) > @param f_s: sample rate of audio data > > @retval v spectral centroid (in Hz) ======================================================================
0001 %computes the spectral centroid from the (squared) magnitude spectrum 0002 %> called by ::ComputeFeature 0003 %> 0004 %> @param X: spectrogram (dimension FFTLength X Observations) 0005 %> @param f_s: sample rate of audio data 0006 %> 0007 %> @retval v spectral centroid (in Hz) 0008 % ====================================================================== 0009 function [vsc] = FeatureSpectralCentroid (X, f_s) 0010 0011 vsc = ((0:size(X, 1)-1)*X) ./ sum(X, 1); 0012 0013 % avoid NaN for silence frames 0014 vsc (sum(X, 1) == 0) = 0; 0015 0016 % convert from index to Hz 0017 vsc = vsc / (size(X, 1)-1) * f_s / 2; 0018 end