-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunTwoSeriesLinkSim.m
37 lines (28 loc) · 1.55 KB
/
runTwoSeriesLinkSim.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
%% Function runTwoSeriesLinkSim()
% Parameters
% K - the number of packets in the application message
% p - the probability of failure
% N - the number of simulations to run
%
% Returns: the average numeric result across the total simulations
function result = runTwoSeriesLinkSim(K,p,N)
simResults = ones(1,N); % a place to store the result of each simulation
for i=1:N
txAttemptCount = 0; % transmission count
pktSuccessCount = 0; % number of packets that have made it across
while pktSuccessCount < K
r1 = rand; % generate random number to determine if packet is successful (r1 > p) 1 denotes link 1
r2 = rand; % generate random number to determine if packet is successful (r2 > p) 2 denotes link 2
txAttemptCount = txAttemptCount + 1; % count 1st attempt
% while packet transmissions is not successful (r1 or r2 < p)
while r1 < p || r2 < p
r1 = rand; % transmit again, generate new success check value r1
r2 = rand; % transmit again, generate new success check value r2
txAttemptCount = txAttemptCount + 1; % count additional attempt
end
pktSuccessCount = pktSuccessCount + 1; % increase success count after success (r1 and r2 > p)
end
simResults(i) = txAttemptCount; % record total number of attempted transmissions before entire application message (K successful packets) transmitted
end
result = mean(simResults);
end