code: def amdf(lag, size):
    
    filt = (1 - z ** -lag).linearize()
  
    @tostream
    def amdf_filter(sig, zero=0.):
      return maverage(size)(abs(filt(sig, zero=zero)), zero=zero)
  
    return amdf_filter
docs: Average Magnitude Difference Function non-linear filter for a given
    size and a fixed lag.
  
    Parameters
    ----------
    lag :
      Time lag, in samples. See ``freq2lag`` if needs conversion from
      frequency values.
    size :
      Moving average size.
  
    Returns
    -------
    A callable that accepts two parameters: a signal ``sig`` and the starting
    memory element ``zero`` that behaves like the ``LinearFilter.__call__``
    arguments. The output from that callable is a Stream instance, and has
    no decimation applied.
  
    See Also
    --------
    freq2lag :
      Frequency (in rad/sample) to lag (in samples) converter.