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



我需要将根绘制到覆盖一个单位圆的传递函数H(z)上,给足够的空间来查看所有点。当H(z)以零=[z0 z1 z2…],极点=[p0 p1 p2]的形式给出时,我能够从中得到根。使用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_roots,a_rots),但它最终是一个数组,在轴([-lim_max-lim_max-lim_max-lim.max])函数中不起作用。随着输入的变化,我需要将绘图缩放到+10%。

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

设置axis equal并计算最小值/最大值:

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.的回答和帮助。

最新更新