當前位置: 首頁>>代碼示例>>Python>>正文


Python signal.lfilter方法代碼示例

本文整理匯總了Python中scipy.signal.lfilter方法的典型用法代碼示例。如果您正苦於以下問題:Python signal.lfilter方法的具體用法?Python signal.lfilter怎麽用?Python signal.lfilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.signal的用法示例。


在下文中一共展示了signal.lfilter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: discount

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def discount(x, gamma):
  """
  Compute discounted sum of future values
  out[i] = in[i] + gamma * in[i+1] + gamma^2 * in[i+2] + ...
  """
  return signal.lfilter([1], [1, -gamma], x[::-1], axis=0)[::-1] 
開發者ID:mjacar,項目名稱:pytorch-trpo,代碼行數:8,代碼來源:math_utils.py

示例2: spectrogram2wav

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def spectrogram2wav(mag):
    '''# Generate wave file from spectrogram'''
    # transpose
    mag = mag.T

    # de-noramlize
    mag = (np.clip(mag, 0, 1) * hp.max_db) - hp.max_db + hp.ref_db

    # to amplitude
    mag = np.power(10.0, mag * 0.05)

    # wav reconstruction
    wav = griffin_lim(mag)

    # de-preemphasis
    wav = signal.lfilter([1], [1, -hp.preemphasis], wav)

    # trim
    wav, _ = librosa.effects.trim(wav)

    return wav.astype(np.float32) 
開發者ID:KinglittleQ,項目名稱:GST-Tacotron,代碼行數:23,代碼來源:utils.py

示例3: butter_filter

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def butter_filter(sig, fs, ftype="low", low_cut=50, high_cut=2000, order=5):
    """
    Apply filter to signal.

    Args:
        - sig      (array) : the signal array to filter.
        - fs       (float) : the sampling rate.
        - ftype      (str) : the filter type, by default defined to a low pass filter
        - low_cut  (float) : the low cutoff frequency, by default defined to  50Hz
        - high_cut (float) : the high cutoff frequency, by default defined to 2000Hz.
        - order      (int) : order of the filter, by default defined to 5.

    Returns:
        array of the filtered signal.
    """
    if   ftype == "band" : b, a = butter_bandpass(low_cut, high_cut, fs, order)
    elif ftype == "high" : b, a = butter_highpass(high_cut, fs, order)
    else                 : b, a = butter_lowpass(low_cut,  fs, order)

    # filter signal
    y = lfilter(b, a, sig)
    return y 
開發者ID:SuperKogito,項目名稱:pydiogment,代碼行數:24,代碼來源:filters.py

示例4: preemphasis

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def preemphasis(wav, coeff=0.97):
    """
    Emphasize high frequency range of the waveform by increasing power(squared amplitude).

    Parameters
    ----------
    wav : np.ndarray [shape=(n,)]
        Real-valued the waveform.

    coeff: float <= 1 [scalar]
        Coefficient of pre-emphasis.

    Returns
    -------
    preem_wav : np.ndarray [shape=(n,)]
        The pre-emphasized waveform.
    """
    preem_wav = signal.lfilter([1, -coeff], [1], wav)
    return preem_wav 
開發者ID:andabi,項目名稱:parallel-wavenet-vocoder,代碼行數:21,代碼來源:audio.py

示例5: inv_preemphasis

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def inv_preemphasis(preem_wav, coeff=0.97):
    """
    Invert the pre-emphasized waveform to the original waveform.

    Parameters
    ----------
    preem_wav : np.ndarray [shape=(n,)]
        The pre-emphasized waveform.

    coeff: float <= 1 [scalar]
        Coefficient of pre-emphasis.

    Returns
    -------
    wav : np.ndarray [shape=(n,)]
        Real-valued the waveform.
    """
    wav = signal.lfilter([1], [1, -coeff], preem_wav)
    return wav 
開發者ID:andabi,項目名稱:parallel-wavenet-vocoder,代碼行數:21,代碼來源:audio.py

