本文整理汇总了Python中scipy.signal.stft方法的典型用法代码示例。如果您正苦于以下问题:Python signal.stft方法的具体用法?Python signal.stft怎么用?Python signal.stft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.signal
的用法示例。
在下文中一共展示了signal.stft方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import stft [as 别名]
def __init__(self, filename, in_memory=True, window_size=4096,
output_size=84, feature_size=1024, sample_freq=11000,
complex_=False, fourier=False, stft=False, fast_load=False,
rng=None, seed=123):
if not in_memory:
raise NotImplementedError
self.filename = filename
self.window_size = window_size
self.output_size = output_size
self.feature_size = feature_size
self.sample_freq = sample_freq
self.complex_ = complex_
self.fourier = fourier
self.stft = stft
self.fast_load = fast_load
if rng is not None:
self.rng = rng
else:
self.rng = numpy.random.RandomState(seed)
self._train_data = {}
self._valid_data = {}
self._test_data = {}
self._loaded = False
self._eval_sets = {}
示例2: aggregate_raw_batch
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import stft [as 别名]
def aggregate_raw_batch(self, features, output):
"""Aggregate batch.
All post processing goes here.
Parameters:
-----------
features : 3D float tensor
Input tensor
output : 2D integer tensor
Output classes
"""
channels = 2 if self.complex_ else 1
features_out = numpy.zeros(
[features.shape[0], self.window_size, channels])
if self.fourier:
if self.complex_:
data = fft(features, axis=1)
features_out[:, :, 0] = numpy.real(data[:, :, 0])
features_out[:, :, 1] = numpy.imag(data[:, :, 0])
else:
data = numpy.abs(fft(features, axis=1))
features_out = data
elif self.stft:
_, _, data = stft(features, nperseg=120, noverlap=60, axis=1)
length = data.shape[1]
n_feats = data.shape[3]
if self.complex_:
features_out = numpy.zeros(
[len(self.train_data), length, n_feats * 2])
features_out[:, :, :n_feats] = numpy.real(data)
features_out[:, :, n_feats:] = numpy.imag(data)
else:
features_out = numpy.abs(data[:, :, 0, :])
else:
features_out = features
return features_out, output
示例3: test_istft
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import stft [as 别名]
def test_istft(ctx, window_size, stride, fft_size, window_type, center):
backend = ctx.backend[0].split(":")[0]
if backend == 'cuda':
pytest.skip('CUDA Convolution N-D is only supported in CUDNN extension')
# clear all previous STFT conv/deconv kernels
nn.clear_parameters()
# Make sure that iSTFT(STFT(x)) = x
x = np.random.randn(1, window_size * 10)
nx = nn.Variable.from_numpy_array(x)
with nn.context_scope(ctx):
nyr, nyi = F.stft(nx,
window_size=window_size,
stride=stride,
fft_size=fft_size,
window_type=window_type,
center=center)
nz = F.istft(nyr, nyi,
window_size=window_size,
stride=stride,
fft_size=fft_size,
window_type=window_type,
center=center)
nz.forward()
invalid = window_size - stride
assert(np.allclose(nx.d[:, invalid:-invalid],
nz.d[:, invalid:-invalid],
atol=1e-5, rtol=1e-5))
示例4: stft
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import stft [as 别名]
def stft(x, frame_len=2048, frame_step=512):
return _stft(x, nperseg=frame_len, noverlap=(frame_len - frame_step))[-1]
示例5: test_stft
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import stft [as 别名]
def test_stft(ctx, window_size, stride, fft_size, window_type):
backend = ctx.backend[0].split(":")[0]
if backend == 'cuda':
pytest.skip('CUDA Convolution N-D is only supported in CUDNN extension')
# clear all previous STFT conv/deconv kernels
nn.clear_parameters()
# Compare to `scipy.signal.stft` - only done if SciPy available
x = np.random.randn(1, window_size * 10)
nx = nn.Variable.from_numpy_array(x)
with nn.context_scope(ctx):
nyr, nyi = F.stft(nx,
window_size=window_size,
stride=stride,
fft_size=fft_size,
window_type=window_type,
center=False)
nn.forward_all([nyr, nyi])
stft_nnabla = nyr.d + 1j * nyi.d
window_type_scipy = window_type
if window_type == 'rectangular' or window_type is None:
window_type_scipy = 'boxcar'
_f, _t, stft_scipy = sig.stft(x,
window=window_type_scipy,
nperseg=window_size,
noverlap=window_size-stride,
nfft=fft_size,
boundary=None,
padded=False)
# scipy does a different scaling - take care here
stft_nnabla /= fft_size // 2
assert(np.allclose(stft_nnabla,
stft_scipy,
atol=1e-5, rtol=1e-5))