title: How to plot frequency response of butterworth filter using Matlab
body: <p>I am trying to plot the frequency response of my sequence when filtered by a butterworth, low-pass filter. I have my pole and zero plot figured out just fine but can't seem to get my frequency response plotted correctly. When I do my axis are always way out of scale. I've tried using Matlab's <code>bode</code> function to no avail. A sample input that I have been using would be something like this <code>buttdes(1000, 2500, -3, -20, 20000)</code>. Any help is much appreciated!! Here is my code so far : </p>
  
  <pre><code>function buttdes(fpass, fstop, dp, ds, fs)
  
  %// Design a discrete-time Butterworth filter
  
  %// BUTTDES(fpass, fstop, dp, ds, fs) designs and plots the bode plot
  
  %// of the resulting analog-equivalent filter that has been
  
  %// designed to match the analog parameters fpass (in Hz),
  
  %// fstop (in Hz), dp (in dB) and ds (in dB).
  
  %// fs is the sample rate in Hz
  
  wp = fpass/fs;        
  ws = fstop/fs;
  WpT = 2 * tan(wp / 2);
  WsT = 2 * tan(ws / 2);
  qp = log10(10^-(dp/10)-1);
  qs = log10(10^-(ds/10)-1);
  
  N = ceil((qs-qp) / 2 / log10(WsT / WpT)); 
  WcT = WpT * 10^(-qp/2/N);
  
  k = 0:N-1;
  skT = WcT * exp(j*pi*(2*k+N+1)/2/N);
  
  b = real(prod(skT./(skT -2))) * poly(-ones(1, N));
  a = real(poly(-(skT+2)./(skT-2)));
  
  zplane(b, a);
  </code></pre>