當前位置: 首頁>>代碼示例>>Python>>正文


Python windows.hann方法代碼示例

本文整理匯總了Python中scipy.signal.windows.hann方法的典型用法代碼示例。如果您正苦於以下問題:Python windows.hann方法的具體用法?Python windows.hann怎麽用?Python windows.hann使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.signal.windows的用法示例。


在下文中一共展示了windows.hann方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _stft

# 需要導入模塊: from scipy.signal import windows [as 別名]
# 或者: from scipy.signal.windows import hann [as 別名]
def _stft(self, data, inverse=False, length=None):
        """
        Single entrypoint for both stft and istft. This computes stft and istft with librosa on stereo data. The two
        channels are processed separately and are concatenated together in the result. The expected input formats are:
        (n_samples, 2) for stft and (T, F, 2) for istft.
        :param data: np.array with either the waveform or the complex spectrogram depending on the parameter inverse
        :param inverse: should a stft or an istft be computed.
        :return: Stereo data as numpy array for the transform. The channels are stored in the last dimension
        """
        assert not (inverse and length is None)
        data = np.asfortranarray(data)
        N = self._params["frame_length"]
        H = self._params["frame_step"]
        win = hann(N, sym=False)
        fstft = istft if inverse else stft
        win_len_arg = {"win_length": None, "length": length} if inverse else {"n_fft": N}
        n_channels = data.shape[-1]
        out = []
        for c in range(n_channels):
            d = data[:, :, c].T if inverse else data[:, c]
            s = fstft(d, hop_length=H, window=win, center=False, **win_len_arg)
            s = np.expand_dims(s.T, 2-inverse)
            out.append(s)
        if len(out) == 1:
            return out[0]
        return np.concatenate(out, axis=2-inverse) 
開發者ID:deezer,項目名稱:spleeter,代碼行數:28,代碼來源:separator.py

示例2: test_basic

# 需要導入模塊: from scipy.signal import windows [as 別名]
# 或者: from scipy.signal.windows import hann [as 別名]
def test_basic(self):
        assert_allclose(windows.hann(6, sym=False),
                        [0, 0.25, 0.75, 1.0, 0.75, 0.25])
        assert_allclose(windows.hann(7, sym=False),
                        [0, 0.1882550990706332, 0.6112604669781572,
                         0.9504844339512095, 0.9504844339512095,
                         0.6112604669781572, 0.1882550990706332])
        assert_allclose(windows.hann(6, True),
                        [0, 0.3454915028125263, 0.9045084971874737,
                         0.9045084971874737, 0.3454915028125263, 0])
        assert_allclose(windows.hann(7),
                        [0, 0.25, 0.75, 1.0, 0.75, 0.25, 0]) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:14,代碼來源:test_windows.py

示例3: test_extremes

# 需要導入模塊: from scipy.signal import windows [as 別名]
# 或者: from scipy.signal.windows import hann [as 別名]
def test_extremes(self):
        # Test extremes of alpha correspond to boxcar and hann
        tuk0 = windows.tukey(100, 0)
        box0 = windows.boxcar(100)
        assert_array_almost_equal(tuk0, box0)

        tuk1 = windows.tukey(100, 1)
        han1 = windows.hann(100)
        assert_array_almost_equal(tuk1, han1) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:11,代碼來源:test_windows.py

示例4: test_invalid_inputs

# 需要導入模塊: from scipy.signal import windows [as 別名]
# 或者: from scipy.signal.windows import hann [as 別名]
def test_invalid_inputs(self):
        # Window is not a float, tuple, or string
        assert_raises(ValueError, windows.get_window, set('hann'), 8)

        # Unknown window type error
        assert_raises(ValueError, windows.get_window, 'broken', 4) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:8,代碼來源:test_windows.py

示例5: test_deprecation

