Exemplo n.º 1
0
    def get_shannon_index(self, total_bins=8):

        frequency_interval = int(
            np.ceil(1000.0 / (self.fs / float(self.n_fft))))
        bin_probs = []

        i = 0

        psd = (1.0 / self.win_len) * (self.stft**2)
        psd = AudioProcessing.rescale(psd, (0, 1))

        psd_sum = np.sum(psd)

        while i < total_bins * frequency_interval:

            if i + frequency_interval > total_bins * frequency_interval:
                bin = psd[i:, :]
            else:

                bin = psd[i:i + frequency_interval, :]

            bin_probs.append(np.sum(bin))

            i = i + frequency_interval

        bin_probs = np.array(bin_probs)
        bin_probs = bin_probs / psd_sum

        shannon_index = AudioProcessing.get_entropy(bin_probs) / np.log2(
            len(bin_probs))
        return shannon_index
    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
Exemplo n.º 3
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
Exemplo n.º 4
0
    def _get_spectral_entropy(self):

        stft = np.copy(self.stft)
        N = 2**10
        stft = AudioProcessing.rescale(stft, (0, N))
        stft = stft.astype(np.uint16)

        item_frequency = itemfreq(stft)

        total_samples = stft.size

        pmf = []

        for i in range(item_frequency.shape[0]):
            pmf.append(item_frequency[i][1])

        pmf = np.array(pmf)
        pmf = pmf / float(total_samples)

        self.spectral_entropy = AudioProcessing.get_entropy(pmf) / np.log2(N)
Exemplo n.º 5
0
    def _get_temporal_entropy(self):
        envelope = self.envelope[np.nonzero(self.envelope)]
        envelope_energy = envelope**2

        N = 2**10  # (i.e 1024 values of envelope energy possible)

        envelope_energy = AudioProcessing.rescale(envelope_energy, (0, N))
        envelope_energy = envelope_energy.astype(np.uint16)

        item_frequency = itemfreq(envelope_energy)

        total_samples = envelope_energy.size

        pmf = []

        for i in range(item_frequency.shape[0]):
            pmf.append(item_frequency[i][1])

        pmf = np.array(pmf)
        pmf = pmf / float(total_samples)

        self.temporal_entropy = AudioProcessing.get_entropy(pmf) / np.log2(N)