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


Python signal.kaiser方法代碼示例

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


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

示例1: kaiserbessel_window

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import kaiser [as 別名]
def kaiserbessel_window(X, alpha=6.5):
    """
    Apply a Kaiser-Bessel window to X.

    Parameters
    ----------
    X : ndarray, shape=(n_samples, n_features)
        Input array of samples

    alpha : float, optional (default=6.5)
        Tuning parameter for Kaiser-Bessel function. alpha=6.5 should make
        perfect reconstruction possible for DCT.

    Returns
    -------
    X_windowed : ndarray, shape=(n_samples, n_features)
        Windowed version of X.
    """
    beta = np.pi * alpha
    win = sg.kaiser(X.shape[1], beta)
    row_stride = 0
    col_stride = win.itemsize
    strided_win = as_strided(win, shape=X.shape,
                             strides=(row_stride, col_stride))
    return X * strided_win 
開發者ID:kastnerkyle,項目名稱:tools,代碼行數:27,代碼來源:audio_tools.py

示例2: apply_kaiserbessel_window

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import kaiser [as 別名]
def apply_kaiserbessel_window(X, alpha=6.5):
    """
    Apply a Kaiser-Bessel window to X.

    Parameters
    ----------
    X : ndarray, shape=(n_samples, n_features)
        Input array of samples

    alpha : float, optional (default=6.5)
        Tuning parameter for Kaiser-Bessel function. alpha=6.5 should make
        perfect reconstruction possible for MDCT.

    Returns
    -------
    X_windowed : ndarray, shape=(n_samples, n_features)
        Windowed version of X.
    """
    beta = np.pi * alpha
    win = sg.kaiser(X.shape[1], beta)
    row_stride = 0
    col_stride = win.itemsize
    strided_win = as_strided(win, shape=X.shape,
                             strides=(row_stride, col_stride))
    return X * strided_win 
開發者ID:dagbldr,項目名稱:dagbldr,代碼行數:27,代碼來源:preprocessing_utils.py

示例3: firwin_kaiser_lpf

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import kaiser [as 別名]
def firwin_kaiser_lpf(f_pass, f_stop, d_stop, fs = 1.0, N_bump=0):
    """
    Design an FIR lowpass filter using the sinc() kernel and
    a Kaiser window. The filter order is determined based on 
    f_pass Hz, f_stop Hz, and the desired stopband attenuation
    d_stop in dB, all relative to a sampling rate of fs Hz.
    Note: the passband ripple cannot be set independent of the
    stopband attenuation.

    Mark Wickert October 2016
    """
    wc = 2*np.pi*(f_pass + f_stop)/2/fs
    delta_w = 2*np.pi*(f_stop - f_pass)/fs
    # Find the filter order
    M = np.ceil((d_stop - 8)/(2.285*delta_w))
    # Adjust filter order up or down as needed
    M += N_bump
    N_taps = M + 1
    # Obtain the Kaiser window
    beta = signal.kaiser_beta(d_stop)
    w_k = signal.kaiser(N_taps,beta)
    n = np.arange(N_taps)
    b_k = wc/np.pi*np.sinc(wc/np.pi*(n-M/2)) * w_k
    b_k /= np.sum(b_k)
    print('Kaiser Win filter taps = %d.' % N_taps)
    return b_k 
開發者ID:mwickert,項目名稱:scikit-dsp-comm,代碼行數:28,代碼來源:fir_design_helper.py

示例4: firwin_kaiser_hpf

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import kaiser [as 別名]
def firwin_kaiser_hpf(f_stop, f_pass, d_stop, fs = 1.0, N_bump=0):
    """
    Design an FIR highpass filter using the sinc() kernel and
    a Kaiser window. The filter order is determined based on 
    f_pass Hz, f_stop Hz, and the desired stopband attenuation
    d_stop in dB, all relative to a sampling rate of fs Hz.
    Note: the passband ripple cannot be set independent of the
    stopband attenuation.

    Mark Wickert October 2016
    """
    # Transform HPF critical frequencies to lowpass equivalent
    f_pass_eq = fs/2. - f_pass
    f_stop_eq = fs/2. - f_stop
    # Design LPF equivalent
    wc = 2*np.pi*(f_pass_eq + f_stop_eq)/2/fs
    delta_w = 2*np.pi*(f_stop_eq - f_pass_eq)/fs
    # Find the filter order
    M = np.ceil((d_stop - 8)/(2.285*delta_w))
    # Adjust filter order up or down as needed
    M += N_bump
    N_taps = M + 1
    # Obtain the Kaiser window
    beta = signal.kaiser_beta(d_stop)
    w_k = signal.kaiser(N_taps,beta)
    n = np.arange(N_taps)
    b_k = wc/np.pi*np.sinc(wc/np.pi*(n-M/2)) * w_k
    b_k /= np.sum(b_k)
    # Transform LPF equivalent to HPF
    n = np.arange(len(b_k))
    b_k *= (-1)**n
    print('Kaiser Win filter taps = %d.' % N_taps)
    return b_k 
