0

I am trying to run a series of data samples through a butterworth filter. The samples were taken at a sample rate of 200 samples/second. I want a band pass of between 20-40 hz. I use fs = 200 because of the sample rate but I get attenuation at all frequencies and see no evidence of the "passband" being a "0db" pass through - I get uniform attentuation of -20db at all frequencies

def butter_bandpass(lowcut, highcut, fs, order =4):
    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 = 4):
    b, a= butter_bandpass(lowcut, highcut, fs, order = order)
    y = lfilter(b,a,data)
    return y

fs = 200.00
lowcut = 20.0
highcut = 40.0

x = Signal_X_Col 
y = butter_bandpass_filter(x, lowcut, highcut, fs, order = 4 )
DyTech
  • 159
  • 1
  • 9
  • *"... I get attenuation at all frequencies ..."* How do you know this? Show how you are evaluating the frequency response of the filter. Also, run just `b, a = butter_bandpass(lowcut, highcut, fs, order)` and show the values of `b` and `a`. – Warren Weckesser Oct 06 '16 at 01:36
  • I ask how you are evaluating the frequency response because the code works fine for me. – Warren Weckesser Oct 06 '16 at 01:44
  • I write the filtered signal to a file and then analyze in Mathcad. When I plot the resulting data in Mathcad I can see the signal is being attenuated across all frequencies. How are you looking at the output data such that it appears to work for you? – DyTech Oct 06 '16 at 01:50
  • 1
    Two methods: (1) Plot the frequency response using the values returned by `scipy.signal.freqz`; (2) Filter a white noise input, and then plot the magnitude of the FFT of the input and output. For an example of (1), see my answer here: http://stackoverflow.com/questions/12093594/how-to-implement-band-pass-butterworth-filter-with-scipy-signal-butter/12233959#12233959 – Warren Weckesser Oct 06 '16 at 02:06

0 Answers0