Python Forum

Full Version: Frequency Filter for wav file plotting in python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm currently learning to plot in python. Here is a working frequency plotter for a wav file. Now i want to make a filter, which cuts out the frequencies below 300Hz and above 3400Hz, so kinda like a bandpass? Can anyone tell me the easiest way of doing that? I read something about a built in high and lowpassfilter like. Thanks for every answer

"wav_filename.low_pass_filter(3400)", but thats not working.
%matplotlib inline

from scipy.io import wavfile
from scipy.fftpack import fft, fftfreq
import matplotlib.pyplot as plt
from pydub import AudioSegment

wav_filename = "speech_clean (1).wav"

samplerate, data = wavfile.read(wav_filename)

total_samples = len(data)

limit = int((total_samples /2)-1)

fft_abs = abs(fft(data))

freqs = fftfreq(total_samples,1/samplerate)

fftfreq?

# plot the frequencies
plt.plot(freqs[:limit], fft_abs[:limit])
plt.title("Frequency spectrum of %s" % wav_filename)
plt.xlabel('frequency in Hz')
plt.ylabel('amplitude')
plt.show()