Reputation: 5357
I'm fairly new to python and to FFT, so apologies in advance - I'm trying to take a WAV file and re-create it with only certain frequencies (filter out unwanted frequencies)
I'm able to plot everything visually but am struggling to re-create a playable WAV file out of the result. I've minimised my problem - if I take the original signal, I can re-create the WAV file ok. If I run the signal through rfft and then immediately through irfft and try to re-create the WAV file from the result, the file gets created by when I try to play it (Windows 10) I get an error
This item was encoded in a format that's not supported.
Code I'm using (reduced to bare minimum)
fs_rate, signal = wavfile.read(filename)
FFT = scipy.fft.rfft(signal)
recreated_signal = scipy.fft.irfft(FFT)
scipy.io.wavfile.write('recreated file1.wav',fs_rate,signal)
scipy.io.wavfile.write('recreated file2.wav',fs_rate,recreated_signal)
One thing I noticed is that the first file created is 5,619 KB (just under the originating file's size) whilst the second file created is 22,473 KB
What am I missing?
Upvotes: 0
Views: 135
Reputation: 70673
You are probably reading in 16-bit signed integer samples and writing out 64-bit double float samples (the result of the scipy fft function), thus ending up with a file 4X larger.
Check the WAV format sample type of the original file, and compare with the vector length and numeric type of your two scipy signals.
Upvotes: 1