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


Python signal.resample_poly方法代码示例

本文整理汇总了Python中scipy.signal.resample_poly方法的典型用法代码示例。如果您正苦于以下问题:Python signal.resample_poly方法的具体用法?Python signal.resample_poly怎么用?Python signal.resample_poly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.signal的用法示例。


在下文中一共展示了signal.resample_poly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_basic

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [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,)) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:20,代码来源:test_signaltools.py

示例2: bb2pb

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def bb2pb(x, fd, fc, fs=None, axis=-1):
    """Convert baseband signal to passband.

    For communication applications, one may wish to use :func:`arlpy.comms.upconvert` instead,
    as that function supports pulse shaping.

    The convention used in that exp(2j*pi*fc*t) is a positive frequency carrier.

    :param x: complex baseband signal
    :param fd: sampling rate of baseband signal in Hz
    :param fc: carrier frequency in passband in Hz
    :param fs: sampling rate of passband signal in Hz (``None`` => same as `fd`)
    :param axis: axis of the signal, if multiple signals specified
    :returns: real passband signal, sampled at `fs`
    """
    if fs is None or fs == fd:
        y = _np.array(x, dtype=_np.complex)
        fs = fd
    else:
        y = _sig.resample_poly(_np.asarray(x, dtype=_np.complex), fs, fd, axis=axis)
    osc = _np.sqrt(2)*_np.exp(2j*_np.pi*fc*time(y,fs))
    y *= _utils.broadcastable_to(osc, y.shape, axis)
    return y.real 
开发者ID:org-arl,项目名称:arlpy,代码行数:25,代码来源:signal.py

示例3: feature_extraction

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def feature_extraction(filename):
    x, fs = sf.read(filename)
    if len(x.shape)>1:
       x = np.mean(x, axis = 1)
    #x = x[:3*fs]
    x = signal.resample_poly(x, 16000, fs)
    fs = 16000.0 # sampling frequency
    x = x.astype('float32')
    Hop = 320 # hop size (in sample)
    h = scipy.signal.blackmanharris(2049) # window size
    fr = 2.0 # frequency resolution
    fc = 27.5#80.0 # the frequency of the lowest pitch
    tc = 1/4487.0#1/1000.0 # the period of the highest pitch
    g = np.array([0.24, 0.6, 1])
    NumPerOctave = 48 # Number of bins per octave
    #f  --> freq for each axis
    tfrL0, tfrLF, tfrLQ, f, q, t, CenFreq = CFP_filterbank(x, fr, fs, Hop, h, fc, tc, g, NumPerOctave)
    Z = tfrLF * tfrLQ
    return Z, tfrL0, tfrLF, tfrLQ, t, CenFreq 
开发者ID:s603122001,项目名称:Vocal-Melody-Extraction,代码行数:21,代码来源:MelodyExt.py

示例4: feature_extraction

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def feature_extraction(filename):
    x, fs = sf.read(filename)
    if len(x.shape)>1:
       x = np.mean(x, axis = 1)
    #x = x[:3*fs]
    x = signal.resample_poly(x, 16000, fs)
    fs = 16000.0 # sampling frequency
    x = x.astype('float32')
    Hop = 320 # hop size (in sample)
    h = scipy.signal.blackmanharris(2049) # window size
    fr = 2.0 # frequency resolution
    fc = 27.5#80.0 # the frequency of the lowest pitch
    tc = 1/4487.0#1/1000.0 # the period of the highest pitch
    g = np.array([0.24, 0.6, 1])
    NumPerOctave = 48 # Number of bins per octave
    #f  --> freq for each axis
    tfrL0, tfrLF, tfrLQ, f, q, t, CenFreq = CFP_filterbank(x, fr, fs, Hop, h, fc, tc, g, NumPerOctave)
    Z = tfrLF * tfrLQ
    return Z, tfrL0, tfrLF, tfrLQ, t, CenFreq, f 
开发者ID:BreezeWhite,项目名称:Music-Transcription-with-Semantic-Segmentation,代码行数:21,代码来源:MelodyExt.py

示例5: resample

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def resample(waveform, s_sr, t_sr):
    """resampling for waveforms, should work also with when source and
    target rate ratio is fractional

    Parameters
    ----------
    waveform: np.array
       speech waveform, mono
    s_sr: float
       original sample rate
    t_sr: float
       target sample rate

    returns: resampled waveform as np.array
    """
    ratio = fractions.Fraction(int(t_sr), int(s_sr))
    return resample_poly(waveform, ratio.numerator, ratio.denominator) 
开发者ID:asuni,项目名称:wavelet_prosody_toolkit,代码行数:19,代码来源:misc.py

