本文整理汇总了Python中scipy.signal.resample方法的典型用法代码示例。如果您正苦于以下问题:Python signal.resample方法的具体用法?Python signal.resample怎么用?Python signal.resample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.signal
的用法示例。
在下文中一共展示了signal.resample方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _wavdata_rs
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def _wavdata_rs(self):
if self.fs_rs is not None:
# Number of points in resample
ns_rs = np.int_(np.ceil(self.ns * self.fs_rs / self.fs))
# Do resample
# XXX: Tried using a Hamming window as a low pass filter, but it
# didn't seem to make a big difference, so it's not used
# here.
data_rs = resample(self.wavdata, ns_rs)
wavpath_rs = self.wavpath.split('.')[0] + '-resample-' + str(self.fs_rs) + 'Hz.wav'
# Write resampled data to wav file
# Convert data from 32-bit floating point to 16-bit PCM
data_rs_int = np.int16(data_rs * 32768)
wavfile.write(wavpath_rs, self.fs_rs, data_rs_int)
# XXX: Was worried that Python might continue executing code
# before the file write is finished, but it seems like it's
# not an issue.
return wavpath_rs, data_rs, data_rs_int, ns_rs
else:
return None, None, None, None
示例2: test_basic
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def test_basic(self):
# Some basic tests
# Regression test for issue #3603.
# window.shape must equal to sig.shape[0]
sig = np.arange(128)
num = 256
win = signal.get_window(('kaiser', 8.0), 160)
assert_raises(ValueError, signal.resample, sig, num, window=win)
# Other degenerate conditions
assert_raises(ValueError, signal.resample_poly, sig, 'yo', 1)
assert_raises(ValueError, signal.resample_poly, sig, 1, 0)
# test for issue #6505 - should not modify window.shape when axis ≠ 0
sig2 = np.tile(np.arange(160), (2,1))
signal.resample(sig2, num, axis=-1, window=win)
assert_(win.shape == (160,))
示例3: get_traces
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def get_traces(self, channel_ids=None, start_frame=None, end_frame=None):
start_frame_not_sampled = int(start_frame / self.get_sampling_frequency() *
self._recording.get_sampling_frequency())
start_frame_sampled = start_frame
end_frame_not_sampled = int(end_frame / self.get_sampling_frequency() *
self._recording.get_sampling_frequency())
end_frame_sampled = end_frame
traces = self._recording.get_traces(start_frame=start_frame_not_sampled,
end_frame=end_frame_not_sampled,
channel_ids=channel_ids)
if np.mod(self._recording.get_sampling_frequency(), self._resample_rate) == 0:
traces_resampled = signal.decimate(traces,
q=int(self._recording.get_sampling_frequency() / self._resample_rate),
axis=1)
else:
traces_resampled = signal.resample(traces, int(end_frame_sampled - start_frame_sampled), axis=1)
return traces_resampled.astype(self._dtype)
示例4: resample
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def resample(recording, resample_rate):
'''
Resamples the recording extractor traces. If the resampling rate is multiple of the sampling rate, the faster
scipy decimate function is used.
Parameters
----------
recording: RecordingExtractor
The recording extractor to be resampled
resample_rate: int or float
The resampling frequency
Returns
-------
resampled_recording: ResampleRecording
The resample recording extractor
'''
return ResampleRecording(
recording=recording,
resample_rate=resample_rate
)
示例5: __call__
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def __call__(self, seq):
if np.random.randint(2):
return seq
else:
seq_aug = np.zeros(seq.shape)
len = seq.shape[1]
length = int(len * (1 + (random.random()-0.5)*self.sigma))
for i in range(seq.shape[0]):
y = resample(seq[i, :], length)
if length < len:
if random.random() < 0.5:
seq_aug[i, :length] = y
else:
seq_aug[i, len-length:] = y
else:
if random.random() < 0.5:
seq_aug[i, :] = y[:len]
else:
seq_aug[i, :] = y[length-len:]
return seq_aug
示例6: cutTabs
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def cutTabs(datas, part):
#First we uniformize the GS
minSize = 0
for nDim in range(len(v.eName)):
for s in part :
if (minSize > len(datas['gs'+s][nDim]) or minSize == 0):
minSize = len(datas['gs'+s][nDim])
oneF = int(minSize/9)
#We cut all tab to reach this size
for nDim in range(len(v.eName)):
for s in part :
#Gold Standard Tab
datas['gs'+s][nDim] = cutTab(datas['gs'+s][nDim],minSize)
#Predictions tab
for nMod in range(len(v.desc)):
datas[s][nDim][nMod] = cutTab(datas[s][nDim][nMod],minSize)
return datas
#End cutTabs
#Used to resample the tab
示例7: downsample
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def downsample(data, oldFS, newFS):
"""
Resample data from oldFS to newFS using the scipy 'resample' function.
Parameters
----------
data : instance of pandas.core.DataFrame
Data to resample.
oldFS : float
The sampling frequency of data.
newFS : float
The new sampling frequency.
Returns:
newData : instance of pandas.DataFrame
The downsampled dataset.
"""
newNumSamples = int((data.shape[0] / oldFS) * newFS)
newData = pd.DataFrame(resample(data, newNumSamples))
return newData
示例8: downsampleNP
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def downsampleNP(data, oldFS, newFS):
"""
Resample data from oldFS to newFS using the scipy 'resample' function.
Parameters
----------
data : array-like
Data to resample.
oldFS : float
The sampling frequency of data.
newFS : float
The new sampling frequency.
Returns:
newData : instance of pandas.DataFrame
The downsampled dataset.
"""
newNumSamples = int((data.shape[0] / oldFS) * newFS)
newData = resample(data, newNumSamples)
return newData
示例9: preprocess
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def preprocess(data, config):
sr = config.sample_rate
if sr == None:
sr = 300
data = np.nan_to_num(data) # removing NaNs and Infs
from scipy.signal import resample
data = resample(data, int(len(data) * 360 / sr) ) # resample to match the data sampling rate 360(mit), 300(cinc)
from sklearn import preprocessing
data = preprocessing.scale(data)
from scipy.signal import find_peaks
peaks, _ = find_peaks(data, distance=150)
data = data.reshape(1,len(data))
data = np.expand_dims(data, axis=2) # required by Keras
return data, peaks
# predict
示例10: f0transform
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def f0transform(self, x, completion=False):
"""Transform F0 of given waveform signals using
Parameters
---------
x : array, shape ('len(x)')
array of waveform sequence
completion : bool, optional
Completion of high frequency range of F0 transformed wavform based on
unvoiced analysis/synthesis voice of given voice and high-pass filter.
This is due to loose the high frequency range caused by resampling
when F0ratio setting to smaller than 1.0.
Returns
---------
transformed : array, shape (`len(x)`)
Array of F0 transformed waveform sequence
"""
self.xlen = len(x)
# WSOLA
wsolaed = self.wsola.duration_modification(x)
# resampling
transformed = resample(wsolaed, self.xlen)
# Frequency completion when decrease F0 of wavform
if completion:
if self.f0rate > 1.0:
raise ValueError("Do not enable completion if f0rate > 1.")
transformed = self._high_frequency_completion(x, transformed)
return transformed
示例11: __call__
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def __call__(self, pkg):
pkg = format_package(pkg)
wav = pkg['chunk']
wav = wav.data.numpy().reshape(-1).astype(np.float32)
warp_factor = random.random() * (self.factor_range[1] - \
self.factor_range[0]) + \
self.factor_range[0]
samp_warp = wav.shape[0] + int(warp_factor * wav.shape[0])
rwav = signal.resample(wav, samp_warp)
if len(rwav) > len(wav):
mid_i = (len(rwav) // 2) - len(wav) // 2
rwav = rwav[mid_i:mid_i + len(wav)]
if len(rwav) < len(wav):
diff = len(wav) - len(rwav)
P = (len(wav) - len(rwav)) // 2
if diff % 2 == 0:
rwav = np.concatenate((np.zeros(P, ),
wav,
np.zeros(P, )),
axis=0)
else:
rwav = np.concatenate((np.zeros(P, ),
wav,
np.zeros(P + 1, )),
axis=0)
if self.report:
if 'report' not in pkg:
pkg['report'] = {}
pkg['report']['warp_factor'] = warp_factor
pkg['chunk'] = torch.FloatTensor(rwav)
return pkg
示例12: test_array_as_window
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def test_array_as_window(self):
# github issue 3603
osfactor = 128
sig = np.arange(128)
win = windows.get_window(('kaiser', 8.0), osfactor // 2)
assert_raises(ValueError, resample,
(sig, len(sig) * osfactor), {'window': win})
示例13: resample_dataset
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def resample_dataset(x, rate):
new_x = np.zeros(shape=(x.shape[0], rate))
from scipy import signal
for i in range(x.shape[0]):
f = signal.resample(x[0], rate)
new_x[i] = f
return new_x
示例14: resample
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def resample(sig, target_point_num=None):
'''
对原始信号进行重采样
:param sig: 原始信号
:param target_point_num:目标型号点数
:return: 重采样的信号
'''
sig = signal.resample(sig, target_point_num) if target_point_num else sig
return sig
示例15: transform
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample [as 别名]
def transform(sig, train=False):
# 前置不可或缺的步骤
sig = resample(sig, config.target_point_num)
# # 数据增强
if train:
if np.random.randn() > 0.5: sig = scaling(sig)
if np.random.randn() > 0.5: sig = verflip(sig)
if np.random.randn() > 0.5: sig = shift(sig)
# 后置不可或缺的步骤
sig = sig.transpose()
sig = torch.tensor(sig.copy(), dtype=torch.float)
return sig