def stft_from_frames(frames, window='hann', dtype=np.complex64):
    """
    Variation of the librosa.core.stft function,
    that computes the short-time-fourier-transfrom from frames instead from the signal.

    See http://librosa.github.io/librosa/_modules/librosa/core/spectrum.html#stft
    """

    win_length = frames.shape[0]
    n_fft = win_length

    fft_window = filters.get_window(window, win_length, fftbins=True)

    # Reshape so that the window can be broadcast
    fft_window = fft_window.reshape((-1, 1))

    # Pre-allocate the STFT matrix
    stft_matrix = np.empty((int(1 + n_fft // 2), frames.shape[1]),
                           dtype=dtype,
                           order='F')

    # how many columns can we fit within MAX_MEM_BLOCK?
    n_columns = int(util.MAX_MEM_BLOCK / (stft_matrix.shape[0] *
                                          stft_matrix.itemsize))

    for bl_s in range(0, stft_matrix.shape[1], n_columns):
        bl_t = min(bl_s + n_columns, stft_matrix.shape[1])

        # RFFT and Conjugate here to match phase from DPWE code
        stft_matrix[:, bl_s:bl_t] = fft.fft(fft_window *
                                            frames[:, bl_s:bl_t],
                                            axis=0)[:stft_matrix.shape[0]].conj()

    return stft_matrix
def stft_from_frames ( frames , window = 'hann' , dtype = np . complex64 ) : win_length = frames . shape [ 0 ] n_fft = win_length fft_window = filters . get_window ( window , win_length , fftbins = True ) fft_window = fft_window . reshape ( ( - 1 , 1 ) ) stft_matrix = np . empty ( ( int ( 1 + n_fft // 2 ) , frames . shape [ 1 ] ) , dtype = dtype , order = 'F' ) n_columns = int ( util . MAX_MEM_BLOCK / ( stft_matrix . shape [ 0 ] * stft_matrix . itemsize ) ) for bl_s in range ( 0 , stft_matrix . shape [ 1 ] , n_columns ) : bl_t = min ( bl_s + n_columns , stft_matrix . shape [ 1 ] ) stft_matrix [ : , bl_s : bl_t ] = fft . fft ( fft_window * frames [ : , bl_s : bl_t ] , axis = 0 ) [ : stft_matrix . shape [ 0 ] ] . conj ( ) return stft_matrix
Variation of the librosa.core.stft function,
    that computes the short-time-fourier-transfrom from frames instead from the signal.

    See http://librosa.github.io/librosa/_modules/librosa/core/spectrum.html#stft