code: def decimate(x, q, n=None, ftype="iir", axis=-1, zero_phase=True):
      """
      Downsample the signal after applying an anti-aliasing 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 : array_like
          The signal to be downsampled, as an N-dimensional array.
      q : int
          The downsampling factor. When using IIR downsampling, it is recommended
          to call `decimate` multiple times for downsampling factors higher than
          13.
      n : int, optional
          The order of the filter (1 less than the length for 'fir'). Defaults to
          8 for 'iir' and 20 times the downsampling factor for 'fir'.
      ftype : str {'iir', 'fir'} or ``dlti`` instance, optional
          If 'iir' or 'fir', specifies the type of lowpass filter. If an instance
          of an `dlti` object, uses that object to filter before downsampling.
      axis : int, optional
          The axis along which to decimate.
      zero_phase : bool, optional
          Prevent phase shift by filtering with `filtfilt` instead of `lfilter`
          when using an IIR filter, and shifting the outputs back by the filter's
          group delay when using an FIR filter. The default value of ``True`` is
          recommended, since a phase shift is generally not desired.
  
          .. versionadded:: 0.18.0
  
      Returns
      -------
      y : ndarray
          The down-sampled signal.
  
      See Also
      --------
      resample : Resample up or down using the FFT method.
      resample_poly : Resample using polyphase filtering and an FIR filter.
  
      Notes
      -----
      The ``zero_phase`` keyword was added in 0.18.0.
      The possibility to use instances of ``dlti`` as ``ftype`` was added in
      0.18.0.
      """
  
      x = asarray(x)
      q = operator.index(q)
  
      if n is not None:
          n = operator.index(n)
  
      if ftype == "fir":
          if n is None:
              half_len = (
                  10 * q
              )  # reasonable cutoff for our sinc-like function
              n = 2 * half_len
          b, a = firwin(n + 1, 1.0 / q, window="hamming"), 1.0
      elif ftype == "iir":
          if n is None:
              n = 8
          system = dlti(*cheby1(n, 0.05, 0.8 / q))
          b, a = system.num, system.den
      elif isinstance(ftype, dlti):
          system = (
              ftype._as_tf()
          )  # Avoids copying if already in TF form
          b, a = system.num, system.den
      else:
          raise ValueError("invalid ftype")
  
      sl = [slice(None)] * x.ndim
      a = np.asarray(a)
  
      if a.size == 1:  # FIR case
          b = b / a
          if zero_phase:
              y = resample_poly(x, 1, q, axis=axis, window=b)
          else:
              # upfirdn is generally faster than lfilter by a factor equal to the
              # downsampling factor, since it only calculates the needed outputs
              n_out = x.shape[axis] // q + bool(x.shape[axis] % q)
              y = upfirdn(b, x, up=1, down=q, axis=axis)
              sl[axis] = slice(None, n_out, None)
  
      else:  # IIR case
          if zero_phase:
              y = filtfilt(b, a, x, axis=axis)
          else:
              y = lfilter(b, a, x, axis=axis)
          sl[axis] = slice(None, None, q)
  
      return y[tuple(sl)]
  
imports: from __future__ import division, print_function, absolute_import
  import operator
  import threading
  import sys
  import timeit
  from scipy.spatial import cKDTree
  from .None import sigtools, dlti
  from ._upfirdn import upfirdn, _output_len
  from scipy._lib.six import callable
  from scipy._lib._version import NumpyVersion
  from scipy import fftpack, linalg
  from scipy.fftpack.helper import _init_nd_shape_and_axes_sorted
  from numpy import allclose, angle, arange, argsort, array, asarray, atleast_1d, atleast_2d, cast, dot, exp, expand_dims, iscomplexobj, mean, ndarray, newaxis, ones, pi, poly, polyadd, polyder, polydiv, polymul, polysub, polyval, product, r_, ravel, real_if_close, reshape, roots, sort, take, transpose, unique, where, zeros, zeros_like
  import numpy
  import math
  from scipy.special import factorial
  from .windows import get_window
  from ._arraytools import axis_slice, axis_reverse, odd_ext, even_ext, const_ext
  from .filter_design import cheby1, _validate_sos
  from .fir_filter_design import firwin
label_desc: Use image node_id 43 for calling a global function with example usage: decimate(x, q, n, ftype, axis, zero_phase) and returns: y