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


Python signal.filtfilt方法代码示例

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


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

示例1: _butter_bandpass_filter

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def _butter_bandpass_filter(data, low_cut, high_cut, fs, axis = 0, order=5):
    '''Apply a bandpass butterworth filter with zero-phase filtering

    Args:
        data: (np.array)
        low_cut: (float) lower bound cutoff for high pass filter
        high_cut: (float) upper bound cutoff for low pass filter
        fs: (float) sampling frequency in Hz
        axis: (int) axis to perform filtering.
        order: (int) filter order for butterworth bandpass
    
    Returns:
        bandpass filtered data.
    '''
    nyq = 0.5 * fs
    b, a = butter(order, [low_cut/nyq, high_cut/nyq], btype='band')
    return filtfilt(b, a, data, axis=axis) 
开发者ID:cosanlab,项目名称:nltools,代码行数:19,代码来源:stats.py

示例2: filter_signal

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def filter_signal(b, a, signal):
    """
    Filter a signal.

    Simple wrapper around :func:`scipy.signal.filtfilt` to apply a
    foward-backward filter to preserve phase of the input. Requires the
    numerator and denominator polynomials from
    :func:`sensormotion.signal.build_filter`.

    Parameters
    ----------
    b : ndarray
        Numerator polynomial coefficients of the filter.
    a : ndarray
        Denominator polynomial coefficients of the filter.
    signal : ndarray
        Input array to be filtered.

    Returns
    -------
    signal_filtered : ndarray
        Filtered output of the original input signal.
    """

    return filtfilt(b, a, signal) 
开发者ID:sho-87,项目名称:sensormotion,代码行数:27,代码来源:signal.py

示例3: _do_filter

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def _do_filter(self, chunk):
        sampling_frequency = self._recording.get_sampling_frequency()
        M = chunk.shape[0]
        chunk2 = chunk
        # Do the actual filtering with a DFT with real input
        if self._type == 'fft':
            chunk_fft = np.fft.rfft(chunk2)
            kernel = _create_filter_kernel(
                chunk2.shape[1],
                sampling_frequency,
                self._freq_min, self._freq_max, self._freq_wid
            )
            kernel = kernel[0:chunk_fft.shape[1]]  # because this is the DFT of real data
            chunk_fft = chunk_fft * np.tile(kernel, (M, 1))
            chunk_filtered = np.fft.irfft(chunk_fft)
        elif self._type == 'butter':
            chunk_filtered = ss.filtfilt(self._b, self._a, chunk2, axis=1)

        return chunk_filtered 
开发者ID:SpikeInterface,项目名称:spiketoolkit,代码行数:21,代码来源:bandpass_filter.py

示例4: prepData

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def prepData(seqLocal = seq):
    dm = DataManager()
    dm.initHelper(dsName, subType, seqLocal)
    dt = dm.dt

    pSignal = dm.accdt_gnd
    pSignal = preClamp(pSignal)

    mSignal = dm.pr_dtr_gnd
    mSignal = preClamp((mSignal))

    mCov = dm.dtr_cov_gnd

    gtSignal = preClamp(dm.gt_dtr_gnd)
    gtSignal = filtfilt(gtSignal)
    return gtSignal, dt, pSignal, mSignal, mCov 
开发者ID:ElliotHYLee,项目名称:Deep_Visual_Inertial_Odometry,代码行数:18,代码来源:main_KF.py

示例5: add_disturbance

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def add_disturbance(self, input):
        if self.options['input_disturbance'] is not None:
            fc = self.options['input_disturbance']['fc']
            stdev = self.options['input_disturbance']['stdev']
            if 'mean' in self.options['input_disturbance']:
                mean = self.options['input_disturbance']['mean']
            else:
                mean = np.zeros(stdev.shape)
            n_sign = input.shape[0]
            n_samp = input.shape[1]
            disturbance = np.zeros((n_sign, n_samp))
            filt = butter(3, fc, 'low')
            for k in range(n_sign):
                disturbance[k, :] = filtfilt(filt[0], filt[1],
                                             normal(mean[k], stdev[k], n_samp))
            return input + disturbance
        else:
            return input 
开发者ID:meco-group,项目名称:omg-tools,代码行数:20,代码来源:vehicle.py

示例6: demodulate

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def demodulate(x, Fs, freq):
    """return decimated and demodulated audio signal envelope at a known CW frequency """
    t = np.arange(len(x))/ float(Fs)
    mixed =  x*((1 + np.sin(2*np.pi*freq*t))/2 )

    #calculate envelope and low pass filter this demodulated signal
    #filter bandwidth impacts decoding accuracy significantly 
    #for high SNR signals 40 Hz is better, for low SNR 20Hz is better
    # 25Hz is a compromise - could this be made an adaptive value?
    low_cutoff = 25. # 25 Hz cut-off for lowpass
    wn = low_cutoff/ (Fs/2.)    
    b, a = butter(3, wn)  # 3rd order butterworth filter
    z = filtfilt(b, a, abs(mixed))
    
    decimate = int(Fs/64) # 8000 Hz / 64 = 125 Hz => 8 msec / sample 
    Ts = 1000.*decimate/float(Fs)
    o = z[0::decimate]/max(z)
    return o 
