Example #1
0
def decimate_filtfilt(x, q, n=None, ftype='iir', axis=-1, zerophase=True):
    """
    Downsample the signal by using a filter.

    By default, an order 8 Chebyshev type I filter is used.  A 30 point FIR
    filter with hamming window is used if `ftype` is 'fir'.

    Parameters
    ----------
    x : ndarray
        The signal to be downsampled, as an N-dimensional array.
    q : int
        The downsampling factor.
    n : int, optional
        The order of the filter (1 less than the length for 'fir').
    ftype : str {'iir', 'fir'}, optional
        The type of the lowpass filter.
    axis : int, optional
        The axis along which to decimate.

    Returns
    -------
    y : ndarray
        The down-sampled signal.

    See also
    --------
    resample

    """

    if not isinstance(q, int):
        raise TypeError("q must be an integer")

    if n is None:
        if ftype == 'fir':
            n = 30
        else:
            n = 8

    if ftype == 'fir':
        b = firwin(n + 1, 1. / q, window='hamming')
        a = 1.
    else:
        b, a = cheby1(n, 0.05, 0.8 / q)

    if zerophase == True:
        y = signal.filtfilt(b, a, x, axis=axis)
    elif zerophase == False:
        y = signal.lfilter(b, a, x, axis=axis)

    sl = [slice(None)] * y.ndim
    sl[axis] = slice(None, None, q)
    return y[sl]
Example #2
0
def decimate(x, q, n=None, ftype='iir', axis=-1):
    """Downsample the signal `x` by an integer factor `q`, using an order `n` 
    filter.

    By default, an order 8 Chebyshev type I filter is used.  A 30 point FIR
    filter with hamming window is used if `ftype` is 'fir'.

    Parameters
    ----------
    x : N-d array
      the signal to be downsampled
    q : int
      the downsampling factor
    n : int or None
      the order of the filter (1 less than the length for 'fir')
    ftype : {'iir' or 'fir'}
      the type of the lowpass filter
    axis : int
      the axis along which to decimate

    Returns
    -------
    y : N-d array
      the down-sampled signal

    See also
    --------
    resample
    """

    if not isinstance(q, int):
        raise TypeError("q must be an integer")

    if n is None:
        if ftype == 'fir':
            n = 30
        else:
            n = 8

    if ftype == 'fir':
        b = firwin(n + 1, 1. / q, window='hamming')
        a = 1.
    else:
        b, a = cheby1(n, 0.05, 0.8 / q)

    y = lfilter(b, a, x, axis=axis)

    sl = [slice(None)] * y.ndim
    sl[axis] = slice(None, None, q)
    return y[sl]
Example #3
0
def decimate(x, q, n=None, ftype='iir', axis=-1):
    """Downsample the signal `x` by an integer factor `q`, using an order `n` 
    filter.

    By default, an order 8 Chebyshev type I filter is used.  A 30 point FIR
    filter with hamming window is used if `ftype` is 'fir'.

    Parameters
    ----------
    x : N-d array
      the signal to be downsampled
    q : int
      the downsampling factor
    n : int or None
      the order of the filter (1 less than the length for 'fir')
    ftype : {'iir' or 'fir'}
      the type of the lowpass filter
    axis : int
      the axis along which to decimate

    Returns
    -------
    y : N-d array
      the down-sampled signal

    See also
    --------
    resample
    """

    if not isinstance(q, int):
        raise TypeError("q must be an integer")

    if n is None:
        if ftype == 'fir':
            n = 30
        else:
            n = 8

    if ftype == 'fir':
        b = firwin(n + 1, 1. / q, window='hamming')
        a = 1.
    else:
        b, a = cheby1(n, 0.05, 0.8 / q)

    y = lfilter(b, a, x, axis=axis)

    sl = [slice(None)] * y.ndim
    sl[axis] = slice(None, None, q)
    return y[sl]
Example #4
0
def decimate_filtfilt(x, q, n=None, ftype='iir', axis=-1):
    """
    Downsample the signal by using a filter.
    By default, an order 8 Chebyshev type I filter is used.  A 30 point FIR
    filter with hamming window is used if `ftype` is 'fir'.
    Parameters
    ----------
    x : ndarray
        The signal to be downsampled, as an N-dimensional array.
    q : int
        The downsampling factor.
    n : int, optional
        The order of the filter (1 less than the length for 'fir').
    ftype : str {'iir', 'fir'}, optional
        The type of the lowpass filter.
    axis : int, optional
        The axis along which to decimate.
    Returns
    -------
    y : ndarray
        The down-sampled signal.
    See also
    --------
    resample
    """
    if not isinstance(q, int):
        raise TypeError("q must be an integer")

    if n is None:
        if ftype == 'fir':
            n = 30
        else:
            n = 8

    if ftype == 'fir':
        b = firwin(n + 1, 1. / q, window='hamming')
        a = 1.
    else:
        b, a = cheby1(n, 0.05, 0.8 / q)

    y = filtfilt(b, a, x, axis=axis)

    sl = [slice(None)] * y.ndim
    sl[axis] = slice(None, None, q)
    return y[sl]
Example #5
0
def cheby1_bp(ripple, lo=0, hi=0, Fs=2.0, ord=3):
    freqs, btype = _bandpass_params(lo, hi)
    return fdesign.cheby1(ord, ripple, 2 * freqs / Fs, btype=btype)