Exemplo n.º 1
0
 def filter(self, soundfile):
     #2 - aplico transformada de fourier
     trans = fft.rfft(soundfile.getdata())
     trans_real = abs(trans)
     #2b - lo grafico
     plotter.saveplot("transformed", trans_real)
     #3 - busco la frecuencia
     band = 2000
     # ignore the first 200Hz
     hzignored = 200
     frec = hzignored + argmax(trans_real[hzignored:])
     #print max(trans_real)
     #print trans_real[frec]
     #print frec
     min = (frec - band / 2) if (frec > band / 2) else 0
     filter_array = append(zeros(min), ones(band))
     filter_array = append(filter_array,
                           zeros(len(trans_real) - len(filter_array)))
     filtered_array = multiply(trans, filter_array)
     plotter.saveplot("filtered_trans", abs(filtered_array))
     #4 - antitransformo
     filtered_signal = array(
         fft.irfft(filtered_array)[:soundfile.getlength()], dtype="int16")
     plotter.saveplot("filtered_signal", filtered_signal)
     soundfile.setdata(filtered_signal)
Exemplo n.º 2
0
    def filter(self, soundfile):
        trans = fft.rfft(soundfile.getdata())  # Transposing data?
        self.trans_real = abs(trans)

        band = 2000  # Over a 2KHz band

        # Ignore the first 200Hz
        hzignored = 200
        frec = hzignored + argmax(self.trans_real[hzignored:])  # Calculate the frequency
        min = int((frec - band / 2)) if (frec > band / 2) else 0

        print(f"Band: {band} Hz")
        print(f"Frequency: {frec} Hz")
        print(f"Min: {min} Hz")

        filter_array = append(zeros(min), ones(band))
        filter_array = append(filter_array, zeros(len(self.trans_real) - len(filter_array)))

        self.filtered_array = multiply(trans, filter_array)
        self.filtered_signal = array(fft.irfft(self.filtered_array)[:soundfile.getlength()], dtype="int16")
        soundfile.setdata(self.filtered_signal)
Exemplo n.º 3
0
	def filter(self, soundfile):
		#2 - aplico transformada de fourier
		trans = fft.rfft(soundfile.getdata())
		trans_real = abs(trans)
		#2b - lo grafico
		plotter.saveplot("transformed",trans_real)
		#3 - busco la frecuencia
		band = 2000
		# ignore the first 200Hz
		hzignored = 200
		frec = hzignored + argmax(trans_real[hzignored:])
		#print max(trans_real)
		#print trans_real[frec]
		#print frec
		min = (frec - band / 2) if (frec > band / 2) else 0
		filter_array = append(zeros(min), ones(band))
		filter_array = append(filter_array, zeros(len(trans_real) - len(filter_array)))
		filtered_array = multiply(trans, filter_array)
		plotter.saveplot("filtered_trans",abs(filtered_array))
		#4 - antitransformo
		filtered_signal = array(fft.irfft(filtered_array)[:soundfile.getlength()], dtype="int16")
		plotter.saveplot("filtered_signal",filtered_signal)
		soundfile.setdata(filtered_signal)