# Path: wyrm/processing.py
# def lfilter_zi(b, a, n=1):
#     """Compute an initial state ``zi`` for the :func:`lfilter` function.
# 
#     When ``n == 1`` (default), this method mainly delegates the call to
#     :func:`scipy.signal.lfilter_zi` and returns the result ``zi``. If
#     ``n > 1``, ``zi``  is repeated ``n`` times. This is useful if you
#     want to filter n-dimensional data like multi channel EEG.
# 
#     Parameters
#     ----------
#     b, a : 1-d array
#         The IIR filter coefficients
#     n : int, optional
#         The desired width of the output vector. If ``n == 1`` the output
#         is simply the 1d zi vector. For ``n > 1``, the zi vector is
#         repeated ``n`` times.
# 
#     Returns
#     -------
#     zi : n-d array
#         The initial state of the filter.
# 
#     See Also
#     --------
#     :func:`lfilter`, :func:`scipy.signal.lfilter_zi`
# 
#     Examples
#     --------
# 
#     >>> # pre-calculate the filter coefficients and the initial filter
#     >>> # state
#     >>> b, a = signal.butter(butter_ord, [f_low / fn, f_high / fn], btype='band')
#     >>> zi = proc.lfilter_zi(b, a, len(CHANNELS))
#     >>> while 1:
#     ...     data, markers = amp.get_data()
#     ...     # convert incoming data into ``Data`` object
#     ...     cnt = Data(data, ...)
#     ...     # filter the data, note how filter now also returns the
#     ...     # filter state which we feed back into the next call of
#     ...     # ``filter``
#     ...     cnt, zi = lfilter(cnt, b, a, zi=zi)
#     ...     ...
# 
#     """
#     zi = signal.lfilter_zi(b, a)
#     if n > 1:
#         zi = np.tile(zi, (n, 1)).T
#     return zi


import unittest
import numpy as np
from wyrm.processing import lfilter_zi
from __future__ import division





class TestLFilterZi(unittest.TestCase):

    COEFFS = 10

    def setUp(self):
        self.b, self.a = np.ones(self.COEFFS), np.ones(self.COEFFS)

    def test_lfilter_1d(self):
        """Output has the correct shape for n=1."""
        zi = lfilter_zi(self.b, self.a)
        self.assertEqual(len(zi), self.COEFFS - 1)

    def test_lfilter_nd(self):
        """Output has the correct shape for n>1."""

# Path: wyrm/processing.py
# def lfilter_zi(b, a, n=1):
#     """Compute an initial state ``zi`` for the :func:`lfilter` function.
# 
#     When ``n == 1`` (default), this method mainly delegates the call to
#     :func:`scipy.signal.lfilter_zi` and returns the result ``zi``. If
#     ``n > 1``, ``zi``  is repeated ``n`` times. This is useful if you
#     want to filter n-dimensional data like multi channel EEG.
# 
#     Parameters
#     ----------
#     b, a : 1-d array
#         The IIR filter coefficients
#     n : int, optional
#         The desired width of the output vector. If ``n == 1`` the output
#         is simply the 1d zi vector. For ``n > 1``, the zi vector is
#         repeated ``n`` times.
# 
#     Returns
#     -------
#     zi : n-d array
#         The initial state of the filter.
# 
#     See Also
#     --------
#     :func:`lfilter`, :func:`scipy.signal.lfilter_zi`
# 
#     Examples
#     --------
# 
#     >>> # pre-calculate the filter coefficients and the initial filter
#     >>> # state
#     >>> b, a = signal.butter(butter_ord, [f_low / fn, f_high / fn], btype='band')
#     >>> zi = proc.lfilter_zi(b, a, len(CHANNELS))
#     >>> while 1:
#     ...     data, markers = amp.get_data()
#     ...     # convert incoming data into ``Data`` object
#     ...     cnt = Data(data, ...)
#     ...     # filter the data, note how filter now also returns the
#     ...     # filter state which we feed back into the next call of
#     ...     # ``filter``
#     ...     cnt, zi = lfilter(cnt, b, a, zi=zi)
#     ...     ...
# 
#     """
#     zi = signal.lfilter_zi(b, a)
#     if n > 1:
#         zi = np.tile(zi, (n, 1)).T
#     return zi


# Path: test/test_lfilter_zi.py
import unittest
import numpy as np
from wyrm.processing import lfilter_zi

from __future__ import division





class TestLFilterZi(unittest.TestCase):

    COEFFS = 10

    def setUp(self):
        self.b, self.a = np.ones(self.COEFFS), np.ones(self.COEFFS)

    def test_lfilter_1d(self):
        """Output has the correct shape for n=1."""
        zi = lfilter_zi(self.b, self.a)
        self.assertEqual(len(zi), self.COEFFS - 1)

    def test_lfilter_nd(self):
        """Output has the correct shape for n>1."""

        zi = lfilter_zi(self.b, self.a, 7)