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 = np.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")
  
      result_type = x.dtype
      if result_type.kind in "bui":
          result_type = np.float64
      b = np.asarray(b, dtype=result_type)
      a = np.asarray(a, dtype=result_type)
  
      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: import operator
  import math
  import timeit
  from scipy.spatial import cKDTree
  from .None import sigtools, dlti
  from ._upfirdn import upfirdn, _output_len, _upfirdn_modes
  from scipy import linalg, fft
  from scipy.fft._helper import _init_nd_shape_and_axes
  from scipy._lib._util import prod
  import numpy
  from scipy.special import lambertw
  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
  from ._sosfilt import _sosfilt
  import warnings
label_desc: Use image node_id 53 for calling a global function with example usage: decimate(x, q, n, ftype, axis, zero_phase) and returns: y