# Path: pysmo/aimbat/filtering.py
# def filtering_time_freq(originalTime, originalSignalTime, delta, filterType, highFreq, lowFreq, order, runReversePass = False):
# 	originalFreq, originalSignalFreq = time_to_freq(originalTime, originalSignalTime, delta)
# 
# 	# make filter, default is bandpass
# 	MULTIPLE = 0.7*max(np.abs(originalSignalFreq))
# 	NYQ, Wn, B, A, adjusted_w, adjusted_h = get_filter_params(delta, lowFreq, highFreq, filterType, order, MULTIPLE)
# 
# 	# apply filter
# 	filteredSignalTime = signal.lfilter(B, A, originalSignalTime)
# 	if runReversePass:
# 		filteredSignalTime = signal.lfilter(B, A, filteredSignalTime[::-1])
# 		filteredSignalTime = filteredSignalTime[::-1]
# 
# 	# convert filtered time signal -> frequency signal
# 	filteredSignalFreq = np.fft.fft(filteredSignalTime)
# 
# 	return filteredSignalTime, filteredSignalFreq, adjusted_w, adjusted_h
# 
# def get_filter_params(delta, lowFreq, highFreq, filterType, order, MULTIPLE=3000):
# 	NYQ = 1.0/(2*delta)
# 	Wn = [lowFreq/NYQ, highFreq/NYQ]
# 	B, A = signal.butter(order, Wn, analog=False, btype='bandpass')
# 	if filterType=='lowpass':
# 		Wn = lowFreq/NYQ
# 		B, A = signal.butter(order, Wn, analog=False, btype='lowpass')
# 	elif filterType=='highpass':
# 		Wn = highFreq/NYQ
# 		B, A = signal.butter(order, Wn, analog=False, btype='highpass')
# 
# 	w, h = signal.freqz(B, A)
# 	adjusted_w = w*(NYQ/np.pi)
# 	adjusted_h = MULTIPLE*np.abs(h)
# 
# 	return NYQ, Wn, B, A, adjusted_w, adjusted_h
# 
# def filtering_time_signal(originalSignalTime, delta, lowFreq, highFreq, filterType, order, MULTIPLE, runReversePass = False):
# 	NYQ, Wn, B, A, w, h = get_filter_params(delta, lowFreq, highFreq, filterType, order, MULTIPLE)
# 	filteredSignalTime = signal.lfilter(B, A, originalSignalTime)
# 	if runReversePass:
# 		filteredSignalTime = signal.lfilter(B, A, filteredSignalTime[::-1])
# 		filteredSignalTime = filteredSignalTime[::-1]
# 	return filteredSignalTime
# 
# def time_to_freq(originalTime, originalSignalTime, delta):
# 	originalFreq = np.fft.fftfreq(len(originalTime), delta) 
# 	originalSignalFreq = np.fft.fft(originalSignalTime) 
# 	return originalFreq, originalSignalFreq


import unittest
import numpy as np
from pysmo.aimbat.filtering import filtering_time_freq, get_filter_params, filtering_time_signal, time_to_freq
        NYQ, Wn, B, A, w, h = get_filter_params(delta_time, lowFreq, highFreq, filterType, order)

        for i in xrange(len(w)):
            if h[i] > 1000 and w[i] > 0: #broad spike
                self.assertFalse(w[i] < 0.5*lowFreq)
                self.assertFalse(w[i] > 1.5*highFreq)

        # --------
        #         \
        #          \
        #  LOWPASS  \
        #            \
        # ------------
        # signal drops sharply after lowFreq
        filterType = 'lowpass'
        NYQ, Wn, B, A, w, h = get_filter_params(delta_time, lowFreq, highFreq, filterType, order)

        for i in xrange(len(w)):
            if h[i] > 1000 and w[i] > 0:    #broad spike
                self.assertFalse(w[i] > 1.5*lowFreq)    #not allowed to spike pas lowFreq

        #        --------
        #       /
        #      /
        #     /
        #    /  HIGHPASS
        #   /
        #   -------------
        #signal is low before highFreq
        filterType = 'highpass'

