当前位置: 首页>>代码示例>>Python>>正文


Python signal.tukey方法代码示例

本文整理汇总了Python中scipy.signal.tukey方法的典型用法代码示例。如果您正苦于以下问题:Python signal.tukey方法的具体用法?Python signal.tukey怎么用?Python signal.tukey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.signal的用法示例。


在下文中一共展示了signal.tukey方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _make_template

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import tukey [as 别名]
def _make_template(self, crop):
        temp = {}
        temp['raw'] = crop.to(self.device)
        temp['im'] = torch_to_img(crop)

        temp['kernel'] = self._net.featureExtract(temp['raw'])
        temp['reg'] = self._net.conv_r1(temp['kernel'])
        temp['cls'] = self._net.conv_cls1(temp['kernel'])
        t_s = temp['reg'].data.size()[-1]

        temp['reg_anc'] = temp['reg'].view(self._net.anchor*4, self._net.feature_out, t_s, t_s)
        temp['cls_anc'] = temp['cls'].view(self._net.anchor*2, self._net.feature_out, t_s, t_s)

        # add the tukey window to the temp for comparison
        alpha = self._cfg.tukey_alpha
        win = np.outer(tukey(self.kernel_sz, alpha), tukey(self.kernel_sz, alpha))
        temp['compare'] = temp['kernel'] * torch.Tensor(win).to(self.device)
        return temp 
开发者ID:xl-sr,项目名称:THOR,代码行数:20,代码来源:wrapper.py

示例2: test_cw

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import tukey [as 别名]
def test_cw(self):
        self.assertArrayEqual(signal.cw(10000, 0.1, 50000), np.sin(2*np.pi*10000*np.arange(5000, dtype=np.float)/50000), precision=6)
        self.assertArrayEqual(signal.cw(10000, 0.1, 50000, complex_output=True), np.exp(2j*np.pi*10000*np.arange(5000, dtype=np.complex)/50000), precision=6)
        self.assertArrayEqual(signal.cw(10000, 0.1, 50000, ('tukey', 0.1)), sp.tukey(5000, 0.1)*np.sin(2*np.pi*10000*np.arange(5000, dtype=np.float)/50000), precision=2) 
开发者ID:org-arl,项目名称:arlpy,代码行数:6,代码来源:test_basic.py

示例3: test_sweep

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import tukey [as 别名]
def test_sweep(self):
        self.assertArrayEqual(signal.sweep(5000, 10000, 0.1, 50000), sp.chirp(np.arange(5000, dtype=np.float)/50000, 5000, 0.1, 10000, 'linear'))
        self.assertArrayEqual(signal.sweep(5000, 10000, 0.1, 50000, 'hyperbolic'), sp.chirp(np.arange(5000, dtype=np.float)/50000, 5000, 0.1, 10000, 'hyperbolic'))
        self.assertArrayEqual(signal.sweep(5000, 10000, 0.1, 50000, window=('tukey', 0.1)), sp.tukey(5000, 0.1)*sp.chirp(np.arange(5000, dtype=np.float)/50000, 5000, 0.1, 10000), precision=2) 
开发者ID:org-arl,项目名称:arlpy,代码行数:6,代码来源:test_basic.py

示例4: __init__

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import tukey [as 别名]
def __init__(self, sample_rate, window_shift, window_size, nfft, window=tukey):
        self.nfft = nfft
        self.window_size = int(sample_rate * window_size)
        self.window_shift = int(sample_rate * window_shift)
        self.window = torch.FloatTensor(window(self.window_size)) 
开发者ID:jinserk,项目名称:pytorch-asr,代码行数:7,代码来源:dataset.py

示例5: tukey_window

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import tukey [as 别名]
def tukey_window(n_times_atom):
    window = signal.tukey(n_times_atom)
    window[0] = 1e-9
    window[-1] = 1e-9
    return window 
开发者ID:alphacsc,项目名称:alphacsc,代码行数:7,代码来源:dictionary.py

