nussl/separation/primitive/repet.py
def compute_beat_spectrum(power_spectrogram):
        """ Computes the beat spectrum averages (over freq's) the autocorrelation matrix of a one-sided spectrogram.

        The autocorrelation matrix is computed by taking the autocorrelation of each row of the spectrogram and
        dismissing the symmetric half.

        Args:
            power_spectrogram (:obj:`np.array`): 2D matrix containing the one-sided power spectrogram of an audio signal
            
        Returns:
            (:obj:`np.array`): array containing the beat spectrum based on the power spectrogram
            
        See Also:
            J Foote's original derivation of the Beat Spectrum: 
            Foote, Jonathan, and Shingo Uchihashi. "The beat spectrum: A new approach to rhythm analysis." 
            Multimedia and Expo, 2001. ICME 2001. IEEE International Conference on. IEEE, 2001.
            (`See PDF here <http://rotorbrain.com/foote/papers/icme2001.pdf>`_)
            
        """
        freq_bins, time_bins = power_spectrogram.shape

        # row-wise autocorrelation according to the Wiener-Khinchin theorem
        power_spectrogram = np.vstack([power_spectrogram, np.zeros_like(power_spectrogram)])

        nearest_power_of_two = 2 ** np.ceil(np.log(power_spectrogram.shape[0]) / np.log(2))
        pad_amount = int(nearest_power_of_two - power_spectrogram.shape[0])
        power_spectrogram = np.pad(power_spectrogram, ((0, pad_amount), (0, 0)), 'constant')
        fft_power_spec = scifft.fft(power_spectrogram, axis=0)
        abs_fft = np.abs(fft_power_spec) ** 2
        autocorrelation_rows = np.real(
            scifft.ifft(abs_fft, axis=0)[:freq_bins, :])  # ifft over columns

        # normalization factor
        norm_factor = np.tile(np.arange(freq_bins, 0, -1), (time_bins, 1)).T
        autocorrelation_rows = autocorrelation_rows / norm_factor

        # compute the beat spectrum
        beat_spectrum = np.mean(autocorrelation_rows, axis=1)
        # average over frequencies

        return beat_spectrum
 Computes the beat spectrum averages (over freq's) the autocorrelation matrix of a one-sided spectrogram.

        The autocorrelation matrix is computed by taking the autocorrelation of each row of the spectrogram and
        dismissing the symmetric half.

        Args:
            power_spectrogram (:obj:`np.array`): 2D matrix containing the one-sided power spectrogram of an audio signal
            
        Returns:
            (:obj:`np.array`): array containing the beat spectrum based on the power spectrogram
            
        See Also:
            J Foote's original derivation of the Beat Spectrum: 
            Foote, Jonathan, and Shingo Uchihashi. "The beat spectrum: A new approach to rhythm analysis." 
            Multimedia and Expo, 2001. ICME 2001. IEEE International Conference on. IEEE, 2001.
            (`See PDF here <http://rotorbrain.com/foote/papers/icme2001.pdf>`_)
            
        
Computes the beat spectrum averages (over freq's) the autocorrelation matrix of a one-sided spectrogram.
The autocorrelation matrix is computed by taking the autocorrelation of each row of the spectrogram and
dismissing the symmetric half.
Computes the beat spectrum averages ( over freq ' s ) the autocorrelation matrix of a one - sided spectrogram . The autocorrelation matrix is computed by taking the autocorrelation of each row of the spectrogram and dismissing the symmetric half .
def compute_beat_spectrum(power_spectrogram):
        freq_bins, time_bins = power_spectrogram.shape
        power_spectrogram = np.vstack([power_spectrogram, np.zeros_like(power_spectrogram)])
        nearest_power_of_two = 2 ** np.ceil(np.log(power_spectrogram.shape[0]) / np.log(2))
        pad_amount = int(nearest_power_of_two - power_spectrogram.shape[0])
        power_spectrogram = np.pad(power_spectrogram, ((0, pad_amount), (0, 0)), 'constant')
        fft_power_spec = scifft.fft(power_spectrogram, axis=0)
        abs_fft = np.abs(fft_power_spec) ** 2
        autocorrelation_rows = np.real(
            scifft.ifft(abs_fft, axis=0)[:freq_bins, :])  
        norm_factor = np.tile(np.arange(freq_bins, 0, -1), (time_bins, 1)).T
        autocorrelation_rows = autocorrelation_rows / norm_factor
        beat_spectrum = np.mean(autocorrelation_rows, axis=1)
        return beat_spectrum
def compute_beat_spectrum ( power_spectrogram ) : freq_bins , time_bins = power_spectrogram . shape power_spectrogram = np . vstack ( [ power_spectrogram , np . zeros_like ( power_spectrogram ) ] ) nearest_power_of_two = 2 ** np . ceil ( np . log ( power_spectrogram . shape [ 0 ] ) / np . log ( 2 ) ) pad_amount = int ( nearest_power_of_two - power_spectrogram . shape [ 0 ] ) power_spectrogram = np . pad ( power_spectrogram , ( ( 0 , pad_amount ) , ( 0 , 0 ) ) , 'constant' ) fft_power_spec = scifft . fft ( power_spectrogram , axis = 0 ) abs_fft = np . abs ( fft_power_spec ) ** 2 autocorrelation_rows = np . real ( scifft . ifft ( abs_fft , axis = 0 ) [ : freq_bins , : ] ) norm_factor = np . tile ( np . arange ( freq_bins , 0 , - 1 ) , ( time_bins , 1 ) ) . T autocorrelation_rows = autocorrelation_rows / norm_factor beat_spectrum = np . mean ( autocorrelation_rows , axis = 1 ) return beat_spectrum
Computes the beat spectrum averages (over freq's) the autocorrelation matrix of a one-sided spectrogram.
Computes the beat spectrum averages ( over freq ' s ) the autocorrelation matrix of a one - sided spectrogram .
""" Computes the beat spectrum averages (over freq's) the autocorrelation matrix of a one-sided spectrogram.

        The autocorrelation matrix is computed by taking the autocorrelation of each row of the spectrogram and
        dismissing the symmetric half.

        Args:
            power_spectrogram (:obj:`np.array`): 2D matrix containing the one-sided power spectrogram of an audio signal
            
        Returns:
            (:obj:`np.array`): array containing the beat spectrum based on the power spectrogram
            
        See Also:
            J Foote's original derivation of the Beat Spectrum: 
            Foote, Jonathan, and Shingo Uchihashi. "The beat spectrum: A new approach to rhythm analysis." 
            Multimedia and Expo, 2001. ICME 2001. IEEE International Conference on. IEEE, 2001.
            (`See PDF here <http://rotorbrain.com/foote/papers/icme2001.pdf>`_)
            
        """ # row-wise autocorrelation according to the Wiener-Khinchin theorem # ifft over columns # normalization factor # compute the beat spectrum # average over frequencies
`np.array`): array containing the beat spectrum based on the power spectrogram
` np . array ` ) : array containing the beat spectrum based on the power spectrogram
(
power_spectrogram
power_spectrogram (
`np.array`): 2D matrix containing the one-sided power spectrogram of an audio signal
` np . array ` ) : 2D matrix containing the one - sided power spectrogram of an audio signal