why is the zpk function not producing the transfer function in MATLAB?

Hello guys,
I am trying to use the zpk function, where I input the zeros, poles and gain and it should return the factored form of the transfer function but it is not giving me that output. The code I used is below with the output I am getting from zpk.
a = [2,5,9,5,3];
b = [5,45,2,1,1];
[zer,pol,t] = zplane(a,b);
z = zeros(1,4);
p = zeros(1,4);
%disp('Zeros of the Transfer function are: ');
for i = 1:4
X = ['(',num2str(zer.XData(i)),',',num2str(zer.YData(i)),')'];
z(i) = zer.XData(i) + 1i*zer.YData(i);
%disp(X)
end
%disp('Poles of the transfer function are: ');
for i = 1:(length(b)-1)
X = ['(',num2str(pol.XData(i)),',',num2str(pol.YData(i)),')'];
p(i) = pol.XData(i) + 1i*pol.YData(i);
%disp(X);
end
%disp(z);
G = zpk([z],[p],1);
disp(G);
Output:
zpk with properties:
Z: {[4×1 double]}
P: {[4×1 double]}
K: 1
DisplayFormat: 'roots'
Variable: 's'
IODelay: 0
InputDelay: 0
OutputDelay: 0
Ts: 0
TimeUnit: 'seconds'
InputName: {''}
InputUnit: {''}
InputGroup: [1×1 struct]
OutputName: {''}
OutputUnit: {''}
OutputGroup: [1×1 struct]
Notes: [0×1 string]
UserData: []
Name: ''
SamplingGrid: [1×1 struct]

 採用された回答

Star Strider
Star Strider 2022 年 2 月 11 日
Remove the closing parentheses in the ‘G’ assignment to see the result as a sort of ‘prettyprint’ output:
a = [2,5,9,5,3];
b = [5,45,2,1,1];
[zer,pol,t] = zplane(a,b);
z = zeros(1,4);
p = zeros(1,4);
%disp('Zeros of the Transfer function are: ');
for i = 1:4
X = ['(',num2str(zer.XData(i)),',',num2str(zer.YData(i)),')'];
z(i) = zer.XData(i) + 1i*zer.YData(i);
%disp(X)
end
%disp('Poles of the transfer function are: ');
for i = 1:(length(b)-1)
X = ['(',num2str(pol.XData(i)),',',num2str(pol.YData(i)),')'];
p(i) = pol.XData(i) + 1i*pol.YData(i);
%disp(X);
end
%disp(z);
G = zpk([z],[p],1)
G = (s^2 + 0.5s + 0.5) (s^2 + 2s + 3) ---------------------------------------------- (s+8.958) (s+0.2718) (s^2 - 0.2293s + 0.08216) Continuous-time zero/pole/gain model.
Zv = G.Z{:}
Zv =
-1.0000 + 1.4142i -1.0000 - 1.4142i -0.2500 + 0.6614i -0.2500 - 0.6614i
Pv = G.P{:}
Pv =
-8.9576 + 0.0000i -0.2718 + 0.0000i 0.1147 + 0.2627i 0.1147 - 0.2627i
Kv = G.K
Kv = 1
disp(G)
zpk with properties: Z: {[4×1 double]} P: {[4×1 double]} K: 1 DisplayFormat: 'roots' Variable: 's' IODelay: 0 InputDelay: 0 OutputDelay: 0 Ts: 0 TimeUnit: 'seconds' InputName: {''} InputUnit: {''} InputGroup: [1×1 struct] OutputName: {''} OutputUnit: {''} OutputGroup: [1×1 struct] Notes: [0×1 string] UserData: [] Name: '' SamplingGrid: [1×1 struct]
.

6 件のコメント

