Experiment number:-TF To SS
Experiment number:-TF To SS
Que. Enter the Transfer Function and get its state space representation.
ANSWER:= (EDITOR WINDOW)
% program for acquiring STATE SPACE REPRESENTATION FROM TRANSFER FUNCTION
clc;
clear all;
close all;
disp('The length of Num & Den must be equal')
num=input('Enter the num coeff. of TF matrix=');
den=input('Enter the den coeff. of TF matrix=');
TF=tf(num,den)
l1=length(den);
l2=length(num);
%for matrix A
A=zeros(l1-1);
for j=1:l1-1 %this for loop will flip the coeft of 'den'
c(1,j) = den(1,l1-(j-1)) ;
end
c=-c;
A(l1-1,:)=c; % replace the last row of A=the flipped DENOMINATOR
for i=1:l1-2 % this loop will make the elements above diagonal =1
A(i,i+1)=1;
end
A
%---------------------------
% for matrix B
o=size(A);
s=o(1,1);
%z=zeros(s-1,1);
%I=eye(1,1);
B=[zeros(s-1,1);eye(1,1)]
%---------------------------
%for matrix C
C=[];
for k=l1:-1:2
C=[C num(1,k)-den(1,k)*num(1,1)] ;
end
C
%---------------------------
%for matrix D
D=[num(1,1)]
%---------------------------
ANSWER:= (COMMAND WINDOW)
The length of Num & Den must be equal
Enter the num coeff. of TF matrix=[3 4 5 4]
Enter the den coeff. of TF matrix=[1 2 3 4]
Transfer function:
3 s^3 + 4 s^2 + 5 s + 4
-----------------------
S^3 + 2 s^2 + 3 s + 4
A =
0 1 0
0 0 1
-4 -3 -2
B =
0
0
1
C =
-8 -4 -2
D =
3