Matlab绘制Z变换的根(零点和极点)

Matlab绘制Z变换的根(零点和极点),matlab,matlab-figure,transfer-function,Matlab,Matlab Figure,Transfer Function,我需要把根画在一个传递函数H(z)上,覆盖一个单位圆,这样就有足够的空间看到所有的点。当H(z)的形式为0=[z0 z1 z2…],极点=[p0 p1 p2]时,我可以从H(z)得到根。使用Matlab的根函数,我能够得到极点和零点的位置。到目前为止,我的Matlab代码是 function zplot(b, a) b_roots = roots(b); a_roots = roots(a); hold on rectangle('Position',[-1 -1 2 2],'Curvatu

我需要把根画在一个传递函数H(z)上,覆盖一个单位圆,这样就有足够的空间看到所有的点。当H(z)的形式为0=[z0 z1 z2…],极点=[p0 p1 p2]时,我可以从H(z)得到根。使用Matlab的根函数,我能够得到极点和零点的位置。到目前为止,我的Matlab代码是

function zplot(b, a)

b_roots = roots(b);
a_roots = roots(a);

hold on
rectangle('Position',[-1 -1 2 2],'Curvature',[1 1]);
plot(b_roots,'x blue');
plot(a_roots,'o blue');
axis %need axis to be equal and +10percent of maximum value
hold off

end
到目前为止,我可以绘制根和单位圆,但我需要帮助调整轴,使它们1)彼此相等,2)比最高值多10%。我不知道该怎么做这个部分。我尝试创建一个变量lim_max=max(b_根,a_根),但它最终变成了一个数组,在axis([-lim_max lim_max-lim_max])函数中无法工作。我需要在输入发生变化时将绘图缩放到+10%


旁注(不需要):有没有办法让它在我绘制时看起来像一个圆,因为现在它大部分时间看起来都像一个椭圆形。我可以重新调整屏幕,这很好,但如果有简单的方法,我也想知道。

设置轴相等并计算最小/最大:

function zplot(b, a)

b_roots = roots(b);
a_roots = roots(a);
xlimits = [min(min([real(a_roots);real(b_roots)])), max(max([real(a_roots);real(b_roots)]))];
ylimits = [min(min([imag(a_roots);imag(b_roots)])), max(max([imag(a_roots);imag(b_roots)]))];

hold on
rectangle('Position',[-1 -1 2 2],'Curvature',[1 1]);
plot(b_roots,'x black');
plot(a_roots,'o blue');
axis equal;
xlim(1.1*xlimits);
ylim(1.1*ylimits);
hold off

end

使用以下代码。这将1)找到x轴和y轴的最大总限制2)将这些限制设置为彼此相等3)绘制这些限制+10%

b_roots = roots(b);
a_roots = roots(a);

x_min = min(min([real(a_roots);real(b_roots)]));
x_max = max(max([real(a_roots);real(b_roots)]));
y_min = min(min([imag(a_roots);imag(b_roots)]));
y_max = max(max([imag(a_roots);imag(b_roots)]));

%get the magnitude of the overall minimum value
min_lim = abs(min(x_min,y_min));
 %abs may not be necessary
max_lim = abs(max(x_max,y_max));

%set high and low limits equal to each other from negative to positive
eq_limit = [-max(min_lim,max_lim),max(min_lim,max_lim)];

hold on
rectangle('Position',[-1 -1 2 2],'Curvature',[1 1]);
plot(b_roots,'x black');
plot(a_roots,'o blue');
axis equal;
xlim(1.1*eq_limit);
ylim(1.1*eq_limit);
hold off

感谢@M.S.的回答和帮助。

这让我走上了正确的方向,但总体来说并不奏效。我想在某个地方限制被搞砸了。多亏了你,我成功了。