Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % I use this code to obtain the time of detecting the attacks against z3,
- % using the nonparametric cusum algorithm
- clear;
- clc;
- max_iter = 1000;
- taoval = 1:3:400; %taoval means \tau, which is the threshold
- iter1 = [];iter2 = [];iter3 = [];
- for itao = 1:length(taoval)
- tao = taoval(itao);
- Si1 = 0;Si_1 = 0;
- for i = 1:max_iter-1
- Si1 = Si_1+0.01*abs(randn(1));
- if(i>100)
- Si1 = Si1+0.5*94.20; %94.20 is the \gamma?percentiles of z3, which is derived from historical data. 0.5 means the true value is changed by 50%
- end
- if(Si1>tao)
- iter_tmp1 = i;
- break;
- end
- Si_1 = Si1;
- end
- iter1 = [iter1,iter_tmp1-100];
- Si2=0; Si_1 = 0;
- for i = 1:max_iter-1
- Si2 = Si_1+0.01*abs(randn(1));
- if(i>100)
- Si2 = Si2+0.3*94.20; %0.3 means the true value is changed by 30%
- end
- if(Si2>tao)
- iter_tmp2 = i;
- break;
- end
- Si_1 = Si2;
- end
- iter2 = [iter2,iter_tmp2-100];
- Si3=0; Si_1 = 0;
- for i = 1:max_iter-1
- Si3 = Si_1+0.01*abs(randn(1));
- if(i>100)
- Si3 = Si3+0.1*94.20; %0.1 means the true value is changed by 10%
- end
- if(Si3>tao)
- iter_tmp3 = i;
- break;
- end
- Si_1 = Si3;
- end
- iter3 = [iter3,iter_tmp3-100];
- end
- figure(1);clf;
- plot(taoval,iter1,'r--','linewidth',2);hold on;
- plot(taoval,iter2,'g-.','linewidth',2);hold on;
- plot(taoval,iter3,'b-','linewidth',2);hold off;
- xlabel('\tau');ylabel('Average Detection Time(s)');
- LEGEND('z_{a}=0.5*z','z_{a}=0.7*z','z_{a}=0.9*z','Location','northwest');
- title('z_{3}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement