function show_z(B,A);
%function show_z(B,A);
%
% SHOW_Z  --  a function that displays a surface plot of the Z-plane
%             for a given filter defined by B and A
%
%  Of course, the z-plane "blows up" in many locations, so this function
%  "cuts off" the surface at 2+ the maximum point on the unit circle.


num_pts = 46;
upplus = 2;

[B,A] = eqtflength(B,A);

[z,p,k] = tf2zp(B,A);

mn = min([-1.2; real([z; p]); imag([z;p])]);
mx = max([1.2; real([z; p]); imag([z;p])]);

[x,y] = meshgrid(linspace(mn,mx,num_pts),linspace(mn,mx,num_pts));

z = x+i*y;

zi = 1./z;

ce = exp(j*2*pi*(0:.001:1));
cevals = abs(polyval(B(end:-1:1),ce)./polyval(A(end:-1:1),ce));

vals = polyval(B(end:-1:1),zi)./polyval(A(end:-1:1),zi);
vals(abs(vals) > max(cevals)+upplus) = NaN;

mesh(x,y,abs(vals));

axis tight;

h = line(real(ce),imag(ce),cevals);
set(h,'Color',[1 0 0]);
set(h,'LineWidth',2);

xlabel('Real(z)');
ylabel('Imag(z)');
zlabel('|H(z)|');