示例6: compressor

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def compressor(x, thresh=-24, ratio=2, attackrel=0.045, sr=44100.0, dtype=np.float32):
    """
    simple compressor effect, code thanks to Eric Tarr @hackaudio
    Inputs:
       x:        the input waveform
       thresh:   threshold in dB
       ratio:    compression ratio
       attackrel:   attack & release time in seconds
       sr:       sample rate
    """
    attack = attackrel * sr  # convert to samples
    fc = 1.0/float(attack)     # this is like 1/attack time
    b, a = scipy_signal.butter(1, fc, analog=False, output='ba')
    zi = scipy_signal.lfilter_zi(b, a)

    dB = 20. * np.log10(np.abs(x) + 1e-6)
    in_env, _ = scipy_signal.lfilter(b, a, dB, zi=zi*dB[0])  # input envelope calculation
    out_env = np.copy(in_env)              # output envelope
    i = np.where(in_env >  thresh)          # compress where input env exceeds thresh
    out_env[i] = thresh + (in_env[i]-thresh)/ratio
    gain = np.power(10.0,(out_env-in_env)/20)
    y = x * gain
    return y 
開發者ID:drscotthawley,項目名稱:signaltrain,代碼行數:25,代碼來源:audio.py

示例7: discount_cumsum

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def discount_cumsum(x, discount):
    """
    Forked from rllab for computing discounted cumulative sums of vectors.

    :param x (np.ndarray or tf.Tensor)
        vector of [x0, x1, x2]
    :return output:
        [x0 + discount * x1 + discount^2 * x2,  
         x1 + discount * x2,
         x2]
    """
    return lfilter(
        b=[1],
        a=[1, float(-discount)],
        x=x[::-1],
        axis=0)[::-1] 
開發者ID:keiohta,項目名稱:tf2rl,代碼行數:18,代碼來源:discount_cumsum.py

示例8: geterrors

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def geterrors(self, params):
        #copied from sandbox.tsa.arima.ARIMA
        p, q = self.nar, self.nma
        ar = np.concatenate(([1], -params[:p]))
        ma = np.concatenate(([1], params[p:p+q]))

        #lfilter_zi requires same length for ar and ma
        maxlag = 1+max(p,q)
        armax = np.zeros(maxlag)
        armax[:p+1] = ar
        mamax = np.zeros(maxlag)
        mamax[:q+1] = ma
        #remove zi again to match better with Skipper's version
        #zi = signal.lfilter_zi(armax, mamax)
        #errorsest = signal.lfilter(rhoy, rhoe, self.endog, zi=zi)[0] #zi is also returned
        errorsest = signal.lfilter(ar, ma, self.endog)
        return errorsest 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:19,代碼來源:arma_mle.py

示例9: generate_garch

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def generate_garch(nobs, ar, ma, mu=1., scale=0.1):
    '''simulate standard garch

    scale : float
       scale/standard deviation of innovation process in GARCH process
    '''

    eta = scale*np.random.randn(nobs)
    # copied from armageneratesample
    h = signal.lfilter(ma, ar, eta**2)

    #
    #h = (mu+h)**2
    #h = np.abs(h)
    #h = np.exp(h)
    #err = np.sqrt(h)*np.random.randn(nobs)
    err = np.sqrt(h)*eta #np.random.standard_t(8, size=nobs)
    return err, h 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:20,代碼來源:garch.py

示例10: filter

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def filter(self, x):
        '''
        filter a timeseries with the ARMA filter

        padding with zero is missing, in example I needed the padding to get
        initial conditions identical to direct filter

        Initial filtered observations differ from filter2 and signal.lfilter, but
        at end they are the same.

        See Also
        --------
        tsa.filters.fftconvolve

        '''
        n = x.shape[0]
        if n == self.fftarma:
            fftarma = self.fftarma
        else:
            fftarma = self.fftma(n) / self.fftar(n)
        tmpfft = fftarma * fft.fft(x)
        return fft.ifft(tmpfft) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:24,代碼來源:fftarma.py

