First, write out the system’s zero vector, pole vector, and system gain, then call zp2tf() to obtain the system’s transfer function model, and call zp2ss() to obtain the system’s state-space model.
% Convert zero-pole model to transfer function model %
zp2ss();
zp2tf()%
X’ = A*X + B*U;%
Y = C*X + D*U%%%%%%%%%%%
clear all;clc;close all;%%%%%%%%%%%%%%
example 1%%
gainK = 2.7;%%
zeroZ = [-3.6 -4.8]’;%%
poleP = [-0.8 -1.6 -2.9 -3.5]’;
[num1, den1] = zp2tf(Z, P, K);
disp(‘Transfer function:’);
printsys(num1, den1, ‘s’);
[A, B, C, D] = zp2ss(Z, P, K);
disp(‘State-space model:’);
disp(‘A=’);
disp(A);
disp(‘B=’);
disp(B);
disp(‘C=’);
disp(C);
disp(‘D=’);
disp(D);
%%%%%%%%%%%%%%%
sys1 = tf(num1, den1);
t1 = 0:0.01:10;
x1 = 5*sin(2*pi*6*t1 + pi/2);
[y2, t2] = lsim(sys1, x1, t1);
figure(1);
plot(t2, y2(:,1), ‘r’);
xlabel(‘t(s)’);
ylabel(‘y’);
%%%%%%%%%%%%%%%
disp(‘End.’)