開發者ID:mwickert,項目名稱:scikit-dsp-comm,代碼行數:35,代碼來源:fir_design_helper.py

示例5: firwin_kaiser_bpf

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import kaiser [as 別名]
def firwin_kaiser_bpf(f_stop1, f_pass1, f_pass2, f_stop2, d_stop, 
                      fs = 1.0, N_bump=0):
    """
    Design an FIR bandpass filter using the sinc() kernel and
    a Kaiser window. The filter order is determined based on 
    f_stop1 Hz, f_pass1 Hz, f_pass2 Hz, f_stop2 Hz, and the 
    desired stopband attenuation d_stop in dB for both stopbands,
    all relative to a sampling rate of fs Hz.
    Note: the passband ripple cannot be set independent of the
    stopband attenuation.

    Mark Wickert October 2016    
    """
    # Design BPF starting from simple LPF equivalent
    # The upper and lower stopbands are assumed to have 
    # the same attenuation level. The LPF equivalent critical
    # frequencies:
    f_pass = (f_pass2 - f_pass1)/2
    f_stop = (f_stop2 - f_stop1)/2
    # Continue to design equivalent LPF
    wc = 2*np.pi*(f_pass + f_stop)/2/fs
    delta_w = 2*np.pi*(f_stop - f_pass)/fs
    # Find the filter order
    M = np.ceil((d_stop - 8)/(2.285*delta_w))
    # Adjust filter order up or down as needed
    M += N_bump
    N_taps = M + 1
    # Obtain the Kaiser window
    beta = signal.kaiser_beta(d_stop)
    w_k = signal.kaiser(N_taps,beta)
    n = np.arange(N_taps)
    b_k = wc/np.pi*np.sinc(wc/np.pi*(n-M/2)) * w_k
    b_k /= np.sum(b_k)
    # Transform LPF to BPF
    f0 = (f_pass2 + f_pass1)/2
    w0 = 2*np.pi*f0/fs
    n = np.arange(len(b_k))
    b_k_bp = 2*b_k*np.cos(w0*(n-M/2))
    print('Kaiser Win filter taps = %d.' % N_taps)
    return b_k_bp 
開發者ID:mwickert,項目名稱:scikit-dsp-comm,代碼行數:42,代碼來源:fir_design_helper.py

