%invlaplace.m
%Transfer function creation
%Calculation of residues for Partial Fraction Expansion
%Interconnection of systems
%Extraction of system data
%Introduction to:
%commands for polynomials
%- conv
%- poly
%- roots
%commands for system creation
%- tf
%commands for residue calculation
%- residue
%commands for system connections
%- feedback
%- parallel
%- series
%commands for system data extraction
%- tfdata
%- zpkdata


clc

%CASE1:
%T(s)=s+1/(s^3+5s^2+4s+1)
fprintf('\nCASE1: T(s)=s+1/(s^3+5s^2+4s+1)\n')
num1=[1 1]
den1=[1 5 4 1]
z1=roots(num1)
p1=roots(den1)
sys1=tf(num1,den1)

fprintf('\nPress a key to continue ... \n')
pause

%CASE2:
%T(s)=(s+1)*(s^2+s)/((s^3+5s^2+4s+1)*(s+1))
fprintf('\nCASE2: T(s)=(s+1)*(s^2+s)/((s^3+5s^2+4s+1)*(s+1))\n')
num2=conv([1 1],[1 1 0])
den2=conv([1 5 4 1],[1 1])
z2=roots(num2)
p2=roots(den2)
sys2=tf(num2,den2)

fprintf('\nPress a key to continue ... \n')
pause

%CASE3:
%T(s)=(s+1)*(s+3)/((s+4)*(s+2))
fprintf('\nCASE3: T(s)=(s+1)*(s+3)/((s+4)*(s+2))\n')
z3=[-1 -3]
p3=[-4 -2]
num3=poly(z3)
den3=poly(p3)
sys3=tf(num3,den3)

fprintf('\nPress a key to continue ... \n')
pause

%Calculation of Residues
%sys1
[R1,P1,K1]=residue(num1,den1)
%sys2
[R2,P2,K2]=residue(num2,den2)
%sys3
[R3,P3,K3]=residue(num3,den3)

fprintf('\nPress a key to continue ... \n')
pause

%Feeback connection
sys_feedback=feedback(sys1,sys2)

%Series connection
sys_series=series(sys1,sys2)

%Parallel connection
sys_parallel=parallel(sys1,sys2)

fprintf('\nPress a key to continue ... \n')
pause

[num_feedback,den_feedback]=tfdata(sys_feedback,'v')
[R_feedback,P_feedback,K_feedback]=residue(num_feedback,den_feedback)
[Z_feedback,P_feedback,K_feedback]=zpkdata(sys_feedback,'v')


