【问题标题】:Matlab Plotting roots (zeros and poles) of Z-TransformMatlab 绘制 Z 变换的根(零点和极点)
【发布时间】:2015-04-17 21:34:22
【问题描述】:

我需要将根绘制到覆盖单位圆的传递函数 H(z) 上,以提供足够的空间来查看所有点。当 H(z) 以 zeros = [z0 z1 z2...]、poles = [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_roots,a_roots) 但它最终成为一个数组,并且不能在 axis([-lim_max lim_max -lim_max lim_max]) 函数中工作。我需要随着输入的变化将绘图缩放到 +10%。

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

【问题讨论】:

    标签: matlab matlab-figure transfer-function


    【解决方案1】:

    设置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
    

    【讨论】:

    • 这使我朝着正确的方向前进,但总体上没有奏效。我认为限制在某个地方搞砸了。多亏了你,我让它工作了。
    【解决方案2】:

    使用以下代码。这将 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.感谢他们的回答和帮助。

    【讨论】:

      猜你喜欢
      • 2017-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多