forked from apresiokefin/event-triggering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
et_sigma_SE.m
81 lines (75 loc) · 1.91 KB
/
et_sigma_SE.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
79
80
81
sigma_array=linspace(0,1,100);
[p,q]=size(sigma_array);
for iter = 1:q
t=0.0;
t_final=30;
x=[0 0 0]';
y=0.0;yb=0.0;ys=0.0;ysb=0.0;
delta_t=0.01;n=round(t_final/delta_t);
C=[0 0 1];
theta=0.0; %time delay
h_u=zeros(1,1000);
n_theta=round(theta/delta_t);
kc=1.5;ti=3.0;td=0.5;s=0.0;
sigma=sigma_array(iter);
dist=0;
for i=1:n
t_array(i)=t; y_array(i)=y; ys_array(i)=ys;x_array(:,i)=x;
if (t>1) ys=1.0; else ys=0.0;end
%if (t>10)&&(t<15) dist=1; else dist=0;end %disturbance
s=s+(kc/ti)*(ys-y)*delta_t;
if (i>1)
x_error=x_array(:,i)-x_array(:,i-1);
if (abs(norm(x_error))>(sigma*(norm(x_array(:,i-1)))))||norm(x_array(:,i-1))==0
u=dist+kc*(ys-y)+s+kc*td*((ys-y)-(ysb-yb))/delta_t;
u_array(i)=u;
event_array(i)=1;
else
u=u_array(i-1); u_array(i)=u; event_array(i)=0; end
else
u=dist+kc*(ys-y)+s+kc*td*((ys-y)-(ysb-yb))/delta_t;
u_array(i)=u;
event_array(i)=1; end;
ysb=ys; yb=y;
for j=1:999
h_u(j)=h_u(j+1);
end
h_u(1000)=u;
dx_dt=g_system(y,x,h_u(1000-n_theta));
x=x+dx_dt*delta_t;
y=C*x;
t=t+delta_t;
end
%{
figure(1);
subplot(3,1,1)
plot(t_array,ys_array,t_array,y_array);
xlabel('time(s)');ylabel('Output Value');
legend('y_{setpoint}','y')
grid on
subplot(3,1,2)
plot(t_array,u_array);
xlabel('time(s)');ylabel('Input Value');
legend('u')
grid on
subplot(3,1,3)
area(t_array,event_array);
title('Event-triggered')
xlabel('time(s)');
%}
%{
figure(2)
plot(t_array,x_array)
legend('x1','x2','x3')
grid on
%}
[m,n]=size(t_array);
R=sum(event_array)/n;
R_array(iter)=R;
end
figure(1)
set(gca,'FontSize',10);
plot(sigma_array,R_array,'LineWidth',2,'Color','b');
grid on
xlabel('Sigma'); ylabel('R'); title('Event Ratio (R) vs Error Criterion (Sigma)');
print('sigma_vs_R_SE','-dpng');