-
Notifications
You must be signed in to change notification settings - Fork 0
/
simTauKpro.m
35 lines (32 loc) · 1.52 KB
/
simTauKpro.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
function tau = simTauKpro(n, K, T_tx, T_dp, T_fb, T_up, P) % simulated value of tau under K-pro scheme
% n is the number of packets transmitted
% P is the success probability threshold; a packet with proba p<=P is
% transmitted succesfully
T_rtt = K*T_tx + T_dp + T_up + T_fb;
tau = 0;
for i=1:n
p = rand(1, K); % picks a random K-vector probability
succ = (p <= P); % success flag
succ = find(succ, 1); % get the index of the first non-null element (the first successfull transmitted replica)
% succ will contain a 1*0 array if the above operation doesn't find any index.
% so the following step is just an insurance :)
if succ >= 1
l = succ;
else
l = 0;
end
while l == 0 % while there are transmission failure
tau = tau + T_rtt; % add transmission times to tau
p = rand(1, K); % picks a random K-vector probability
succ = (p <= P); % success flag
succ = find(succ, 1); % get the index of the first non-null element (the first successfull transmitted replica)
if succ >= 1
l = succ;
else
l = 0;
end
end
tau = tau + l*T_tx + T_dp + T_up + T_fb; % add the time of the successfull transmission (the last one)
end
tau = tau/n; % get the mean value
end