-
Notifications
You must be signed in to change notification settings - Fork 0
/
simTauKrep.m
22 lines (20 loc) · 961 Bytes
/
simTauKrep.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function tau = simTauKrep(n, K, T_tx, T_dp, T_fb, T_up, P) % simulated value of mean service time tau on K-rep scheme; T_fa is ignored
% 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 = sum(p <= P); % success flag
succ = (succ >= 1);
while succ == 0 % while there are transmission failure
tau = tau + T_rtt; % add transmission times to tau
p = rand(1, K); % and try again
succ = sum(p <= P);
succ = (succ >= 1);
end
tau = tau + T_rtt; % add the service time of the successfull transmission (the last one)
end
tau = tau/n; % get the mean value
end