2
$\begingroup$

I'm trying to make a bandstop digital filter. I have used butterworth signal library to make a highpass filter, but using same technique I cannot achieve this bandstop filter. Here's an example:

from scipy import signal

Bx = data.data[0,]
By = data.data[1,]

Bxfft = (Bx[100:-100])
Byfft = (By[100:-100])

Sampling = float(266336) / 300
HalfSampling = float(Sampling) / 2
Wn = float(1) / HalfSampling
b, a = signal.butter(3, Wn, 'high')
BxHPF = signal.filtfilt(b, a, Bxfft)
ByHPF = signal.filtfilt(b, a, Byfft)

So for my bandstop filter I need to cutoff 50 Hz, so I try to take lowcut at 49.9 Hz and Highcut at 50.1 Hz, and the order settled at 3. Do You have any ideas how to achieve that?

$\endgroup$
3
$\begingroup$

I have found the answer, maybe someone will use it.

 def butter_bandstop_filter(data, lowcut, highcut, fs, order):


        nyq = 0.5 * fs
        low = lowcut / nyq
        high = highcut / nyq

        i, u = butter(order, [low, high], btype='bandstop')
        y = lfilter(i, u, data)
        return y
$\endgroup$

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.