4

I need to filter frequencies above 5Khz in a wav file. I made some research and found about butterworth algorithm but couldn't apply it.

Assume that I have a mono channel wav file. I read it, then I want to use a low pass filter to filter frequencies above 5Khz.

What I've done so far is this. I read the file, read frames and convert them to numerical values.

from pydub import AudioSegment

song = AudioSegment.from_wav("audio.wav")
frame_count = int(song.frame_count())
all_frames = [song.get_frame(i) for i in range(frame_count)]

def sample_to_int(sample):
    return int(sample.encode("hex"), 16)

int_freqs = [sample_to_int(frame) for frame in all_frames]

If I make change values >5000 to 0 is it enough? I don't think that's the way, I am very confused and would be glad to hear any help.

nope
  • 751
  • 2
  • 12
  • 29
  • Although if you want to implement it yourself, you can apply some sort of curve to an FFT and then do an inverse FFT. But that's a pretty naive way of doing it. – Linuxios May 10 '16 at 17:21
  • Filtering down to 5kHz is quite normal. Older adults can hear to about 12 kHz, young adults (not today probably) to 18kHz, telephone conversations (POTS) have limits around 3-4 kHz. Look up this example I wrote for someone else for bandpass filtering with FFT if you want to learn more, but for practical purposes I'd go with Linuxious' answer. http://stackoverflow.com/questions/36968418/python-designing-a-time-series-filter-after-fourier-analysis/36975979#36975979 – roadrunner66 May 10 '16 at 22:27
  • @roadrunner66: Normal, yes. Still, unless you're using it for effect, it doesn't sound that good :). – Linuxios May 11 '16 at 03:45

1 Answers1

6

Pydub includes a lopass filter -- there's no need for you to implement it yourself:

from pydub import AudioSegment

song = AudioSegment.from_wav("audio.wav")
new = song.low_pass_filter(5000)

It's "documented" in effects.py.

Linuxios
  • 34,849
  • 13
  • 91
  • 116