code: def parse_filter(args, analog=False, sample_rate=None):
      
      if analog and not sample_rate:
          raise ValueError("Must give sample_rate frequency to convert "
                           "analog filter to digital")
  
      # unpack filter
      if isinstance(args, tuple) and len(args) == 1:
          # either packed defintion ((z, p, k)) or simple definition (lti,)
          args = args[0]
  
      # parse FIR filter
      if isinstance(args, numpy.ndarray) and args.ndim == 1:  # fir
          b, a = args, [1.]
          if analog:
              return 'ba', signal.bilinear(b, a)
          return 'ba', (b, a)
  
      # parse IIR filter
      if isinstance(args, LinearTimeInvariant):
          lti = args
      elif (isinstance(args, numpy.ndarray) and
              args.ndim == 2 and args.shape[1] == 6):
          lti = signal.lti(*signal.sos2zpk(args))
      else:
          lti = signal.lti(*args)
  
      # convert to zpk format
      try:
          lti = lti.to_zpk()
      except AttributeError:  # scipy < 0.18, doesn't matter
          pass
  
      # convert to digital components
      if analog:
          return 'zpk', bilinear_zpk(lti.zeros, lti.poles, lti.gain,
                                     fs=sample_rate)
      # return zpk
      return 'zpk', (lti.zeros, lti.poles, lti.gain)
docs: Parse arbitrary input args into a TF or ZPK filter definition
  
      Parameters
      ----------
      args : `tuple`, `~scipy.signal.lti`
          filter definition, normally just captured positional ``*args``
          from a function call
  
      analog : `bool`, optional
          `True` if filter definition has analogue coefficients
  
      sample_rate : `float`, optional
          sampling frequency at which to convert analogue filter to digital
          via bilinear transform, required if ``analog=True``
  
      Returns
      -------
      ftype : `str`
          either ``'ba'`` or ``'zpk'``
      filt : `tuple`
          the filter components for the returned `ftype`, either a 2-tuple
          for with transfer function components, or a 3-tuple for ZPK