# Remove audio signal component under certain frequency in python

I want to remove all signal components under 10KHz in one audio file. Below is my code

from scipy.signal import butter, filtfilt

def butter_highpass(cutoff, fs, order=5):
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = butter(order, normal_cutoff, btype='high', analog=False)
return b, a

def butter_highpass_filter(data, cutoff, fs, order=5):
b, a = butter_highpass(cutoff, fs, order=order)
y = filtfilt(b, a, data)
return y

y=butter_highpass_filter(rate,10000, fs, order=5)


Below are the two outputs before and after applying the HPF.

Why should the be a mistake?

A linear system (like your filter) can never introduce frequency components that weren't there. So, the tone can't move anywhere. And because you don't show the mapping of colors to power, you can't notice any change in amplitude.

So, I bet your signal is properly attenuated, you just forgot to actually check whether it is.

Also, filfilt is almost certainly not the function you're looking for, read the documentation to that function before using it. You're even importing lfilter!

Furthermore, you label this as "BB (baseband?) signal" in your plot. Further guess: you really don't want a Butterworth filter, but a FIR with a linear phase.

(Using an FIR with a linear phase would most definitely make filtfilt obsolete, as you can just shift the signal by the constant group delay.)

• Thanks for the response. 'BB' stands for blackbird. So how could I remove the signal components shown on the plot above? – tony sasa Sep 3 '20 at 8:26
• please re-read my answer. You removed them. You just don't notice, because your color bar is absent and you don't see how weak they are now. – Marcus Müller Sep 3 '20 at 8:31
• I edited the question with more info of code I am using now. However, I want to totally remove any signal below 10kHz, which the light line on the plot should be gone. – tony sasa Sep 3 '20 at 8:52