开发者ID:ag1le,项目名称:LSTM_morse,代码行数:20,代码来源:MorseDecoder.py

示例7: upscale_log

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def upscale_log(log, freq=20):
    """
    downscale a well log with a lowpass butterworth filter
    """
    depth = np.array(log.depth)
    data = np.array(log.data)
    mask = np.isfinite(data)
    func = interp1d(depth[mask], data[mask])
    interp_data = func(depth[log.start_idx: log.stop_idx])
    nyq = 10000 / 2
    dw = freq / nyq
    b, a = butter(4, dw, btype='low', analog=False)
    filtered = filtfilt(b, a, interp_data, method='gust')
    downscale_data = np.array(data)
    downscale_data[log.start_idx: log.stop_idx] = filtered
    log_downscale = Log()
    log_downscale.name = log.name + "_downscale_" + str(freq)
    log_downscale.units = log.units
    log_downscale.descr = log.descr
    log_downscale.depth = log.depth
    log_downscale.data = downscale_data
    return log_downscale 
开发者ID:whimian,项目名称:pyGeoPressure,代码行数:24,代码来源:log_tools.py

示例8: _high_frequency_completion

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def _high_frequency_completion(self, x, transformed):
        """
        Please see Sect. 3.2 and 3.3 in the following paper to know why we complete the
        unvoiced synthesized voice of the original voice into high frequency range
        of F0 transformed voice.

        - K. Kobayashi et al., "F0 transformation techniques for statistical voice
        conversion with direct waveform modification with spectral differential,"
        Proc. IEEE SLT 2016, pp. 693-700. 2016.
        """
        # construct feature extractor and synthesis
        feat = FeatureExtractor(fs=self.fs)
        f0, spc, ap = feat.analyze(x)
        uf0 = np.zeros(len(f0))

        # synthesis
        synth = Synthesizer(fs=self.fs)
        unvoice_anasyn = synth.synthesis_spc(uf0, spc, ap)

        # HPF for synthesized speech
        fil = firwin(255, self.f0rate, pass_zero=False)
        HPFed_unvoice_anasyn = filtfilt(fil, 1, unvoice_anasyn)

        if len(HPFed_unvoice_anasyn) > len(transformed):
            return transformed + HPFed_unvoice_anasyn[:len(transformed)]
        else:
            transformed[:len(HPFed_unvoice_anasyn)] += HPFed_unvoice_anasyn
            return transformed 
开发者ID:k2kobayashi,项目名称:sprocket,代码行数:30,代码来源:shifter.py

