Dear Colleagues,
we have a Matlab code example to plot the Event-triggered NCS curves but when we try to re-simulate an example of any research paper ( eg. 10.1016/j.ins.2015.09.049), the obtained curves (state responses and Release instants and intervals) is not the same in these papers.
Please, can anyone check the error in the code or give us another simulation code?
Our Matlab code:
global A B K E x0 n error_k delta tau1 tt tau2 Omega simtime
A=[0 0 1 0
0 0 0 1
-0.3 0.3 -0.004 0.004
0.3 -0.3 0.004 -0.004];
B=[0;0;1;0];
C=[0 1 0 0];
E=[0;0;0;1];
D=0;
F=0;
x0=[-0.1 0.5 -0.3 0.2]';
tau2=0.224;
tau1=0.01;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
delta=0.2;
simtime=20;
h=0.01;
n=size(A,1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%error_k=x0;
xx=x0; % initial values of sampling times
rs_value=0; % store the values of rs for each step
phi_t=-0.1;
rs=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k=1:(simtime+1)/h
taut(k)=tau1+(tau2-tau1)*rand;
end
omegat=0;
for i=1:(simtime)/h
if(i> 20 && i=0% Verify if the event-triggered contidion satisfied or not
rs=k;
rs_value(1,k)=rs;
else
if k>=2
rs_value(1,k)=rs_value(1,k-1);
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t=0:h:simtime;
t1=h:h:simtime;
length(t1)
length(xx)
figure()
for i=1:n
temp_var = strcat( 'xx_',num2str(i) );
temp_var = xx(i,:);
pl=strcat( 'p_',num2str(i) );
pl =plot(t,temp_var,'LineWidth',2);
hold on
end
ylabel('x_i (t)');xlabel('time(sec)');
legend('x_1 (t)','x_2 (t)','x_3 (t)');
grid on;
%--------------------------------------------------------------
delta_rs1=zeros(1,length(rs_value));
delta_rs1(1)=1;
for i=2:1:length(rs_value)
delta_rs1(i)=rs_value(i)-rs_value(i-1);
if delta_rs1(i)>0
delta_rs1(i)= delta_rs1(i);
else
delta_rs1(i)=0;
end
end
figure()
stem(t1,delta_rs1*h,'b')
xlabel('time(s)')
ylabel('Release instants and intervals')
%--------------------------------------------------------------
figure()
delta_rs2(1)=0;
for i=2:1: length(rs_value)
delta_rs2(i)=rs_value(i)-rs_value(i-1);
if delta_rs2(i)>1
delta_rs2(i)= delta_rs2(i)-1;
else
delta_rs2(i)=0;
end
end
stem(t1,delta_rs2, '-ko')
xlabel('time(s)')
ylabel('Number of successive packet dropouts')
max(delta_rs2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CODE2
function dx=Ncs_state_model(t,x,x_tkh,omegat)
global A B E K n error_k
dx=zeros(n,1);
dx=A*x(:)+(B*K)*x_tkh(:)+(B*K)*error_k+E*omegat;