Error in applying Butterworth lowpass filter in Scipy - advice for a good Wn parameter

240 Views Asked by At

I am brand new to Digital Signal Processing and I would like to understand how to choose the parameter Wn (or the critical frequency) when aplying Butterworth lowpass filter with scipy.signal. To apply the butterworth lowpassfilter, the following Python/scipy source code can do it.

    from scipy.signal import butter
    from scipy.signal import filtfilt

    def butter_lowpass_filter(data, cutoff, fs, order):
        nyq = 0.5 * fs
        normal_cutoff = cutoff / nyq
        # Get the filter coefficients 
        b, a = butter(order, normal_cutoff, btype='low', analog=False)
        y = filtfilt(b, a, data)
        return y 

I would like to understand what could be a value for the cutoff parameter for my case. Suppose I have a 1kHZ (or 1000HZ) sampling rate in an audio file, and in this audio file I would like to filter out frequencies higher than 600HZ. IF I simply put 600 as cutoff requency (the threshold I want), the normalized cutoff would be 600/500=1.2, and the following error returns to me:

ValueError: Digital filter critical frequencies must be 0 < Wn < 1

So, it seems that the cutoff should never be higher than half of the sampling rate. Other values lower than 500 would work for the cutoff value, but I am not sure which one would be the best for my case. So, is there any rule of thumb to select a cutoff value considering my requirements of filtering values higher than 600Hz? or such a value would depend only on the data? is my 600Hz requirement feasible? is the butterworth filter the right solution for this?

0

There are 0 best solutions below