function zplane_jf(arg1, arg2, axis_size)
%
%function zplane_jf(zeros, poles, axis_size)
% my zplane figure given zeros and poles as column vectors
%
%function zplane_jf(bk, ak, axis_size)
% my zplane figure given bk and ak coefficients as row vectors
%
% if first two args are both scalars, assume 1 pole and 1 zero.
%
% axis_size defaults to 1.3, so make it bigger if zeros are far from unit circle
%
% caution: this does not know about pole-zero cancellations!
%
% Jeff Fessler

if nargin < 2, help(mfilename), error(mfilename), end
if nargin < 3, axis_size = 1.3; end

if size(arg1, 2) > 1 | size(arg2, 2) > 2
	[b,a] = eqtflength(arg1, arg2);
	[zz,pp] = tf2zp(b,a);
else
	zz = arg1;
	pp = arg2;
end

t = linspace(0, 2*pi, 100);
plot(	real(zz), imag(zz), 'yo', real(pp), imag(pp), 'cx', ...
	cos(t), sin(t), 'g--', ...
	[-1 1]*axis_size, [0 0], 'b-', ...
	[0 0], [-1 1]*axis_size, 'b-')
axis([-1 1 -1 1]*axis_size)
axis square
xtick([-1 0 1])
ytick([-1 0 1])
xlabel 'Re(z)'
ylabel 'Im(z)'

% repeated poles or zeros
for set = 1:2
	if set==1
		root = pp;
		offset = 0.1;
		align = 'bottom';
	else
		root = zz;
		offset = -0.1;
		align = 'top';
	end
	used = zeros(length(root),1);
	for ii=1:length(root)
		used(ii) = 1;
		repeat = abs(root(ii) - root) < 100*eps;
		if any(repeat & ~used)
			jj = find(repeat);
			used(jj) = 1;
			xp = real(root(ii)) + abs(offset) * axis_size;
			yp = imag(root(ii)) + offset * axis_size;
			text(xp, yp, sprintf('%d', length(jj)), 'vert', align)
		end
	end
end
