本文整理汇总了Python中scipy.signal.get_window方法的典型用法代码示例。如果您正苦于以下问题:Python signal.get_window方法的具体用法?Python signal.get_window怎么用?Python signal.get_window使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.signal
的用法示例。
在下文中一共展示了signal.get_window方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_psd
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def test_psd():
n_channels, n_times = data.shape
_data = data[None, ...]
# Only test output shape when `method='welch'` or `method='multitaper'`
# since it is actually just a wrapper for MNE functions:
psd_welch, _ = power_spectrum(sfreq, _data, psd_method='welch')
psd_multitaper, _ = power_spectrum(sfreq, _data, psd_method='multitaper')
psd_fft, freqs_fft = power_spectrum(sfreq, _data, psd_method='fft')
assert_equal(psd_welch.shape, (1, n_channels, n_times // 2 + 1))
assert_equal(psd_multitaper.shape, (1, n_channels, n_times // 2 + 1))
assert_equal(psd_fft.shape, (1, n_channels, n_times // 2 + 1))
# Compare result obtained with `method='fft'` to the Scipy's result
# (implementation of Welch's method with rectangular window):
expected_freqs, expected_psd = signal.welch(data, sfreq,
window=signal.get_window(
'boxcar', data.shape[-1]),
return_onesided=True,
scaling='density')
assert_almost_equal(expected_freqs, freqs_fft)
assert_almost_equal(expected_psd, psd_fft[0, ...])
示例2: test_window_external
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def test_window_external(self):
x = np.zeros(16)
x[0] = 1
x[8] = 1
f, p = welch(x, 10, 'hann', nperseg=8)
win = signal.get_window('hann', 8)
fe, pe = welch(x, 10, win, nperseg=None)
assert_array_almost_equal_nulp(p, pe)
assert_array_almost_equal_nulp(f, fe)
assert_array_equal(fe.shape, (5,)) # because win length used as nperseg
assert_array_equal(pe.shape, (5,))
assert_raises(ValueError, welch, x,
10, win, nperseg=4) # because nperseg != win.shape[-1]
win_err = signal.get_window('hann', 32)
assert_raises(ValueError, welch, x,
10, win_err, nperseg=None) # win longer than signal
示例3: cw
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def cw(fc, duration, fs, window=None, complex_output=False):
"""Generate a sinusoidal pulse.
:param fc: frequency of the pulse in Hz
:param duration: duration of the pulse in s
:param fs: sampling rate in Hz
:param window: window function to use (``None`` means rectangular window)
:param complex_output: True to return complex signal, False for a real signal
For supported window functions, see documentation for :func:`scipy.signal.get_window`.
>>> import arlpy
>>> x1 = arlpy.signal.cw(fc=27000, duration=0.5, fs=250000)
>>> x2 = arlpy.signal.cw(fc=27000, duration=0.5, fs=250000, window='hamming')
>>> x3 = arlpy.signal.cw(fc=27000, duration=0.5, fs=250000, window=('kaiser', 4.0))
"""
n = int(round(duration*fs))
x = _np.exp(2j*_np.pi*fc*time(n, fs)) if complex_output else _np.sin(2*_np.pi*fc*time(n, fs))
if window is not None:
w = _sig.get_window(window, n, False)
x *= w
return x
示例4: sweep
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def sweep(f1, f2, duration, fs, method='linear', window=None):
"""Generate frequency modulated sweep.
:param f1: starting frequency in Hz
:param f2: ending frequency in Hz
:param duration: duration of the pulse in s
:param fs: sampling rate in Hz
:param method: type of sweep (``'linear'``, ``'quadratic'``, ``'logarithmic'``, ``'hyperbolic'``)
:param window: window function to use (``None`` means rectangular window)
For supported window functions, see documentation for :func:`scipy.signal.get_window`.
>>> import arlpy
>>> x1 = arlpy.signal.sweep(20000, 30000, duration=0.5, fs=250000)
>>> x2 = arlpy.signal.sweep(20000, 30000, duration=0.5, fs=250000, window='hamming')
>>> x2 = arlpy.signal.sweep(20000, 30000, duration=0.5, fs=250000, window=('kaiser', 4.0))
"""
n = int(round(duration*fs))
x = _sig.chirp(time(n, fs), f1, duration, f2, method)
if window is not None:
w = _sig.get_window(window, n, False)
x *= w
return x
示例5: __init__
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def __init__(self,
alpha=0.92,
alpha_s=0.9,
alpha_d=0.85,
b_min=1.66,
gamma0=4.6,
gamma1=3,
zeta0=1.67,
xi_min_db=-18,
gmin_db=-10,
w_mcra=1,
h_mcra="hann",
beta=1.47,
V=15,
U=8):
self.alpha = {"s": alpha_s, "d": alpha_d, "t": alpha}
self.beta = beta
self.gamma0, self.gamma1 = gamma0, gamma1
self.zeta0 = zeta0
self.b_min = 1 / b_min
self.xi_min = 10**(xi_min_db / 10)
self.gain_min = 10**(gmin_db / 10)
self.w_m = ss.get_window(h_mcra, w_mcra * 2 + 1)
self.V = V
self.U = U
示例6: _prep_window
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def _prep_window(self, **kwargs):
"""
Provide validation for our window type, return the window
we have already been validated.
"""
window = self._get_window()
if isinstance(window, (list, tuple, np.ndarray)):
return com.asarray_tuplesafe(window).astype(float)
elif is_integer(window):
import scipy.signal as sig
# the below may pop from kwargs
def _validate_win_type(win_type, kwargs):
arg_map = {'kaiser': ['beta'],
'gaussian': ['std'],
'general_gaussian': ['power', 'width'],
'slepian': ['width']}
if win_type in arg_map:
return tuple([win_type] + _pop_args(win_type,
arg_map[win_type],
kwargs))
return win_type
def _pop_args(win_type, arg_names, kwargs):
msg = '%s window requires %%s' % win_type
all_args = []
for n in arg_names:
if n not in kwargs:
raise ValueError(msg % n)
all_args.append(kwargs.pop(n))
return all_args
win_type = _validate_win_type(self.win_type, kwargs)
# GH #15662. `False` makes symmetric window, rather than periodic.
return sig.get_window(win_type, window, False).astype(float)
示例7: _prep_window
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def _prep_window(self, **kwargs):
"""
provide validation for our window type, return the window
we have already been validated
"""
window = self._get_window()
if isinstance(window, (list, tuple, np.ndarray)):
return com._asarray_tuplesafe(window).astype(float)
elif is_integer(window):
import scipy.signal as sig
# the below may pop from kwargs
def _validate_win_type(win_type, kwargs):
arg_map = {'kaiser': ['beta'],
'gaussian': ['std'],
'general_gaussian': ['power', 'width'],
'slepian': ['width']}
if win_type in arg_map:
return tuple([win_type] + _pop_args(win_type,
arg_map[win_type],
kwargs))
return win_type
def _pop_args(win_type, arg_names, kwargs):
msg = '%s window requires %%s' % win_type
all_args = []
for n in arg_names:
if n not in kwargs:
raise ValueError(msg % n)
all_args.append(kwargs.pop(n))
return all_args
win_type = _validate_win_type(self.win_type, kwargs)
# GH #15662. `False` makes symmetric window, rather than periodic.
return sig.get_window(win_type, window, False).astype(float)
示例8: __init__
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def __init__(self, filter_length=800, hop_length=200, win_length=800,
window='hann'):
super(STFT, self).__init__()
self.filter_length = filter_length
self.hop_length = hop_length
self.win_length = win_length
self.window = window
self.forward_transform = None
scale = self.filter_length / self.hop_length
fourier_basis = np.fft.fft(np.eye(self.filter_length))
cutoff = int((self.filter_length / 2 + 1))
fourier_basis = np.vstack([np.real(fourier_basis[:cutoff, :]),
np.imag(fourier_basis[:cutoff, :])])
forward_basis = torch.FloatTensor(fourier_basis[:, None, :])
inverse_basis = torch.FloatTensor(
np.linalg.pinv(scale * fourier_basis).T[:, None, :])
if window is not None:
assert(filter_length >= win_length)
# get window and zero center pad it to filter_length
fft_window = get_window(window, win_length, fftbins=True)
fft_window = pad_center(fft_window, filter_length)
fft_window = torch.from_numpy(fft_window).float()
# window the bases
forward_basis *= fft_window
inverse_basis *= fft_window
self.register_buffer('forward_basis', forward_basis.float())
self.register_buffer('inverse_basis', inverse_basis.float())
示例9: test_window_external
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def test_window_external(self):
x = np.zeros(16)
x[0] = 1
f, p = periodogram(x, 10, 'hanning')
win = signal.get_window('hanning', 16)
fe, pe = periodogram(x, 10, win)
assert_array_almost_equal_nulp(p, pe)
assert_array_almost_equal_nulp(f, fe)
示例10: test_boxcar
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def test_boxcar(self):
w = signal.get_window('boxcar', 12)
assert_array_equal(w, np.ones_like(w))
示例11: test_cheb_odd
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def test_cheb_odd(self):
w = signal.get_window(('chebwin', -40), 53, fftbins=False)
assert_array_almost_equal(w, cheb_odd_true, decimal=4)
示例12: test_cheb_even
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def test_cheb_even(self):
w = signal.get_window(('chebwin', -40), 54, fftbins=False)
assert_array_almost_equal(w, cheb_even_true, decimal=4)
示例13: test_boxcar
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def test_boxcar(self):
w = windows.get_window('boxcar', 12)
assert_array_equal(w, np.ones_like(w))
# window is a tuple of len 1
w = windows.get_window(('boxcar',), 16)
assert_array_equal(w, np.ones_like(w))
示例14: test_cheb_even
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def test_cheb_even(self):
with suppress_warnings() as sup:
sup.filter(UserWarning, "This window is not suitable")
w = windows.get_window(('chebwin', 40), 54, fftbins=False)
assert_array_almost_equal(w, cheb_even_true, decimal=4)
示例15: test_kaiser_float
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import get_window [as 别名]
def test_kaiser_float(self):
win1 = windows.get_window(7.2, 64)
win2 = windows.kaiser(64, 7.2, False)
assert_allclose(win1, win2)