示例6: test_mutable_window

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def test_mutable_window(self):
        # Test that a mutable window is not modified
        impulse = np.zeros(3)
        window = np.random.RandomState(0).randn(2)
        window_orig = window.copy()
        signal.resample_poly(impulse, 5, 1, window=window)
        assert_array_equal(window, window_orig) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:9,代码来源:test_signaltools.py

示例7: test_poly_vs_filtfilt

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def test_poly_vs_filtfilt(self):
        # Check that up=1.0 gives same answer as filtfilt + slicing
        random_state = np.random.RandomState(17)
        try_types = (int, np.float32, np.complex64, float, complex)
        size = 10000
        down_factors = [2, 11, 79]

        for dtype in try_types:
            x = random_state.randn(size).astype(dtype)
            if dtype in (np.complex64, np.complex128):
                x += 1j * random_state.randn(size)

            # resample_poly assumes zeros outside of signl, whereas filtfilt
            # can only constant-pad. Make them equivalent:
            x[0] = 0
            x[-1] = 0

            for down in down_factors:
                h = signal.firwin(31, 1. / down, window='hamming')
                yf = filtfilt(h, 1.0, x, padtype='constant')[::down]

                # Need to pass convolved version of filter to resample_poly,
                # since filtfilt does forward and backward, but resample_poly
                # only goes forward
                hc = convolve(h, h[::-1])
                y = signal.resample_poly(x, 1, down, window=hc)
                assert_allclose(yf, y, atol=1e-7, rtol=1e-7) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:29,代码来源:test_signaltools.py

示例8: test_correlate1d

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def test_correlate1d(self):
        for down in [2, 4]:
            for nx in range(1, 40, down):
                for nweights in (32, 33):
                    x = np.random.random((nx,))
                    weights = np.random.random((nweights,))
                    y_g = correlate1d(x, weights[::-1], mode='constant')
                    y_s = signal.resample_poly(x, up=1, down=down, window=weights)
                    assert_allclose(y_g[::down], y_s) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:11,代码来源:test_signaltools.py

示例9: pb2bb

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def pb2bb(x, fs, fc, fd=None, flen=127, cutoff=None, axis=-1):
    """Convert passband signal to baseband.

    The baseband conversion uses a low-pass filter after downconversion, with a
    default cutoff frequency of `0.6*fd`, if `fd` is specified, or `1.1*fc` if `fd`
    is not specified. Alternatively, the user may specify the cutoff frequency
    explicitly.

    For communication applications, one may wish to use :func:`arlpy.comms.downconvert` instead,
    as that function supports matched filtering with a pulse shape rather than a generic
    low-pass filter.

    The convention used in that exp(2j*pi*fc*t) is a positive frequency carrier.

    :param x: passband signal
    :param fs: sampling rate of passband signal in Hz
    :param fc: carrier frequency in passband in Hz
    :param fd: sampling rate of baseband signal in Hz (``None`` => same as `fs`)
    :param flen: number of taps in the low-pass FIR filter
    :param cutoff: cutoff frequency in Hz (``None`` means auto-select)
    :param axis: axis of the signal, if multiple signals specified
    :returns: complex baseband signal, sampled at `fd`
    """
    if cutoff is None:
        cutoff = 0.6*fd if fd is not None else 1.1*_np.abs(fc)
    osc = _np.sqrt(2)*_np.exp(-2j*_np.pi*fc*time(x.shape[axis],fs))
    y = x * _utils.broadcastable_to(osc, x.shape, axis)
    hb = _sig.firwin(flen, cutoff=cutoff, nyq=fs/2.0)
    y = _sig.filtfilt(hb, 1, y, axis=axis)
    if fd is not None and fd != fs:
        y = _sig.resample_poly(y, 2*fd, fs, axis=axis)
        y = _np.apply_along_axis(lambda a: a[::2], axis, y)
    return y 
开发者ID:org-arl,项目名称:arlpy,代码行数:35,代码来源:signal.py

示例10: poly_resample

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def poly_resample(psg, new_sample_rate, old_sample_rate):
    from scipy.signal import resample_poly
    return resample_poly(psg, new_sample_rate, old_sample_rate, axis=0) 
开发者ID:perslev,项目名称:U-Time,代码行数:5,代码来源:psg_sampling.py

示例11: resample

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def resample(audio, orig_sr, new_sr):
    orig_dtype = audio.dtype
    factor = gcd(orig_sr, new_sr)
    down = orig_sr / factor
    up = new_sr / factor
    audio = resample_poly(audio, up, down).astype(orig_dtype)
    return audio 
开发者ID:f90,项目名称:AdversarialAudioSeparation,代码行数:9,代码来源:Utils.py

