-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpart2.asv
More file actions
135 lines (89 loc) · 2.73 KB
/
Copy pathpart2.asv
File metadata and controls
135 lines (89 loc) · 2.73 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
data = load('data_position.mat');
data = data.data;
Gfs = cell(1, 4);
Gs = cell(1, 4);
Ts = 0.02;
for i = 1:1:4
experiment_name = data { i }. name ;
y = data { i }. y ;
u = data { i }. u ;
Z = detrend ( iddata (y , u , Ts , "Period" , 8191) ) ;
freqs = ( pi /4096: pi /4096: pi ) / Ts ;
Gf = spa ( Z , 8191 , freqs );
Gfs{i} = Gf;
y_derivative = lsim (1 - tf ('z', Ts ) ^ -1 , y ) ;
Z = detrend ( iddata ( y_derivative , u , Ts , "Period" , 8191) ) ;
z = tf ('z', Ts ) ;
G_derivative = oe (Z , [10 , 10 , 1]) ;
G = G_derivative / (1 - z ^ -1) ;
Gs{i} = G;
end
%for i=1:1:4
% figure;
% bode(Gfs{i});
% experiment_name = sprintf('Experiment %d', i);
% title(experiment_name);
%end
errors_Gfs = zeros(length(Gfs));
error_mean = zeros(1, length(Gfs));
Gfs_mean = (Gfs{1} + Gfs{2} + Gfs{3} + Gfs{4})/4;
for i=1:1:length(Gfs)
for j=1:1:length(Gfs)
result = norm(Gfs{j}/Gfs{i} - 1, Inf);
errors_Gfs(i, j) = result;
end
result_mean = norm(Gfs{i}/Gfs_mean - 1, Inf);
error_mean(i) = result_mean;
end
max_Gfs = zeros(1, length(Gfs));
for i=1:1:length(Gfs)
[max_i, idx_i] = max(errors_Gfs(i, :));
max_Gfs(i) = max_i;
end
[max_mean, idx_mean] = max(error_mean);
[min_max_Gfs, idx_min_max_Gfs] = min(max_Gfs);
if min_max_Gfs < max_mean
idx_nom = idx_min_max_Gfs;
Gnom = Gfs{idx_nom};
else
Gnom = Gfs_mean;
end
order = 7; % ordre souhaité
Gnom_ss = fitfrd(Gnom, order); % produit un objet ss
Gmm = stack(1, Gfs{1}, Gfs{2}, Gfs{3}, Gfs{4});
[Gu, info] = ucover(Gmm, Gnom_ss, 7, 'InputMult');
W2 = info.W1;
W2opt = info.W1opt;
% info.W1 (forced to respect the degree N)
% info.W1opt -> gives the best W2 (in terms of precision) but can be too complex
figure;
h = bodeplot(W2, Gfs{1}/Gnom_ - 1, Gfs{2}/Gnom - 1, Gfs{3}/Gnom - 1, Gfs{4}/Gnom - 1);
setoptions(h, 'PhaseVisible', 'off');
figure;
W1s = makeweight(10000, 10, 0.51);
W1s_inverse = W1s^-1;
Ts = 0.02; % période d’échantillonnage
W1z = c2d(W1s, Ts, 'tustin'); % méthode bilinéaire (Tustin)
% Maintenant on veut desing un H inf controller de sorte à minimiser la
% norme infinie à la fois de W1 S afin d'avoir une performance robuste et
% de W2 T afin d'avoir une stabilité robuste
Gnom_ss = ss(Gnom_ss);
W1_ss = ss(W1z);
W2_ss = ss(W2);
K=mixsyn(Gnom_ss,W1_ss,[],W2_ss); % On ne fait rien pour le fonction de transfert U
% On calcule tout partir du Gnominal
S = feedback(1, G*K);
T = feedback(G*K,1);
U = feedback(K,G);
figure;
bodemag(S, 'b', inv(W1_ss), 'k--');
legend('S', 'W1^{-1}');
figure;
bodemag(U, 'r');
legend('U');
figure;
bodemag(T, 'g', inv(W2_ss), 'k--');
legend('T', 'W2^{-1}');
t = 0:Ts:5;
figure;
step(T, t);