why is the zpk function not producing the transfer function in MATLAB?
Show older comments
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]
Accepted Answer
More Answers (1)
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.Z{:}
G.P{:}
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)
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))
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))
1 Comment
Laxman Chinnannavar
on 11 Feb 2022
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
