Beispiel #1
0
	def filter(self, x, axis=None, reset=False, filtfilt=False):
		"""
		Filter the signal or signal packet <x> along the specified <axis>.
		By default, <axis> is the highest dimension of <x>, so a channels-
		by-samples array is the easiest representation.
		
		Optionally, if <reset> is set to True, then the filter object will
		be reset() before filtering <x>.
		
		Return the filtered signal, of the same dimensions as the input.
		"""###
		if hasattr(x, 'y'): # special support for WavTools.Base.wav objects
			obj, x  =  x.copy(), x.y;
			if axis == None: axis = 0
		else:
			obj = None;
			if axis == None: axis = -1

		if reset or filtfilt: self.reset()
		
		if not isinstance(x, numpy.ndarray): x = numpy.array(x, dtype=numpy.float64, ndmin=1)
		y, self.state = applyfilter(x=x, b=self.b, a=self.a, axis=axis, zi=self.state)
		
		if filtfilt:
			self.reset()
			y, self.state = applyfilter(x=flip(y,axis), b=self.b, a=self.a, axis=axis, zi=self.state)
			y = flip(y,axis)
			
		
		self.samples_filtered += x.shape[axis]
		if obj != None: obj.y = y; y = obj
		return y
Beispiel #2
0
def filt( d, fs, band=(58,62), mode='bandstop', axis=0, order=3, reverse=True, filtfilt=True ):
	"""
	Filter using one or more designed causalfilter objects.
	   reverse=True:  start at the end and work backwards
	   filtfilt=True: work in both directions (backwards first if reverse=True) 
	
	"""###
	if not isinstance( mode, ( tuple, list ) ): mode = [ mode ]
	if not isinstance( band[ 0 ], ( tuple, list ) ): band = [ band ]
	if not isinstance( order, ( tuple, list ) ): order = [ order ]
	if len( mode ) == 1: mode = mode * len( band )
	if len( order ) == 1: order = order * len( band )
	for mode, band, order in zip( mode, band, order ):
		f = causalfilter( band, fs, order=order, type=mode )
		if reverse: d = flip( d, axis )
		d = f.apply( d, axis=axis, filtfilt=filtfilt, reset=True )
		if reverse: d = flip( d, axis )
	return d