Laxman Chinnannavar
Laxman Chinnannavar 2022 年 2 月 11 日
Thanks this works
Star Strider
Star Strider 2022 年 2 月 11 日
As always, my pleasure!
Laxman Chinnannavar
Laxman Chinnannavar 2022 年 2 月 12 日
Hey, One more small doubt bro why doesn't the transfer function shown in proper factorized form. Like there is still (s^2 + 0.5s +0.5) term right? Cant that get factorized into imaginary roots?
Star Strider
Star Strider 2022 年 2 月 12 日
Apparently not, at least in the ‘prettyprint’ display. It only factors real roots, however the ‘P’ and ‘Z’ outputs display the complex roots in complex-conjugate pairs.
See the documentation section on Examples for an illustration of how it displays the various factors.
Laxman Chinnannavar
Laxman Chinnannavar 2022 年 2 月 12 日
I had already checked the examples, just wanted to know if there was any way to get the proper factorized form. Really appreciate the help.
Star Strider
Star Strider 2022 年 2 月 12 日
As always, my pleasure!
It might be possible to add that as a format option for the ‘prettyprint’ output. The best way to approach that is to Contact Support and request that as an enhancement.

サインインしてコメントする。

その他の回答 (1 件)

Paul
Paul 2022 年 2 月 11 日
What output is expected? It looks like zpk() is returning a zpk object with poles and zeros at locations shown on the plot.
a = [2,5,9,5,3];
b = [5,45,2,1,1];
[zer,pol,t] = zplane(a,b);
z = zeros(1,4);
p = zeros(1,4);
%disp('Zeros of the Transfer function are: ');
for i = 1:4
X = ['(',num2str(zer.XData(i)),',',num2str(zer.YData(i)),')'];
z(i) = zer.XData(i) + 1i*zer.YData(i);
%disp(X)
end
%disp('Poles of the transfer function are: ');
for i = 1:(length(b)-1)
X = ['(',num2str(pol.XData(i)),',',num2str(pol.YData(i)),')'];
p(i) = pol.XData(i) + 1i*pol.YData(i);
%disp(X);
end
%disp(z);
G = zpk([z],[p],1);
G
G = (s^2 + 0.5s + 0.5) (s^2 + 2s + 3) ---------------------------------------------- (s+8.958) (s+0.2718) (s^2 - 0.2293s + 0.08216) Continuous-time zero/pole/gain model.
G.Z{:}
ans =
-1.0000 + 1.4142i -1.0000 - 1.4142i -0.2500 + 0.6614i -0.2500 - 0.6614i
G.P{:}
ans =
-8.9576 + 0.0000i -0.2718 + 0.0000i 0.1147 + 0.2627i 0.1147 - 0.2627i
The order of the inputs to zplane are zplane(numerator,denominator). Is a really the numerator and b really the denominator? Only asking because the typical naming convention in Matlab is that b is the numerator and a is the denominator. Will continue assuing a is the num and b is the den, but I suggest rechecking that.
If the goal is just to get the zpk representation with poles and zeros governed by a and b with a gain of k=1, that code seems like a really complicated way to go about it. Could just do
G1 = zpk(roots(a),roots(b),1)
G1 = (s^2 + 0.5s + 0.5) (s^2 + 2s + 3) ---------------------------------------------- (s+8.958) (s+0.2718) (s^2 - 0.2293s + 0.08216) Continuous-time zero/pole/gain model.
However, if the goal is get the zpk representation of the transfer function a(s)/b(s), then there is an error because the gain is not unity
G2 = zpk(tf(a,b))
G2 = 0.4 (s^2 + 0.5s + 0.5) (s^2 + 2s + 3) ---------------------------------------------- (s+8.958) (s+0.2718) (s^2 - 0.2293s + 0.08216) Continuous-time zero/pole/gain model.
Note the gain k = 0.4.
Finally, the code is uzing zplane which suggests these are poles and zeros of a discrete time transfer function. As can be seen, zpk returns a continuous time model unless the sample time argument is provided.
G3 = zpk(tf(a,b,-1))
G3 = 0.4 (z^2 + 0.5z + 0.5) (z^2 + 2z + 3) ---------------------------------------------- (z+8.958) (z+0.2718) (z^2 - 0.2293z + 0.08216) Sample time: unspecified Discrete-time zero/pole/gain model.

1 件のコメント

Laxman Chinnannavar
Laxman Chinnannavar 2022 年 2 月 11 日
Thanks @Paul, for providing all this useful facts.
Actually I dont know the general convention for naming denominators and numerators, so switched those up bymistakely but yeah whatever I did in zpk is correct.
Also yes I wanted the transfer function to be z transform rather than in s domain. That helped a lot

サインインしてコメントする。

製品

リリース

R2021b

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by