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)

enter image description here Below are the two outputs before and after applying the HPF.

enter image description here


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.)

  • $\begingroup$ Thanks for the response. 'BB' stands for blackbird. So how could I remove the signal components shown on the plot above? $\endgroup$ – tony sasa Sep 3 '20 at 8:26
  • $\begingroup$ 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. $\endgroup$ – Marcus Müller Sep 3 '20 at 8:31
  • $\begingroup$ 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. $\endgroup$ – tony sasa Sep 3 '20 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.