Apply high pass filter in audio signals

288 views Asked by At

I want to achieve a high pass filter in my audio files to filter out any signals below 6kHz. Below is the code:

def butter_highpass(cutoff, fs, order=5):
    nyq = 0.5 * fs
    normal_cutoff = cutoff / nyq
    b, a = signal.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 = signal.filtfilt(b, a, data)
    return y


(fs,rate)=wav.read('2020_09_02-21_21_16_51.wav')
y=butter_highpass_filter(rate,6000, fs, order=5)
plt.figure(3)
frequencies, times, spectrogram = 
signal.spectrogram(rate,fs)
plt.pcolormesh(times, frequencies, spectrogram)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.show()

However, the result output is incorrect that the signal components should be removed under 6kHz, instead, they still active and changed to start from kHz

0

There are 0 answers