示例9: low_pass_filter

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def low_pass_filter(data, cutoff, fs, n_taps=255):
    """Apply low-pass filter

    Parameters
    ----------
    data : array, shape (`T`, `dim`)
        Array of sequence.
    cutoff : int,
        Cutoff frequency
    fs : int,
        Sampling frequency
    n_taps : int, optional
        Tap number

    Returns
    -------
    modified data: array, shape (`T`, `dim`)
        Array of modified sequence.
    """
    if data.shape[0] < n_taps * 3:
        raise ValueError(
            'Length of data should be three times longer than n_taps.')

    fil = firwin(n_taps, cutoff, pass_zero=True, nyq=fs//2)
    modified_data = filtfilt(fil, 1, data, axis=0)
    return modified_data 
开发者ID:k2kobayashi,项目名称:sprocket,代码行数:28,代码来源:filter.py

示例10: high_pass_filter

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def high_pass_filter(data, cutoff, fs, n_taps=255):
    """Apply high-pass filter

    Parameters
    ----------
    data : array, shape (`T`, `dim`)
        Array of sequence.
    cutoff : int,
        Cutoff frequency
    fs : int,
        Sampling frequency
    n_taps : int, optional
        Tap number

    Returns
    -------
    modified data: array, shape (`T`, `dim`)
        Array of modified sequence.
    """
    if data.shape[0] < n_taps * 3:
        raise ValueError(
            'Length of data should be three times longer than n_taps.')

    fil = firwin(n_taps, cutoff, pass_zero=False, nyq=fs//2)
    modified_data = filtfilt(fil, 1, data, axis=0)
    return modified_data 
开发者ID:k2kobayashi,项目名称:sprocket,代码行数:28,代码来源:filter.py

示例11: _filter_obliquity

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def _filter_obliquity(OBL, F, Kx, vel, critical, ntaper, Ky=0):
    """Apply masking of ``OBL`` based on critical angle and tapering at edges

    Parameters
    ----------
    OBL : :obj:`np.ndarray`
        Obliquity factor
    F : :obj:`np.ndarray`
        Frequency grid
    Kx : :obj:`np.ndarray`
        Horizonal wavenumber grid
    vel : :obj:`float`
        Velocity along the receiver array (must be constant)
    critical : :obj:`float`, optional
        Percentage of angles to retain in obliquity factor
    ntaper : :obj:`float`, optional
        Number of samples of taper applied to obliquity factor around critical
        angle
    Ky : :obj:`np.ndarray`, optional
        Second horizonal wavenumber grid

    Returns
    -------
    OBL : :obj:`np.ndarray`
        Filtered obliquity factor

    """
    critical /= 100.
    mask = np.sqrt(Kx**2 + Ky**2) < critical * np.abs(F) / vel
    OBL *= mask
    OBL = filtfilt(np.ones(ntaper) / float(ntaper), 1, OBL, axis=0)
    OBL = filtfilt(np.ones(ntaper) / float(ntaper), 1, OBL, axis=1)
    if isinstance(Ky, np.ndarray):
        OBL = filtfilt(np.ones(ntaper) / float(ntaper), 1, OBL, axis=2)
    return OBL 
开发者ID:equinor,项目名称:pylops,代码行数:37,代码来源:wavedecomposition.py

示例12: test_basic

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def test_basic(self):
        out = signal.filtfilt([1, 2, 3], [1, 2, 3], np.arange(12))
        assert_equal(out, arange(12)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:5,代码来源:test_signaltools.py

示例13: test_sine

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def test_sine(self):
        rate = 2000
        t = np.linspace(0, 1.0, rate + 1)
        # A signal with low frequency and a high frequency.
        xlow = np.sin(5 * 2 * np.pi * t)
        xhigh = np.sin(250 * 2 * np.pi * t)
        x = xlow + xhigh

        b, a = butter(8, 0.125)
        z, p, k = tf2zpk(b, a)
        # r is the magnitude of the largest pole.
        r = np.abs(p).max()
        eps = 1e-5
        # n estimates the number of steps for the
        # transient to decay by a factor of eps.
        n = int(np.ceil(np.log(eps) / np.log(r)))

        # High order lowpass filter...
        y = filtfilt(b, a, x, padlen=n)
        # Result should be just xlow.
        err = np.abs(y - xlow).max()
        assert_(err < 1e-4)

        # A 2D case.
        x2d = np.vstack([xlow, xlow + xhigh])
        y2d = filtfilt(b, a, x2d, padlen=n, axis=1)
        assert_equal(y2d.shape, x2d.shape)
        err = np.abs(y2d - xlow).max()
        assert_(err < 1e-4)

        # Use the previous result to check the use of the axis keyword.
        # (Regression test for ticket #1620)
        y2dt = filtfilt(b, a, x2d.T, padlen=n, axis=0)
        assert_equal(y2d, y2dt.T) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:36,代码来源:test_signaltools.py

示例14: test_axis

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def test_axis(self):
        # Test the 'axis' keyword on a 3D array.
        x = np.arange(10.0 * 11.0 * 12.0).reshape(10, 11, 12)
        b, a = butter(3, 0.125)
        y0 = filtfilt(b, a, x, padlen=0, axis=0)
        y1 = filtfilt(b, a, np.swapaxes(x, 0, 1), padlen=0, axis=1)
        assert_array_equal(y0, np.swapaxes(y1, 0, 1))
        y2 = filtfilt(b, a, np.swapaxes(x, 0, 2), padlen=0, axis=2)
        assert_array_equal(y0, np.swapaxes(y2, 0, 2)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_signaltools.py

示例15: spectrafilter

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import filtfilt [as 别名]
def spectrafilter(spectre,filtertype,fq,numtaps,columns):
    """Filter specific frequencies in spectra with a butterworth filter

    Inputs
    ------
    spectre : ndarray
        Array of X-Y values of spectra. First column is X and subsequent n columns are Y values of n spectra. (see also spectraarray function)
    filtertype : string
        type of filter; Choose between 'low', 'high', 'bandstop', 'bandpass'.
    fq : ndarray
        Frequency of the periodic signal you try to erase. If using a bandpass or band stop filter, fq must be an array containing the cutoff frequencies.
    columns : ndarray
        An array defining which columns to treat.

    Outputs
    -------
    out : ndarray
        filtered signals.

    """
    out = np.zeros(spectre.shape) # output array
    out[:,0] = spectre[:,0] # record x axis

    # Butterworth band stop filter caracteristics
    a = spectre[1,0] - spectre[0,0]
    samplerate = 1/a  #Hertz
    nyq_rate = samplerate/2 # Nyquist frequency
    cutf = fq # cutoff frequency
    #bandwidth = 0.005 # largeur filtre, for band pass/stop filters
    numtaps = 1 # filter order

    for i in range(len(columns)):
        y = spectre[:,columns[i]]
        if (filtertype == 'low') or (filtertype == 'high'):
            b, a = signal.butter(numtaps, [(cutf/nyq_rate)], btype = filtertype)
        else:
            b, a = signal.butter(numtaps, [(cutf[0]/nyq_rate),(cutf[1]/nyq_rate)], btype = filtertype)

        out[:,columns[i]] = signal.filtfilt(b, a, y) # filter with phase shift correction

    return out 
开发者ID:charlesll,项目名称:rampy,代码行数:43,代码来源:filters.py


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