[英]Matlab 3D Plot of transfer function magnitude
How can I plot amplitude of transfer function in three dimension (for instance to check poles and zeros on graph) ? 如何在三个维度上绘制传递函数的幅度(例如,检查图上的极点和零点)? Suppose this is my transfer function:
假设这是我的传递函数:
My code: 我的代码:
b = [6 -10 2];
a = [1 -3 2];
[x, y] = meshgrid(-3:0.1:3);
z = x+y*j;
res = (polyval(b, z))./(polyval(a,z));
surf(x,y, abs(res));
Is it correct? 这是正确的吗? I'd also like to know is it possible to mark unit circle on plot?
我也想知道是否可以在绘图上标记单位圆?
I think it's correct. 我认为是正确的。 However, you're computing H(z^-1), not H(z).
但是,您正在计算的是H(z ^ -1),而不是H(z)。 Is that you want to do?
那是你想做的吗? For H(z), just reverse the entries in
a
from left to right (with fliplr
), and do the same to b
: 对于H(z),只需将
a
的条目从左向右反转(使用fliplr
),然后对b
进行相同操作:
res = (polyval(fliplr(b), z))./(polyval(fliplr(a),z));
To plot the unit circle you can use rectangle
. 要绘制单位圆,可以使用
rectangle
。 Seriously :-) It has a 'Curvature'
property which can be set to generate a circle. 说真的:-)它具有
'Curvature'
属性,可以将其设置为生成圆。
It's best if you use imagesc
instead of surf
to make the circle clearly visible. 最好是使用
imagesc
而不是surf
使圆圈清晰可见。 You will get a view from above, where color represents height (value of abs(H)): 您将从上方看到一个视图,其中颜色表示高度(abs(H)的值):
imagesc(-3:0.1:3,-3:0.1:3, abs(res));
hold on
rectangle('curvature', [1 1], 'position', [-1 -1 2 2], 'edgecolor', 'w');
axis equal
I have never in my whole life heard of a 3D transfer function, it doesn't make sense. 我一生中从未听说过3D传递功能,这没有道理。 I think you are completely wrong:
z
does not represent a complex number, but the fact that your transfer function is a discrete one, rather than a continuous one (see the Z transform for more details). 我认为您是完全错误的:
z
并不代表复数,而是您的传递函数是离散的而不是连续的一个事实(有关更多详细信息,请参见Z变换 )。
The correct way to do this in MATLAB is to use the tf
function, which requires the Control System Toolbox (note that I have assumed your discrete sample time to be 0.1s, adjust as required): 在MATLAB中执行此操作的正确方法是使用
tf
函数,该函数需要使用Control System Toolbox(请注意,我假设您的离散采样时间为0.1s,请根据需要进行调整):
>> b = [6 -10 2];
a = [1 -3 2];
>> sys = tf(b,a,0.1,'variable','z^-1')
sys =
6 - 10 z^-1 + 2 z^-2
--------------------
1 - 3 z^-1 + 2 z^-2
Sample time: 0.1 seconds
Discrete-time transfer function.
To plot the transfer function, use the bode
or bodeplot
function: 要绘制的传递函数,使用
bode
或bodeplot
功能:
bode(sys)
For the poles and zeros, simply use the pole
and zero
functions. 对于极点和零点,只需使用
pole
和zero
功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.