本文整理匯總了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
示例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)
示例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)
示例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))
示例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
示例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
示例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
示例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
示例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
示例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
示例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