# 需要導入模塊: from scipy.signal import windows [as 別名]
# 或者: from scipy.signal.windows import hann [as 別名]
def test_deprecation():
    if dep_hann.__doc__ is not None:  # can be None with `-OO` mode
        assert_('signal.hann is deprecated' in dep_hann.__doc__)
        assert_('deprecated' not in windows.hann.__doc__) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:6,代碼來源:test_windows.py

示例6: nlfer

# 需要導入模塊: from scipy.signal import windows [as 別名]
# 或者: from scipy.signal.windows import hann [as 別名]
def nlfer(signal, pitch, parameters):

    #---------------------------------------------------------------
    # Set parameters.
    #---------------------------------------------------------------
    N_f0_min = np.around((parameters['f0_min']*2/float(signal.new_fs))*pitch.nfft)
    N_f0_max = np.around((parameters['f0_max']/float(signal.new_fs))*pitch.nfft)

    window = hann(pitch.frame_size+2)[1:-1]
    data = np.zeros((signal.size))  #Needs other array, otherwise stride and
    data[:] = signal.filtered     #windowing will modify signal.filtered

    #---------------------------------------------------------------
    # Main routine.
    #---------------------------------------------------------------
    samples = np.arange(int(np.fix(float(pitch.frame_size)/2)),
                        signal.size-int(np.fix(float(pitch.frame_size)/2)),
                        pitch.frame_jump)

    data_matrix = np.empty((len(samples), pitch.frame_size))
    data_matrix[:, :] = stride_matrix(data, len(samples),
                                    pitch.frame_size, pitch.frame_jump)
    data_matrix *= window

    specData = np.fft.rfft(data_matrix, pitch.nfft)

    frame_energy = np.abs(specData[:, int(N_f0_min-1):int(N_f0_max)]).sum(axis=1)
    pitch.set_energy(frame_energy, parameters['nlfer_thresh1'])
    pitch.set_frames_pos(samples) 
開發者ID:bjbschmitt,項目名稱:AMFM_decompy,代碼行數:31,代碼來源:pYAAPT.py

示例7: lagged_coherence_1freq

# 需要導入模塊: from scipy.signal import windows [as 別名]
# 或者: from scipy.signal.windows import hann [as 別名]
def lagged_coherence_1freq(sig, fs, freq, n_cycles):
    """Compute the lagged coherence of a frequency using the hanning-taper FFT method.

    Parameters
    ----------
    sig : 1d array
        Time series.
    fs : float
        Sampling rate, in Hz.
    freq : float
        The frequency at which to estimate lagged coherence.
    n_cycles : float
        Number of cycles at the examined frequency to use to compute lagged coherence.

    Returns
    -------
    float
        The computed lagged coherence value.
    """

    # Determine number of samples to be used in each window to compute lagged coherence
    n_samps = int(np.ceil(n_cycles * fs / freq))

    # Split the signal into chunks
    chunks = split_signal(sig, n_samps)
    n_chunks = len(chunks)

    # For each chunk, calculate the Fourier coefficients at the frequency of interest
    hann_window = hann(n_samps)
    fft_freqs = np.fft.fftfreq(n_samps, 1 / float(fs))
    fft_freqs_idx = np.argmin(np.abs(fft_freqs - freq))

    fft_coefs = np.zeros(n_chunks, dtype=complex)
    for ind, chunk in enumerate(chunks):
        fourier_coef = np.fft.fft(chunk * hann_window)
        fft_coefs[ind] = fourier_coef[fft_freqs_idx]

    # Compute the lagged coherence value
    lcs_num = 0
    for ind in range(n_chunks - 1):
        lcs_num += fft_coefs[ind] * np.conj(fft_coefs[ind + 1])
    lcs_denom = np.sqrt(np.sum(np.abs(fft_coefs[:-1])**2) * np.sum(np.abs(fft_coefs[1:])**2))

    return np.abs(lcs_num / lcs_denom) 
開發者ID:neurodsp-tools,項目名稱:neurodsp,代碼行數:46,代碼來源:lc.py


注:本文中的scipy.signal.windows.hann方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。