def aggregate_entropy(self): psd = get_psd(self.args) # Entropy of energy in each frequency bin over whole time ebin = np.sum(psd, axis=1) ebin /= np.sum(ebin) return np.sum(-ebin * np.log2(ebin))
def spectral_decrease(self): """ Compute index vector k = [0:size(X,1)-1] k(1) = 1 kinv = 1./k % compute slope vsd = (kinv*(X-repmat(X(1,:),size(X,1),1)))./sum(X(2:end,:),1) % avoid NaN for silence frames vsd (sum(X(2:end,:),1) == 0) = 0 :param self.args: :return: """ psd = get_psd(self.args) k = np.arange(0, psd.shape[0]) k[0] = 1 kinv = 1 / k kinv = kinv.reshape((1, psd.shape[0])) sdecrease = np.matmul(kinv, (psd - psd[0, :])) / np.sum(psd[1:, :], axis=0) return sdecrease
def spectral_flatness(self): psd = get_psd(self.args) nfft, noverlap = unroll_args(self.args, ['nfft', 'noverlap']) hopsize = nfft - noverlap return rosaft.spectral_flatness(y=None, S=psd, n_fft=nfft, hop_length=hopsize)
def total_energy(self): fs, nfft = unroll_args(self.args, ['fs', 'nfft']) psd = get_psd(self.args) # This is a little bit unclear. Eq (6.1) of Raven is the calculation below, but then it says it is in decibels, # which this is not! energy = np.sum(psd) * (fs / nfft) return energy
def spectral_crest(self): """ a.k.a. spectral crest factor: ratio of max freq power over mean spectrum power :param self.args: :return: """ psd = get_psd(self.args) sc = np.max(psd, axis=0) / np.mean(psd, axis=0) return sc
def spectral_rolloff(self): psd = get_psd(self.args) fs, nfft, noverlap = unroll_args(self.args, ['fs', 'nfft', 'noverlap']) hopsize = nfft - noverlap return rosaft.spectral_rolloff(y=None, sr=fs, S=psd, n_fft=nfft, hop_length=hopsize)
def average_entropy(self): psd = get_psd(self.args) # Entropy of each frame (time slice) averaged newsg = (psd.T / np.sum(psd)).T averaged_entropy = np.sum(-newsg * np.log2(newsg), axis=0) averaged_entropy = np.mean(averaged_entropy) return averaged_entropy
def mfc(self): psd = get_psd(self.args) ** 2 fs, nfft, ncep, fmin, fmax = unroll_args(self.args, ['fs', 'nfft', ('ncep', 20), ('fmin', 0.0), ('fmax', None)]) if fmax is None: fmax = fs // 2 # Build a Mel filter mel_basis = _cached_get_mel_filter(sr=fs, n_fft=nfft, n_mels=ncep * 2, fmin=fmin, fmax=fmax) melspect = np.dot(mel_basis, psd) return power_to_db(melspect)
def spectral_contrast(self): psd = get_psd(self.args) fs, nfft, noverlap = unroll_args(self.args, ['fs', 'nfft', 'noverlap']) hopsize = nfft - noverlap if fs < 12800: n_bands = 6 fmin = int(fs / 2.0**(n_bands)) else: fmin = 200 return rosaft.spectral_contrast(y=None, sr=fs, S=psd, n_fft=nfft, hop_length=hopsize, fmin=fmin)
def spectral_kurtosis(self): psd = get_psd(self.args) return kurtosis(psd, axis=0)
def spectral_skewness(self): psd = get_psd(self.args) return skew(psd, axis=0)
def spectral_flux(self): psd = get_psd(self.args) diff = np.pad(np.diff(psd), ((0, 0), (1, 0)), 'constant', constant_values=0) return np.linalg.norm(diff, axis=0)
def spectrum(self): psd = get_psd(self.args) return psd
def frame_entropy(self): psd = get_psd(self.args) # Entropy of each frame (time slice) averaged newsg = (psd.T / np.sum(psd)).T return np.sum(-newsg * np.log2(newsg), axis=0)
def chroma_stft(self): psd = get_psd(self.args) fs, nfft, noverlap = unroll_args(self.args, ['fs', 'nfft', 'noverlap']) hopsize = nfft - noverlap return rosaft.chroma_stft(y=None, sr=fs, S=psd, n_fft=nfft, hop_length=hopsize)