I've tried looking around for information on this, but I'm really out of my league here. I'm a guy who likes to fool around with Python, and I wanted to make a program that would filter an audio file. I'm using Python and NumPy, with the scipy.io.wavfile module for importing and exporting Wave files. I've gotten it messing around with volume, but not filtering. Here's what I have so far.
rate, data = wavfile.read('./TriLeftChannel.wav')
filtereddata = numpy.fft.rfft(data) # FFT Filtered data
freqdata = numpy.fft.fftfreq(data.size) #Frequency data
filtereddata = AudioFunctions.Filter(filtereddata, freqdata, data, rate) # Filter the data
def Filter(filtereddata, freqdata, data, rate):
#fftchunks = (rate / 2)# + 1
x = freqdata[:len(data) / 2]
for f in range(len(x)):
if x[f] > 0.1:
filtereddata[f] = 0.0
filtereddata[len(data) / 2 + f] = 0.0
return filtereddata
In that function, filtereddata is the FFT'd data, freqdata is the frequency data that I got with fftfreq(), and data is the wave file itself, 'bare'. Rate is the sampling rate (though I don't use it). This function doesn't actually filter the frequencies (although I know it's a hard filter and no filter should really be this harsh). After I'm done, I output the file with
filteredwrite = numpy.fft.irfft(filtereddata)
filteredwrite = numpy.round(filteredwrite).astype('int16') # Round off the numbers, and get ready to save it as 16-bit depth file (?)
wavfile.write('TestFiltered.wav', rate, filteredwrite)
Since I'm kind of struggling even just to have gotten this far, I was wondering if anyone could give me any pointers or a kind of beginners' tutorial for FFT? Of course, any help would be greatly appreciated.
EDIT: Fixed indentation issues.