示例12: _preprocess

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def _preprocess(ifilename, rate, chunk_length):
    # data within [-32768 / 2, 32767 / 2] interval
    baserate, data = wavfile.read(ifilename)
    audio = signal.resample_poly(data, rate, baserate)
    # audio within [0; 1] interval: wav_to_float converts it to be in [-1;1] interval
    # mulaw leaves it within same interval, then we shift it to be in [0;1] interval
    audio = mulaw(wav_to_float(audio)) * 0.5 + 0.5
    while len(audio) >= chunk_length:
        yield audio[:chunk_length]
        audio = audio[chunk_length:] 
开发者ID:rampage644,项目名称:wavenet,代码行数:12,代码来源:utils.py

示例13: _read_record

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def _read_record(self, f, blk, chans):
        """Read raw data from a single EDF channel.

        Parameters
        ----------
        i_chan : int
            index of the channel to read
        begsam : int
            index of the first sample
        endsam : int
            index of the last sample

        Returns
        -------
        numpy.ndarray
            A vector with the data as written on file, in 16-bit precision
        """
        dat_in_rec = empty((len(chans), self.max_smp))

        i_ch_in_dat = 0
        for i_ch in chans:
            offset, n_smp_per_chan = self._offset(blk, i_ch)

            f.seek(offset)
            x = fromfile(f, count=n_smp_per_chan, dtype=EDF_FORMAT)

            ratio = self.max_smp / n_smp_per_chan            
            if ratio.is_integer():
                dat_in_rec[i_ch_in_dat, :] = repeat(x, int(ratio))                
            else:
                fract = round(Fraction(ratio), 2)
                up, down = fract.numerator, fract.denominator
                dat_in_rec[i_ch_in_dat, :] = resample_poly(x, up, down)
            i_ch_in_dat += 1                

        return dat_in_rec 
开发者ID:wonambi-python,项目名称:wonambi,代码行数:38,代码来源:edf.py

示例14: resample_oct

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def resample_oct(x, p, q):
    """Resampler that is compatible with Octave"""
    h = _resample_window_oct(p, q)
    window = h / np.sum(h)
    return resample_poly(x, p, q, window=window) 
开发者ID:mpariente,项目名称:pystoi,代码行数:7,代码来源:utils.py

示例15: __init__

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import resample_poly [as 别名]
def __init__(self, timeaxis, timecourse, padvalue=30.0, upsampleratio=100, doplot=False, debug=False,
                 method='univariate'):
        self.upsampleratio = upsampleratio
        self.padvalue = padvalue
        self.initstep = timeaxis[1] - timeaxis[0]
        self.initstart = timeaxis[0]
        self.initend = timeaxis[-1]
        self.hiresstep = self.initstep / np.float64(self.upsampleratio)
        self.hires_x = np.arange(timeaxis[0] - self.padvalue, self.initstep * len(timeaxis) + self.padvalue,
                                 self.hiresstep)
        self.hiresstart = self.hires_x[0]
        self.hiresend = self.hires_x[-1]
        if method == 'poly':
            self.hires_y = 0.0 * self.hires_x
            self.hires_y[int(self.padvalue // self.hiresstep) + 1:-(int(self.padvalue // self.hiresstep) + 1)] = \
                signal.resample_poly(timecourse, np.int(self.upsampleratio * 10), 10)
        elif method == 'fourier':
            self.hires_y = 0.0 * self.hires_x
            self.hires_y[int(self.padvalue // self.hiresstep) + 1:-(int(self.padvalue // self.hiresstep) + 1)] = \
                signal.resample(timecourse, self.upsampleratio * len(timeaxis))
        else:
            self.hires_y = doresample(timeaxis, timecourse, self.hires_x, method=method)
        self.hires_y[:int(self.padvalue // self.hiresstep)] = self.hires_y[int(self.padvalue // self.hiresstep)]
        self.hires_y[-int(self.padvalue // self.hiresstep):] = self.hires_y[-int(self.padvalue // self.hiresstep)]
        if debug:
            print('fastresampler __init__:')
            print('    padvalue:, ', self.padvalue)
            print('    initstep, hiresstep:', self.initstep, self.hiresstep)
            print('    initial axis limits:', self.initstart, self.initend)
            print('    hires axis limits:', self.hiresstart, self.hiresend)

        # self.hires_y[:int(self.padvalue // self.hiresstep)] = 0.0
        # self.hires_y[-int(self.padvalue // self.hiresstep):] = 0.0
        if doplot:
            fig = pl.figure()
            ax = fig.add_subplot(111)
            ax.set_title('fastresampler initial timecourses')
            pl.plot(timeaxis, timecourse, self.hires_x, self.hires_y)
            pl.legend(('input', 'hires'))
            pl.show() 
开发者ID:bbfrederick,项目名称:rapidtide,代码行数:42,代码来源:resample.py


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