示例6: taper1

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import tukey [as 别名]
def taper1(data):
    '''
    apply a cosine taper using tukey window
    '''
    ndata = np.zeros(shape=data.shape,dtype=data.dtype)
    if data.ndim == 1:
        npts  = data.shape[0]
        win   = signal.tukey(npts,alpha=0.05)
        ndata = data*win
    elif data.ndim == 2:
        npts = data.shape[1]
        win   = signal.tukey(npts,alpha=0.05)
        for ii in range(data.shape[0]):
            ndata[ii] = data[ii]*win
    return ndata 
开发者ID:mdenolle,项目名称:NoisePy,代码行数:17,代码来源:check_detrend_performance.py

示例7: taper

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import tukey [as 别名]
def taper(data):
    '''
    apply a cosine taper using tukey window
    '''
    #ndata = np.zeros(shape=data.shape,dtype=data.dtype)
    if data.ndim == 1:
        npts = data.shape[0]

        # window length 
        if npts*0.05>20:wlen = 20
        else:wlen = npts*0.05
        
        # taper values
        func = _get_function_from_entry_point('taper', 'hann')
        if 2*wlen == npts:
            taper_sides = func(2*wlen)
        else:
            taper_sides = func(2*wlen + 1)

        # taper window
        win  = np.hstack((taper_sides[:wlen], np.ones(npts-2*wlen),taper_sides[len(taper_sides) - wlen:]))
        data = data*win
    elif data.ndim == 2:
        npts = data.shape[1]
    
        # window length 
        if npts*0.05>20:wlen = 20
        else:wlen = npts*0.05
        
        # taper values
        func = _get_function_from_entry_point('taper', 'hann')
        if 2*wlen == npts:
            taper_sides = func(2*wlen)
        else:
            taper_sides = func(2*wlen + 1)

        # taper window
        win  = np.hstack((taper_sides[:wlen], np.ones(npts-2*wlen),taper_sides[len(taper_sides) - wlen:]))
        for ii in range(data.shape[0]):
            data[ii] = data[ii]*win
    return data 
开发者ID:mdenolle,项目名称:NoisePy,代码行数:43,代码来源:check_detrend_performance.py

示例8: clean_up

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import tukey [as 别名]
def clean_up(corr,sampling_rate,freqmin,freqmax):
    if corr.ndim == 2:
        axis = 1
    else:
        axis = 0
    corr = scipy.signal.detrend(corr,axis=axis,type='constant')
    corr = scipy.signal.detrend(corr,axis=axis,type='linear')
    percent = sampling_rate * 20 / corr.shape[axis]
    #taper = scipy.signal.tukey(corr.shape[axis],percent)
    taper = tukey(corr.shape[axis],percent)
    corr *= taper
    corr = bandpass(corr,freqmin,freqmax,sampling_rate,zerophase=True)
    return corr 
开发者ID:mdenolle,项目名称:NoisePy,代码行数:15,代码来源:noise_module.py

示例9: _make_template

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import tukey [as 别名]
def _make_template(self, crop):
        temp = {}
        temp['raw'] = crop.to(self.device)
        temp['im'] = torch_to_img(crop)
        temp['kernel'] = self._net.template(temp['raw'])

        # add the tukey window to the temp for comparison
        alpha = self._cfg.tukey_alpha
        win = np.outer(tukey(self.kernel_sz, alpha), tukey(self.kernel_sz, alpha))
        temp['compare'] = temp['kernel'] * torch.Tensor(win).to(self.device)
        return temp 
开发者ID:lukas-blecher,项目名称:AutoMask,代码行数:13,代码来源:wrapper.py

