The sampling rate that I have currently is at 384kHz and I want to downsample it down to 44.1kHz. I want to use a bandpass from 5kHz to 200kHz but I am only able to bandpass up to 192kHz for some reason.

The following is my code:

# Importing data 
datapath = "./Data/"
x, fs = sf.read(datapath + 'example_audio.WAV')

# Filtering function

def butter_bandpass(lowcut, highcut, fs, order=5):
    nyq = 0.5 * fs
    low = lowcut / nyq
    high = highcut / nyq
    b, a = butter(order, [low, high], btype='band')
    return b, a

def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
    b, a = butter_bandpass(lowcut, highcut, fs, order=order)
    y = lfilter(b, a, data)
    return y

# Main code

downsampling_rate = 44100
original_rate = 384000
rate_ratio = downsampling_rate/original_rate 

listing = os.listdir(datapath)

for file in listing:
    print("Before: ")
    x, fs = sf.read(datapath + file)

    # TO DO: figure out 191kHz limit situation and conceptual reason why
    x = butter_bandpass_filter(x, 5000, 191000, fs, order=5) 

    x = scipy_signal.resample(x, int(len(x)*rate_ratio))
    print("After: ")

But, the spectrogram and the PSD graph looks exactly the same (before and after) which makes me think that the band pass filter is not working properly.

Any insight would be greatly appreciated!


Your Answer

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

Browse other questions tagged or ask your own question.