简体   繁体   中英

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). 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 :

res = (polyval(fliplr(b), z))./(polyval(fliplr(a),z));

To plot the unit circle you can use rectangle . Seriously :-) It has a 'Curvature' property which can be set to generate a circle.

It's best if you use imagesc instead of surf to make the circle clearly visible. You will get a view from above, where color represents height (value of 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. 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).

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):

>> 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(sys)

For the poles and zeros, simply use the pole and zero functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM