-
Notifications
You must be signed in to change notification settings - Fork 4
/
f_CLTFM.m
78 lines (67 loc) · 1.83 KB
/
f_CLTFM.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function [Lo,Li,So,Si,To,Ti,KS,SP] = f_CLTFM(P,K)
% OL and CL frequency responses (ss based)
% Works for MIMO P and K
% Inputs:
% P: Plant in state space form
% K: Control in state space form
% Outputs:
% Lo, Li: Open loop tfs in ss
% So,Si,To,Ti,KS,SP: Closed loop tfs in ss
[Ap, Bp, Cp, Dp] = ssdata(P);
n_e = size(P,1);
n_u = size(P,2);
n_p = size(P,'order');
[Ak, Bk, Ck, Dk] = ssdata(K);
n_k = size(K,'order');
%% Lo = PK
A_Lo = [Ap Bp*Ck; zeros(n_k,n_p) Ak];
B_Lo = [Bp*Dk; Bk];
C_Lo = [Cp Dp*Ck];
D_Lo = Dp*Dk;
Lo = ss(A_Lo,B_Lo,C_Lo,D_Lo);
%% Li = KP
A_Li = [Ak Bk*Cp; zeros(n_p,n_k) Ap];
B_Li = [Bk*Dp; Bp];
C_Li = [Ck Dk*Cp];
D_Li = Dk*Dp;
Li = ss(A_Li,B_Li,C_Li,D_Li);
%% Mo
Mo = inv(eye(n_e)+Dp*Dk);
%% Mi
Mi = inv(eye(n_u)+Dk*Dp);
%% So = inv(I+PK)
A_So = [Ap-Bp*Dk*Mo*Cp Bp*Ck-Bp*Dk*Mo*Dp*Ck; -Bk*Mo*Cp Ak-Bk*Mo*Dp*Ck];
B_So = [Bp*Dk*Mo; Bk*Mo];
C_So = [-Mo*Cp -Mo*Dp*Ck];
D_So = Mo;
So = ss(A_So,B_So,C_So,D_So);
%% Si = inv(I+KP)
A_Si = [Ak-Bk*Dp*Mi*Ck Bk*Dp*Mi*Dk*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