當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。