示例11: filter2

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def filter2(self, x, pad=0):
        '''filter a time series using fftconvolve3 with ARMA filter

        padding of x currently works only if x is 1d
        in example it produces same observations at beginning as lfilter even
        without padding.

        TODO: this returns 1 additional observation at the end
        '''
        from statsmodels.tsa.filters import fftconvolve3
        if not pad:
            pass
        elif pad == 'auto':
            #just guessing how much padding
            x = self.padarr(x, x.shape[0] + 2*(self.nma+self.nar), atend=False)
        else:
            x = self.padarr(x, x.shape[0] + int(pad), atend=False)

        return fftconvolve3(x, self.ma, self.ar) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:21,代碼來源:fftarma.py

示例12: exactprocess

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def exactprocess(self, xzero, nobs, ddt=1., nrepl=2):
        '''ddt : discrete delta t



        should be the same as an AR(1)
        not tested yet
        '''
        t = np.linspace(ddt, nobs*ddt, nobs)
        #expnt = np.exp(-self.lambd * t)
        expddt = np.exp(-self.lambd * ddt)
        normrvs = np.random.normal(size=(nrepl,nobs))
        #do I need lfilter here AR(1) ? if mean reverting lag-coeff<1
        #lfilter doesn't handle 2d arrays, it does?
        inc = self._exactconst(expddt) + self._exactstd(expddt) * normrvs
        return signal.lfilter([1.], [1.,-expddt], inc) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:18,代碼來源:diffusion.py

示例13: impz

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def impz(b,a):
    """Pseudo implementation of the impz method of MATLAB"""
#% Compute time vector
# M = 0;  NN = [];
# if isempty(N)
#   % if not specified, determine the length
#   if isTF
#     N = impzlength(b,a,.00005);
#   else
#     N  = impzlength(b,.00005);
#   end
    p = np.roots(a)
    N = stableNmarginal_length(p, 0.00005, 0)
    N = len(b) * len(b) * len(b) # MATLAB AUTOFINDS THE SIZE HERE... 
    #TODO: Implement some way of finding the autosieze of this... I used a couple of examples... matlab gave 43 as length we give 64
    x = zeros(N)
    x[0] = 1
    h = lfilter(b,a, x)
    return h 
開發者ID:awesomebytes,項目名稱:parametric_modeling,代碼行數:21,代碼來源:impz.py

示例14: preemphasis

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def preemphasis(wav, coeff=0.97):
    """
    Emphasize high frequency range of the waveform by increasing power(squared amplitude).
    
    Parameters
    ----------
    wav : np.ndarray [shape=(n,)]
        Real-valued the waveform.

    coeff: float <= 1 [scalar]
        Coefficient of pre-emphasis.

    Returns
    -------
    preem_wav : np.ndarray [shape=(n,)]
        The pre-emphasized waveform.
    """
    preem_wav = signal.lfilter([1, -coeff], [1], wav)
    return preem_wav 
開發者ID:andabi,項目名稱:voice-vector,代碼行數:21,代碼來源:audio.py

示例15: inv_preemphasis

# 需要導入模塊: from scipy import signal [as 別名]
# 或者: from scipy.signal import lfilter [as 別名]
def inv_preemphasis(preem_wav, coeff=0.97):
    """
    Invert the pre-emphasized waveform to the original waveform.
    
    Parameters
    ----------
    preem_wav : np.ndarray [shape=(n,)]
        The pre-emphasized waveform.

    coeff: float <= 1 [scalar]
        Coefficient of pre-emphasis.

    Returns
    -------
    wav : np.ndarray [shape=(n,)]
        Real-valued the waveform.
    """
    wav = signal.lfilter([1], [1, -coeff], preem_wav)
    return wav 
開發者ID:andabi,項目名稱:voice-vector,代碼行數:21,代碼來源:audio.py


注:本文中的scipy.signal.lfilter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。