示例6: kaiser_derived

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import kaiser [as 別名]
def kaiser_derived(M, beta):
    """ Return a Kaiser-Bessel derived window.

    Parameters
    ----------
    M : int
        Number of points in the output window. If zero or less, an empty
        array is returned.
    beta : float
        Kaiser-Bessel window shape parameter.

    Returns
    -------
    w : ndarray
        The window, normalized to fulfil the Princen-Bradley condition.

    Notes
    -----
    This window is only defined for an even number of taps.

    References
    ----------
    .. [1] Wikipedia, "Kaiser window",
           https://en.wikipedia.org/wiki/Kaiser_window

    """
    M = int(M)
    try:
        from scipy.signal import kaiser_derived as scipy_kd
        return scipy_kd(M, beta)
    except ImportError:
        pass

    if M < 1:
        return np.array([])

    if M % 2:
        raise ValueError(
            "Kaiser Bessel Derived windows are only defined for even number "
            "of taps"
        )

    w = np.zeros(M)
    kaiserw = kaiser(M // 2 + 1, beta)
    csum = np.cumsum(kaiserw)
    halfw = np.sqrt(csum[:-1] / csum[-1])
    w[:M//2] = halfw
    w[-M//2:] = halfw[::-1]

    return w 
開發者ID:nils-werner,項目名稱:mdct,代碼行數:52,代碼來源:windows.py

示例7: firwin_kaiser_bsf

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import kaiser [as 別名]
def firwin_kaiser_bsf(f_stop1, f_pass1, f_pass2, f_stop2, d_stop, 
                  fs = 1.0, N_bump=0):
    """
    Design an FIR bandstop filter using the sinc() kernel and
    a Kaiser window. The filter order is determined based on 
    f_stop1 Hz, f_pass1 Hz, f_pass2 Hz, f_stop2 Hz, and the 
    desired stopband attenuation d_stop in dB for both stopbands,
    all relative to a sampling rate of fs Hz.
    Note: The passband ripple cannot be set independent of the
    stopband attenuation.
    Note: The filter order is forced to be even (odd number of taps)
    so there is a center tap that can be used to form 1 - H_BPF.

    Mark Wickert October 2016    
    """
    # First design a BPF starting from simple LPF equivalent
    # The upper and lower stopbands are assumed to have 
    # the same attenuation level. The LPF equivalent critical
    # frequencies:
    f_pass = (f_pass2 - f_pass1)/2
    f_stop = (f_stop2 - f_stop1)/2
    # Continue to design equivalent LPF
    wc = 2*np.pi*(f_pass + f_stop)/2/fs
    delta_w = 2*np.pi*(f_stop - f_pass)/fs
    # Find the filter order
    M = np.ceil((d_stop - 8)/(2.285*delta_w))
    # Adjust filter order up or down as needed
    M += N_bump
    # Make filter order even (odd number of taps)
    if ((M+1)/2.0-int((M+1)/2.0)) == 0:
        M += 1
    N_taps = M + 1
    # Obtain the Kaiser window
    beta = signal.kaiser_beta(d_stop)
    w_k = signal.kaiser(N_taps,beta)
    n = np.arange(N_taps)
    b_k = wc/np.pi*np.sinc(wc/np.pi*(n-M/2)) * w_k
    b_k /= np.sum(b_k)
    # Transform LPF to BPF
    f0 = (f_pass2 + f_pass1)/2
    w0 = 2*np.pi*f0/fs
    n = np.arange(len(b_k))
    b_k_bs = 2*b_k*np.cos(w0*(n-M/2))
    # Transform BPF to BSF via 1 - BPF for odd N_taps
    b_k_bs = -b_k_bs
    b_k_bs[int(M/2)] += 1 
    print('Kaiser Win filter taps = %d.' % N_taps)
    return b_k_bs 
開發者ID:mwickert,項目名稱:scikit-dsp-comm,代碼行數:50,代碼來源:fir_design_helper.py

示例8: compute_freq_bands

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import kaiser [as 別名]
def compute_freq_bands(self, y):
        """
        Compute FFT using a kaiser window over a series of data points of
        length window_size.

        The Kaiser window can approximate many other windows by varying
        the beta parameter.

        beta  |  Window shape
        ------------------------------
        0	  |  Rectangular
        5	  |  Similar to a Hamming
        6	  |  Similar to a Hann
        8.6	  |  Similar to a Blackman

        A beta value of 14 is probably a good starting point.
        Note that as beta gets large, the window narrows, and so the number
        of samples needs
        to be large enough to sample the increasingly narrow spike,
        otherwise NaNs will get returned.

        More here:
        http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/
        scipy.signal.kaiser.html

        :param y: (numpy.Array) array of floats. Frequency bands will be
            extracted from this data.
        """

        # make sure the number of data points to analyze is equal to window size
        assert len(y) == self.window_size

        w = kaiser(self.window_size, beta=14)
        ywf = fft(y * w)

        freqs = np.fft.fftfreq(self.window_size, d=1. / self.sampling_frequency)

        bands = {}
        for (name, freq_range) in self.frequency_bands.items():
            bands[name] = np.sum(np.abs(ywf[(freqs >= freq_range[0])
                                            & (freqs < freq_range[1])]))

        return bands 
開發者ID:marionleborgne,項目名稱:cloudbrain,代碼行數:45,代碼來源:fft.py


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