当前位置: 首页>>代码示例>>Python>>正文


Python signal.decimate方法代码示例

本文整理汇总了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 
开发者ID:santi-pdp,项目名称:pase,代码行数:19,代码来源:transforms.py

示例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 
开发者ID:kastnerkyle,项目名称:tools,代码行数:20,代码来源:audio_tools.py

示例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) 
开发者ID:SpikeInterface,项目名称:spiketoolkit,代码行数:19,代码来源:resample.py

示例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
    ) 
开发者ID:SpikeInterface,项目名称:spiketoolkit,代码行数:24,代码来源:resample.py

示例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]) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:5,代码来源:test_signaltools.py

示例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)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:9,代码来源:test_signaltools.py

示例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) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:6,代码来源:test_signaltools.py

示例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]) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:6,代码来源:test_signaltools.py

示例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]) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:6,代码来源:test_signaltools.py

示例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)) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:9,代码来源:test_signaltools.py

示例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) 
开发者ID:Max-Manning,项目名称:passiveRadar,代码行数:5,代码来源:signal_utils.py

示例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 
开发者ID:Max-Manning,项目名称:passiveRadar,代码行数:8,代码来源:signal_utils.py

示例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 
开发者ID:Max-Manning,项目名称:passiveRadar,代码行数:8,代码来源:signal_utils.py

示例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')

# ---------------------------------------------------------------------------- 
开发者ID:kuleshov,项目名称:audio-super-res,代码行数:38,代码来源:io.py

示例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') 
开发者ID:anlthms,项目名称:sp-2016,代码行数:33,代码来源:prep.py


注:本文中的scipy.signal.decimate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。