def get_spectral_average_variance_entropy(self):

        segments_stft = None

        N = 2**10

        stft = np.copy(self.stft)
        # stft = AudioProcessing.rescale(self.stft,(0,N))
        # stft = stft.astype(np.uint16)

        for segment in self.segments:
            start = int(float(segment[0]) / self.n_fft)
            stop = int(float(segment[1]) / self.n_fft)

            if segments_stft is None:
                segments_stft = stft[:, start:stop]
            else:
                segments_stft = np.concatenate(
                    (segments_stft, stft[:, start:stop]), axis=1)

        average_spectra = np.mean(segments_stft, axis=1)
        var_spectra = np.var(segments_stft, axis=1)

        N = 2**8
        average_spectra = AudioProcessing.rescale(average_spectra, (0, N))
        average_spectra = average_spectra.astype(np.uint8)

        var_spectra = AudioProcessing.rescale(var_spectra, (0, N))
        var_spectra = var_spectra.astype(np.uint8)

        avg_pdf, bins = AudioProcessing.get_histogram(average_spectra,
                                                      bins=np.arange(0, 255))
        var_pdf, bins = AudioProcessing.get_histogram(var_spectra,
                                                      bins=np.arange(0, 255))

        avg_pdf = avg_pdf[np.nonzero(avg_pdf)]
        var_pdf = var_pdf[np.nonzero(var_pdf)]

        average_spectrum_entropy = AudioProcessing.get_entropy(
            avg_pdf) / np.log2(N)
        variance_spectrum_entropy = AudioProcessing.get_entropy(
            var_pdf) / np.log2(N)

        return average_spectrum_entropy, variance_spectrum_entropy
Beispiel #2
0
    def get_spectral_maxima_entropy(self):
        max_bins = []

        for segment in self.segments:
            start = int(float(segment[0]) / self.n_fft)
            stop = int(float(segment[1]) / self.n_fft)

            for i in range(start, stop + 1):
                stft_column = self.stft[:, i]
                max_bins.append(np.argmax(stft_column))

        pdf, bins = AudioProcessing.get_histogram(max_bins,
                                                  bins=np.arange(
                                                      0, self.stft.shape[0]))

        pdf = pdf[np.nonzero(pdf)]
        spectral_max_entropy = AudioProcessing.get_entropy(pdf) / np.log2(
            self.stft.shape[0])

        return spectral_max_entropy