# Path: pysmo/aimbat/filtering.py
# def filtering_time_freq(originalTime, originalSignalTime, delta, filterType, highFreq, lowFreq, order, runReversePass = False):
# 	originalFreq, originalSignalFreq = time_to_freq(originalTime, originalSignalTime, delta)
# 
# 	# make filter, default is bandpass
# 	MULTIPLE = 0.7*max(np.abs(originalSignalFreq))
# 	NYQ, Wn, B, A, adjusted_w, adjusted_h = get_filter_params(delta, lowFreq, highFreq, filterType, order, MULTIPLE)
# 
# 	# apply filter
# 	filteredSignalTime = signal.lfilter(B, A, originalSignalTime)
# 	if runReversePass:
# 		filteredSignalTime = signal.lfilter(B, A, filteredSignalTime[::-1])
# 		filteredSignalTime = filteredSignalTime[::-1]
# 
# 	# convert filtered time signal -> frequency signal
# 	filteredSignalFreq = np.fft.fft(filteredSignalTime)
# 
# 	return filteredSignalTime, filteredSignalFreq, adjusted_w, adjusted_h
# 
# def get_filter_params(delta, lowFreq, highFreq, filterType, order, MULTIPLE=3000):
# 	NYQ = 1.0/(2*delta)
# 	Wn = [lowFreq/NYQ, highFreq/NYQ]
# 	B, A = signal.butter(order, Wn, analog=False, btype='bandpass')
# 	if filterType=='lowpass':
# 		Wn = lowFreq/NYQ
# 		B, A = signal.butter(order, Wn, analog=False, btype='lowpass')
# 	elif filterType=='highpass':
# 		Wn = highFreq/NYQ
# 		B, A = signal.butter(order, Wn, analog=False, btype='highpass')
# 
# 	w, h = signal.freqz(B, A)
# 	adjusted_w = w*(NYQ/np.pi)
# 	adjusted_h = MULTIPLE*np.abs(h)
# 
# 	return NYQ, Wn, B, A, adjusted_w, adjusted_h
# 
# def filtering_time_signal(originalSignalTime, delta, lowFreq, highFreq, filterType, order, MULTIPLE, runReversePass = False):
# 	NYQ, Wn, B, A, w, h = get_filter_params(delta, lowFreq, highFreq, filterType, order, MULTIPLE)
# 	filteredSignalTime = signal.lfilter(B, A, originalSignalTime)
# 	if runReversePass:
# 		filteredSignalTime = signal.lfilter(B, A, filteredSignalTime[::-1])
# 		filteredSignalTime = filteredSignalTime[::-1]
# 	return filteredSignalTime
# 
# def time_to_freq(originalTime, originalSignalTime, delta):
# 	originalFreq = np.fft.fftfreq(len(originalTime), delta) 
# 	originalSignalFreq = np.fft.fft(originalSignalTime) 
# 	return originalFreq, originalSignalFreq


# Path: tests/filtering_tests.py
import unittest
import numpy as np
from pysmo.aimbat.filtering import filtering_time_freq, get_filter_params, filtering_time_signal, time_to_freq

        NYQ, Wn, B, A, w, h = get_filter_params(delta_time, lowFreq, highFreq, filterType, order)

        for i in xrange(len(w)):
            if h[i] > 1000 and w[i] > 0: #broad spike
                self.assertFalse(w[i] < 0.5*lowFreq)
                self.assertFalse(w[i] > 1.5*highFreq)

        # --------
        #         \
        #          \
        #  LOWPASS  \
        #            \
        # ------------
        # signal drops sharply after lowFreq
        filterType = 'lowpass'
        NYQ, Wn, B, A, w, h = get_filter_params(delta_time, lowFreq, highFreq, filterType, order)

        for i in xrange(len(w)):
            if h[i] > 1000 and w[i] > 0:    #broad spike
                self.assertFalse(w[i] > 1.5*lowFreq)    #not allowed to spike pas lowFreq

        #        --------
        #       /
        #      /
        #     /
        #    /  HIGHPASS
        #   /
        #   -------------
        #signal is low before highFreq
        filterType = 'highpass'

        NYQ, Wn, B, A, w, h = get_filter_params(delta_time, lowFreq, highFreq, filterType, order)