Ejemplo n.º 1
0
	def apply(self, signalToFilter, showFilterResult = False):
		taps = len(self.coefficients)
		newAmplitude = [0 for i in range(len(signalToFilter.amplitude))]
		for i in range(len(signalToFilter.amplitude)):
			if i >= taps:
				for j in range(taps):
					newAmplitude[i] = newAmplitude[i] + (signalToFilter.amplitude[i - j] * self.coefficients[taps - j - 1])
			else:
				for j in range(taps - (taps - i)):
					newAmplitude[i] = newAmplitude[i] + (signalToFilter.amplitude[i - j] * self.coefficients[taps - j - 1])
		if showFilterResult:
			self.showResult(newAmplitude, 'Result of Finite Impulse Response', signalToFilter.amplitude)
		newSignal = Signal()
		newSignal.name = signalToFilter.name
		newSignal.time = dc(signalToFilter.time)
		newSignal.amplitude = dc(newAmplitude)
		newSignal.samplingFrequency = dc(signalToFilter.samplingFrequency)
		return newSignal
Ejemplo n.º 2
0
	def apply(self, signalToFilter, showFilterResult = False):
		newAmplitude = [0 for i in range(len(signalToFilter.amplitude))]
		for i in range(len(signalToFilter.amplitude)):
			subList = []
			if i >= self.taps:
				for j in range(self.taps):
					subList.append(signalToFilter.amplitude[i - j])
			else:
				for j in range(self.taps - (self.taps - i)):
					subList.append(signalToFilter.amplitude[i - j])
			subList.sort()
			if(len(subList) < self.taps):
				if(len(subList) != 0):
					newAmplitude[i] = newAmplitude[i] + subList[0]
			else:
				newAmplitude[i] = newAmplitude[i] + (subList[int(self.taps/2)])
		if showFilterResult:
			self.showResult(newAmplitude, 'Result of Median Filter', signalToFilter.amplitude)
		newSignal = Signal()
		newSignal.name = signalToFilter.name
		newSignal.time = dc(signalToFilter.time)
		newSignal.amplitude = dc(newAmplitude)
		newSignal.samplingFrequency = dc(signalToFilter.samplingFrequency)
		return newSignal