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

14 Ansichten (letzte 30 Tage)
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]

Akzeptierte Antwort

Star Strider
Star Strider am 11 Feb. 2022
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 Kommentare
Laxman Chinnannavar
Laxman Chinnannavar am 12 Feb. 2022
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 am 12 Feb. 2022
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Paul
Paul am 11 Feb. 2022
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 Kommentar
Laxman Chinnannavar
Laxman Chinnannavar am 11 Feb. 2022
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by