本文整理匯總了Python中scipy.signal.decimate方法的典型用法代碼示例。如果您正苦於以下問題:Python signal.decimate方法的具體用法?Python signal.decimate怎麽用?Python signal.decimate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scipy.signal
的用法示例。
在下文中一共展示了signal.decimate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __call__
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [as 別名]
def __call__(self, pkg):
pkg = format_package(pkg)
wav = pkg['chunk']
wav = wav.data.numpy()
factor = random.choice(self.factors)
x_lr = decimate(wav, factor).copy()
x_lr = torch.FloatTensor(x_lr)
x_ = F.interpolate(x_lr.view(1, 1, -1),
scale_factor=factor,
align_corners=True,
mode='linear').view(-1)
if self.report:
if 'report' not in pkg:
pkg['report'] = {}
pkg['report']['resample_factor'] = factor
pkg['chunk'] = x_
return pkg
示例2: harvest_get_downsampled_signal
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [as 別名]
def harvest_get_downsampled_signal(x, fs, target_fs):
decimation_ratio = np.round(fs / target_fs)
offset = np.ceil(140. / decimation_ratio) * decimation_ratio
start_pad = x[0] * np.ones(int(offset), dtype=np.float32)
end_pad = x[-1] * np.ones(int(offset), dtype=np.float32)
x = np.concatenate((start_pad, x, end_pad), axis=0)
if fs < target_fs:
raise ValueError("CASE NOT HANDLED IN harvest_get_downsampled_signal")
else:
try:
y0 = sg.decimate(x, int(decimation_ratio), 3, zero_phase=True)
except:
y0 = sg.decimate(x, int(decimation_ratio), 3)
actual_fs = fs / decimation_ratio
y = y0[int(offset / decimation_ratio):-int(offset / decimation_ratio)]
y = y - np.mean(y)
return y, actual_fs
示例3: get_traces
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [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 decimate [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: test_basic
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [as 別名]
def test_basic(self):
x = np.arange(6)
assert_array_equal(signal.decimate(x, 2, n=1).round(), x[::2])
示例6: test_shape
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [as 別名]
def test_shape(self):
# Regression test for ticket #1480.
z = np.zeros((10, 10))
d0 = signal.decimate(z, 2, axis=0)
assert_equal(d0.shape, (5, 10))
d1 = signal.decimate(z, 2, axis=1)
assert_equal(d1.shape, (10, 5))
示例7: test_bad_args
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [as 別名]
def test_bad_args(self):
x = np.arange(12)
assert_raises(TypeError, signal.decimate, x, q=0.5, n=1)
assert_raises(TypeError, signal.decimate, x, q=2, n=0.5)
示例8: test_basic_IIR
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [as 別名]
def test_basic_IIR(self):
x = np.arange(12)
y = signal.decimate(x, 2, n=1, ftype='iir', zero_phase=False).round()
assert_array_equal(y, x[::2])
示例9: test_basic_FIR
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [as 別名]
def test_basic_FIR(self):
x = np.arange(12)
y = signal.decimate(x, 2, n=1, ftype='fir', zero_phase=False).round()
assert_array_equal(y, x[::2])
示例10: test_shape
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [as 別名]
def test_shape(self):
# Regression test for ticket #1480.
z = np.zeros((30, 30))
d0 = signal.decimate(z, 2, axis=0, zero_phase=False)
assert_equal(d0.shape, (15, 30))
d1 = signal.decimate(z, 2, axis=1, zero_phase=False)
assert_equal(d1.shape, (30, 15))
示例11: decimate
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [as 別名]
def decimate(x, q):
'''decimate x by a factor of q with some settings that I like'''
return signal.decimate(x, q, 20*q, ftype='fir', axis=0, zero_phase=False)
示例12: find_channel_offset
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [as 別名]
def find_channel_offset(s1, s2, nd, nl):
'''use cross-correlation to find channel offset in samples'''
B1 = signal.decimate(s1, nd)
B2 = np.pad(signal.decimate(s2, nd), (nl, nl), 'constant')
xc = np.abs(signal.correlate(B1, B2, mode='valid'))
return (np.argmax(xc) - nl)*nd
示例13: channel_preprocessing
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [as 別名]
def channel_preprocessing(sig, dec, fc, Fs):
'''deinterleave IQ samples, tune to channel frequency and decimate'''
IQ = deinterleave_IQ(sig)
IQ_tuned = frequency_shift(IQ, fc, Fs)
IQd = decimate(IQ_tuned, dec)
return IQd
示例14: upsample_wav
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [as 別名]
def upsample_wav(wav, args, model):
# load signal
x_hr, fs = librosa.load(wav, sr=args.sr)
x_lr_t = decimate(x_hr, args.r)
# pad to mutliple of patch size to ensure model runs over entire sample
x_hr = np.pad(x_hr, (0, args.patch_size - (x_hr.shape[0] % args.patch_size)), 'constant', constant_values=(0,0))
# downscale signal
x_lr = decimate(x_hr, args.r)
# upscale the low-res version
P = model.predict(x_lr.reshape((1,len(x_lr),1)))
x_pr = P.flatten()
# crop so that it works with scaling ratio
x_hr = x_hr[:len(x_pr)]
x_lr_t = x_lr_t[:len(x_pr)]
# save the file
outname = wav + '.' + args.out_label
librosa.output.write_wav(outname + '.lr.wav', x_lr_t, fs / args.r)
librosa.output.write_wav(outname + '.hr.wav', x_hr, fs)
librosa.output.write_wav(outname + '.pr.wav', x_pr, fs)
# save the spectrum
S = get_spectrum(x_pr, n_fft=2048)
save_spectrum(S, outfile=outname + '.pr.png')
S = get_spectrum(x_hr, n_fft=2048)
save_spectrum(S, outfile=outname + '.hr.png')
S = get_spectrum(x_lr, n_fft=2048/args.r)
save_spectrum(S, outfile=outname + '.lr.png')
# ----------------------------------------------------------------------------
示例15: wavwrite
# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import decimate [as 別名]
def wavwrite(srcfile, fs, training):
try:
mat = io.loadmat(srcfile)
except ValueError:
print('Could not load %s' % srcfile)
return
dat = mat['dataStruct'][0, 0][0]
if ds_factor != 1:
dat = signal.decimate(dat, ds_factor, axis=0, zero_phase=True)
mn = dat.min()
mx = dat.max()
mx = float(max(abs(mx), abs(mn)))
if training and mx == 0:
print('skipping %s' % srcfile)
return
if mx != 0:
dat *= 0x7FFF / mx
dat = np.int16(dat)
winsize = win_dur * 60 * fs
stride = 60 * fs
for elec in range(16):
aud = dat[:, elec]
for win in range(nwin):
dstfile = srcfile.replace('mat', str(win) + '.' + str(elec) + '.wav')
beg = win * stride
end = beg + winsize
clip = aud[beg:end]
audiolab.wavwrite(clip, dstfile, fs=fs, enc='pcm16')