title: How to implement band-pass Butterworth filter with Scipy.signal.butter
body: <p>UPDATE:</p>
  
  <p>I found a Scipy Recipe based in this question! So, for anyone interested, go straight to: <a href="http://scipy-cookbook.readthedocs.io/items/ButterworthBandpass.html" rel="noreferrer">Contents » Signal processing » Butterworth Bandpass</a></p>
  
  <hr>
  
  <p>I'm having a hard time to achieve what seemed initially a simple task of implementing a Butterworth band-pass filter for 1-D numpy array (time-series).</p>
  
  <p>The parameters I have to include are the sample_rate, cutoff frequencies IN HERTZ and possibly order (other parameters, like attenuation, natural frequency, etc. are more obscure to me, so any "default" value would do).</p>
  
  <p>What I have now is this, which seems to work as a high-pass filter but I'm no way sure if I'm doing it right:</p>
  
  <pre><code>def butter_highpass(interval, sampling_rate, cutoff, order=5):
      nyq = sampling_rate * 0.5
  
      stopfreq = float(cutoff)
      cornerfreq = 0.4 * stopfreq  # (?)
  
      ws = cornerfreq/nyq
      wp = stopfreq/nyq
  
      # for bandpass:
      # wp = [0.2, 0.5], ws = [0.1, 0.6]
  
      N, wn = scipy.signal.buttord(wp, ws, 3, 16)   # (?)
  
      # for hardcoded order:
      # N = order
  
      b, a = scipy.signal.butter(N, wn, btype='high')   # should 'high' be here for bandpass?
      sf = scipy.signal.lfilter(b, a, interval)
      return sf
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/CtpRF.png" alt="enter image description here"></p>
  
  <p>The docs and examples are confusing and obscure, but I'd like to implement the form presented in the commend marked as "for bandpass". The question marks in the comments show where I just copy-pasted some example without understanding what is happening.</p>
  
  <p>I am no electrical engineering or scientist, just a medical equipment designer needing to perform some rather straightforward bandpass filtering on EMG signals.</p>