## -*- texinfo -*-
## @deftypefn {Function File} dsp_draw_zplane (@var{ax}, @var{zeros_z}, @var{poles_z}, @var{title_str})
## Draw the unit circle, guide lines, zeros, and poles on the given axes
## handle.  Used by both the integrated P/Z editor and the standalone
## @code{pz_tool}.
## @end deftypefn

function dsp_draw_zplane(ax, zeros_z, poles_z, title_str)
    axes(ax);
    cla;
    hold on;

    theta = linspace(0, 2*pi, 512);
    plot(cos(theta), sin(theta), ...
         "Color",     [0.15, 0.45, 0.88], ...
         "LineWidth", 2.2, ...
         "DisplayName", "Unit Circle");

    plot([-1.5, 1.5], [0, 0], "-", ...
         "Color", [0.55, 0.55, 0.55], "LineWidth", 0.8, ...
         "HandleVisibility", "off");
    plot([0, 0], [-1.5, 1.5], "-", ...
         "Color", [0.55, 0.55, 0.55], "LineWidth", 0.8, ...
         "HandleVisibility", "off");

    if ~isempty(zeros_z)
        plot(real(zeros_z), imag(zeros_z), "o", ...
             "MarkerSize",      11, ...
             "LineWidth",       2.2, ...
             "Color",           [0.05, 0.60, 0.12], ...
             "MarkerFaceColor", "none", ...
             "DisplayName",     sprintf("Zeros  (%d)", numel(zeros_z)));
    end

    if ~isempty(poles_z)
        plot(real(poles_z), imag(poles_z), "x", ...
             "MarkerSize",  13, ...
             "LineWidth",   2.6, ...
             "Color",       [0.85, 0.10, 0.10], ...
             "DisplayName", sprintf("Poles  (%d)", numel(poles_z)));
    end

    hold off;
    axis equal;
    xlim([-1.5, 1.5]);
    ylim([-1.5, 1.5]);
    grid on;
    title(title_str, "FontSize", 11);
    xlabel("Real");
    ylabel("Imaginary");
    legend("location", "northeast");
end