示例10: split_signal

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import tukey [as 别名]
def split_signal(X, n_splits=1, apply_window=True):
    """Split the signal in ``n_splits`` chunks for faster training.

    This function can be used to accelerate the dictionary learning algorithm
    by creating independent chunks that can be processed in parallel. This can
    bias the estimation and can create border artifacts so the number of chunks
    should be kept as small as possible (`e.g.` equal to ``n_jobs``).

    Also, it is advised to not use the result of this function to
    call the ``DictionaryLearning.transform`` method, as it would return an
    approximate reduction of the original signal in the sparse basis.

    Note that this is a lossy operation, as all chunks will have length
    ``n_times // n_splits`` and the last ``n_times % n_splits`` samples are
    discarded.

    Parameters
    ----------
    X : ndarray, shape (n_channels, n_times)
        Signal to be split. It should be a single signal.
    n_splits : int (default: 1)
        Number of splits to create from the original signal. Default is 1.
    apply_window : bool (default: True)
        If set to True (default), a tukey window is applied to each split to
        reduce the border artifacts by reducing the weights of the chunk
        borders.

    Return
    ------
    X_split: ndarray, shape (n_splits, n_channels, n_times // n_splits)
        The signal splitted in ``n_splits``.
    """
    assert X.ndim == 2, (
        "This splitting utility is only designed for one multivariate "
        "signal (n_channels, n_times). Found X.ndim={}.".format(X.ndim))

    n_splits = int(n_splits)
    assert n_splits > 0, "The number of splits should be large than 0."

    n_channels, n_times = X.shape
    n_times = n_times // n_splits
    X_split = X[:, :n_splits * n_times]
    X_split = X_split.reshape(n_channels, n_splits, n_times).swapaxes(0, 1)

    # Apply a window to the signal to reduce the border artifacts
    if apply_window:
        X_split *= tukey(n_times, alpha=0.1)[None, None, :]

    return X_split 
开发者ID:alphacsc,项目名称:alphacsc,代码行数:51,代码来源:signal.py

示例11: whitening

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import tukey [as 别名]
def whitening(X, ordar=10, block_length=256, sfreq=1., zero_phase=True,
              plot=False, use_fooof=False):
    n_trials, n_channels, n_times = X.shape

    ar_model = Arma(ordar=ordar, ordma=0, fs=sfreq, block_length=block_length)
    ar_model.periodogram(X.reshape(-1, n_times), hold=False, mean_psd=True)

    if use_fooof:  # pragma: no cover
        # Fit the psd with a 1/f^a background model plus a gaussian mixture.
        # We keep only the background model
        # (pip install fooof)
        from fooof import FOOOF
        fm = FOOOF(background_mode='fixed', verbose=False)
        power_spectrum = ar_model.psd[-1][0]
        freqs = np.linspace(0, sfreq / 2.0, len(power_spectrum))

        fm.fit(freqs, power_spectrum, freq_range=None)
        # repete first point, which is f_0
        bg_fit = np.r_[fm._bg_fit[0], fm._bg_fit][None, :]
        ar_model.psd.append(np.power(10, bg_fit))

    if zero_phase:
        ar_model.psd[-1] = np.sqrt(ar_model.psd[-1])
    ar_model.estimate()

    # apply the whitening for zero-phase filtering
    X_white = apply_whitening(ar_model, X, zero_phase=zero_phase, mode='same')
    assert X_white.shape == X.shape

    # removes edges
    n_times_white = X_white.shape[-1]
    X_white *= signal.tukey(n_times_white,
                            alpha=3 / float(n_times_white))[None, None, :]

    if plot:  # pragma: no cover
        import matplotlib.pyplot as plt
        # plot the Power Spectral Density (PSD) before/after
        ar_model.arma2psd(hold=True)
        if zero_phase:
            ar_model.psd[-2] **= 2
            ar_model.psd[-1] **= 2
        ar_model.periodogram(
            X_white.reshape(-1, n_times), hold=True, mean_psd=True)
        labels = ['signal', 'model AR', 'signal white']
        if use_fooof:
            labels = ['signal', 'FOOOF fit', 'model AR', 'signal white']
        ar_model.plot('periodogram before/after whitening',
                      labels=labels, fscale='lin')
        plt.legend(loc='lower left')

    return ar_model, X_white 
开发者ID:alphacsc,项目名称:alphacsc,代码行数:53,代码来源:whitening.py


注:本文中的scipy.signal.tukey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。