def parse_filter(args, analog=False, sample_rate=None):
if analog and not sample_rate:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if isinstance(args, tuple) and len(args) == <NUM_LIT:1>:<EOL><INDENT>args = args[<NUM_LIT:0>]<EOL><DEDENT>if isinstance(args, numpy.ndarray) and args.ndim == <NUM_LIT:1>:  <EOL><INDENT>b, a = args, [<NUM_LIT:1.>]<EOL>if analog:<EOL><INDENT>return '<STR_LIT>', signal.bilinear(b, a)<EOL><DEDENT>return '<STR_LIT>', (b, a)<EOL><DEDENT>if isinstance(args, LinearTimeInvariant):<EOL><INDENT>lti = args<EOL><DEDENT>elif (isinstance(args, numpy.ndarray) and<EOL>args.ndim == <NUM_LIT:2> and args.shape[<NUM_LIT:1>] == <NUM_LIT:6>):<EOL><INDENT>lti = signal.lti(*signal.sos2zpk(args))<EOL><DEDENT>else:<EOL><INDENT>lti = signal.lti(*args)<EOL><DEDENT>try:<EOL><INDENT>lti = lti.to_zpk()<EOL><DEDENT>except AttributeError:  <EOL><INDENT>pass<EOL><DEDENT>if analog:<EOL><INDENT>return '<STR_LIT>', bilinear_zpk(lti.zeros, lti.poles, lti.gain,<EOL>fs=sample_rate)<EOL><DEDENT>return '<STR_LIT>', (lti.zeros, lti.poles, lti.gain)<EOL>
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