def decimate(x, q=<NUM_LIT:10>, n=<NUM_LIT:4>, k=<NUM_LIT>, filterfun=ss.cheby1):
if not isinstance(q, int):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if n is None:<EOL><INDENT>n = <NUM_LIT:1><EOL><DEDENT>if filterfun == ss.butter:<EOL><INDENT>b, a = filterfun(n, k / q)<EOL><DEDENT>elif filterfun == ss.cheby1:<EOL><INDENT>b, a = filterfun(n, <NUM_LIT>, k / q)<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>y = ss.filtfilt(b, a, x)<EOL><DEDENT>except: <EOL><INDENT>y = []<EOL>for data in x:<EOL><INDENT>y.append(ss.filtfilt(b, a, data))<EOL><DEDENT>y = np.array(y)<EOL><DEDENT>try:<EOL><INDENT>return y[:, ::q]<EOL><DEDENT>except:<EOL><INDENT>return y[::q]<EOL><DEDENT>
scipy.signal.decimate like downsampling using filtfilt instead of lfilter,
and filter coeffs from butterworth or chebyshev type 1.


Parameters
----------
x : numpy.ndarray
    Array to be downsampled along last axis.
q : int 
    Downsampling factor.
n : int
    Filter order.
k : float
    Aliasing filter critical frequency Wn will be set as Wn=k/q.
filterfun : function
    `scipy.signal.filter_design.cheby1` or
    `scipy.signal.filter_design.butter` function

Returns
-------
numpy.ndarray
    Array of downsampled signal.