title: IIR response in Python
body: <p>I have a new question directly related to <a href="https://stackoverflow.com/questions/23368427/python-iir-filter-response">this post</a> - Built within Python I have an 2nd order IIR bandpass filter with given characteristics [the following code is intentionally idiomatic]:</p>
  
  <pre><code>fs = 40e6           # 40 MHz f sample frequency
  fc = 1e6/fs         # 1 MHz center cutoff
  BW = 20e3/fs        # 20 kHz bandwidth 
  fl = (fc - BW/2)/fs # 0.99 MHz f lower cutoff
  fh = (fc + BW/2)/fs # 1.01 MHz f higher cutoff
  </code></pre>
  
  <p>Which gives coefficients:</p>
  
  <pre><code>R  = 1 - (3*BW)
  K  = (1 - 2*R*np.cos(2*np.pi*fc) + (R*R)) / (2 - 2*np.cos(2*np.pi*fc))
  
  a0 = 1 - K                       # a0 =  0.00140
  a1 = 2*(K-R)*np.cos(2*np.pi*fc)  # a1 =  0.00018 
  a2 = (R*R) - K                   # a2 = -0.00158
  
  b1 = 2*R*np.cos(2*np.pi*fc)      # b1 =  1.97241
  b2 = -(R*R)                      # b2 = -0.99700
  </code></pre>
  
  <p>As suggested by <a href="https://stackoverflow.com/questions/23368427/python-iir-filter-response">ukrutt in the previous post</a> I've used scipy.signal.freqz but sadly have not got the response I was looking for - that said I believe the filter is working as intended (code is below). Here is the result of freqz:</p>
  
  <p><img src="https://i.stack.imgur.com/6aszj.png" alt="enter image description here"></p>
  
  <p><strong>My question is: How may I generate a graph more like the intended response?</strong></p>
  
  <p>Code:</p>
  
  <pre><code>a = [0.0014086232031758072, 0.00018050359364826498, -0.001589126796824103]
  b = [1.9724136161684902, -0.9970022500000001]
  
  w,h  = signal.freqz(a, b)
  h_dB = 20 * np.log10(np.abs(h))
  plt.plot(w/np.max(w),h_dB)
  plt.grid()
  </code></pre>