# Path: sprocket/util/filter.py
# def low_pass_filter(data, cutoff, fs, n_taps=255):
#     """Apply low-pass filter
# 
#     Parameters
#     ----------
#     data : array, shape (`T`, `dim`)
#         Array of sequence.
#     cutoff : int,
#         Cutoff frequency
#     fs : int,
#         Sampling frequency
#     n_taps : int, optional
#         Tap number
# 
#     Returns
#     -------
#     modified data: array, shape (`T`, `dim`)
#         Array of modified sequence.
#     """
#     if data.shape[0] < n_taps * 3:
#         raise ValueError(
#             'Length of data should be three times longer than n_taps.')
# 
#     fil = firwin(n_taps, cutoff, pass_zero=True, nyq=fs//2)
#     modified_data = filtfilt(fil, 1, data, axis=0)
#     return modified_data
# 
# def high_pass_filter(data, cutoff, fs, n_taps=255):
#     """Apply high-pass filter
# 
#     Parameters
#     ----------
#     data : array, shape (`T`, `dim`)
#         Array of sequence.
#     cutoff : int,
#         Cutoff frequency
#     fs : int,
#         Sampling frequency
#     n_taps : int, optional
#         Tap number
# 
#     Returns
#     -------
#     modified data: array, shape (`T`, `dim`)
#         Array of modified sequence.
#     """
#     if data.shape[0] < n_taps * 3:
#         raise ValueError(
#             'Length of data should be three times longer than n_taps.')
# 
#     fil = firwin(n_taps, cutoff, pass_zero=False, nyq=fs//2)
#     modified_data = filtfilt(fil, 1, data, axis=0)
#     return modified_data


import unittest
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from sprocket.util.filter import low_pass_filter, high_pass_filter

matplotlib.use('Agg')


saveflag = False


class FilterFunctionsTest(unittest.TestCase):

    def test_filter(self):
        fs = 8000
        f0 = 440
        sin = np.array([np.sin(2.0 * np.pi * f0 * n / fs)
                        for n in range(fs * 1)])
        noise = np.random.rand(len(sin)) - 0.5
        wav = sin + noise
        lpfed = low_pass_filter(wav, 500, n_taps=255, fs=fs)
        hpfed = high_pass_filter(wav, 1000, n_taps=255, fs=fs)

        lpfed_2d = low_pass_filter(np.vstack([wav, noise]).T, 500, fs=fs)

# Path: sprocket/util/filter.py
# def low_pass_filter(data, cutoff, fs, n_taps=255):
#     """Apply low-pass filter
# 
#     Parameters
#     ----------
#     data : array, shape (`T`, `dim`)
#         Array of sequence.
#     cutoff : int,
#         Cutoff frequency
#     fs : int,
#         Sampling frequency
#     n_taps : int, optional
#         Tap number
# 
#     Returns
#     -------
#     modified data: array, shape (`T`, `dim`)
#         Array of modified sequence.
#     """
#     if data.shape[0] < n_taps * 3:
#         raise ValueError(
#             'Length of data should be three times longer than n_taps.')
# 
#     fil = firwin(n_taps, cutoff, pass_zero=True, nyq=fs//2)
#     modified_data = filtfilt(fil, 1, data, axis=0)
#     return modified_data
# 
# def high_pass_filter(data, cutoff, fs, n_taps=255):
#     """Apply high-pass filter
# 
#     Parameters
#     ----------
#     data : array, shape (`T`, `dim`)
#         Array of sequence.
#     cutoff : int,
#         Cutoff frequency
#     fs : int,
#         Sampling frequency
#     n_taps : int, optional
#         Tap number
# 
#     Returns
#     -------
#     modified data: array, shape (`T`, `dim`)
#         Array of modified sequence.
#     """
#     if data.shape[0] < n_taps * 3:
#         raise ValueError(
#             'Length of data should be three times longer than n_taps.')
# 
#     fil = firwin(n_taps, cutoff, pass_zero=False, nyq=fs//2)
#     modified_data = filtfilt(fil, 1, data, axis=0)
#     return modified_data


# Path: sprocket/util/tests/test_filter.py
import unittest
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from sprocket.util.filter import low_pass_filter, high_pass_filter


matplotlib.use('Agg')


saveflag = False


class FilterFunctionsTest(unittest.TestCase):

    def test_filter(self):
        fs = 8000
        f0 = 440
        sin = np.array([np.sin(2.0 * np.pi * f0 * n / fs)
                        for n in range(fs * 1)])
        noise = np.random.rand(len(sin)) - 0.5
        wav = sin + noise
        lpfed = low_pass_filter(wav, 500, n_taps=255, fs=fs)
        hpfed = high_pass_filter(wav, 1000, n_taps=255, fs=fs)

        lpfed_2d = low_pass_filter(np.vstack([wav, noise]).T, 500, fs=fs)

        hpfed_2d = high_pass_filter(np.vstack([wav, noise]).T, 1000, fs=fs)