-
Notifications
You must be signed in to change notification settings - Fork 0
/
combo.m
81 lines (58 loc) · 5.02 KB
/
combo.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
%%=================================================================================================================================================
%% OUTPUT FOR BUFFERED ALOHA WITH 2 ACTIVE NODES (N = 2)
%%=================================================================================================================================================
%%=============Initialisation of variables=========================================================================================================
S_buff_aloha = []; %% Array to store throughput values (Displayed on the y-axis)
N = 2; %% To be parameterised for N = 2, 5, 10 and INF
i = 0;
x_vals = []; %% Values on the x-axis
%%==================================================================================================================================================
%%=============Assuming there are no buffer overflows=======================================================================================
while i <= N %% dutyCycle needs to be non-negative
G = i; %% To be parameterised
T = G; %% Both are equal in the case of Buffered ALOHA (T = Transmitted Load & G = Offered Load)
%%================(G = T iff there are no buffer overflows and G < Channel Capacity (N))============================================================
dutyCycle = G/N;
P_nb = 1 - dutyCycle; %% Probability of not buffered
coll1 = P_nb ^ (N - 1); %% Collision-1 probability
coll2 = exp(-1 * (N - 1) * dutyCycle); %% Same as the unbuffered case
%% fprintf('Iteration = %d \tcollision-1 = %d \tcollision-2 = %d\n', i, coll1, coll2);
%%==================================================================================================================================================
%%===============Throughput calculation and storing in array [S = Ge^(-G)]==========================================================================
S = G * coll2 * coll1; %% Throughput calculation
S_buff_aloha = [S_buff_aloha, S]; %% Appending the values to form a list
x_vals = [x_vals, i]; %% Appending the x-values
i = i + 0.01; %% Incrementing the step-size by a small amount
end
N = 2; %% Number of nodes - needs to be parameterised in the future versions; Concretely ==> N = 2, 5, 10 and INF
T = 0.5; %% Initial value
dutyCycle = T/N; %% Setting some value initially
d = 2; %% Packet duration
omega = 10; %% Packet generation rate
S_unbuff_T = []; %% Array to store the throuput info ====> useful info for later processing
%%================ ARRAYS USED FOR PLOTTING G VERSUS T ============================================================================================================
%%=========================================================================================================================================================================
%% FOR 2 ACTIVE NODES
%%=========================================================================================================================================================================
T_history_2 = [];
G_history_2 = [];
i = 0;
while i<= N %% G is the Offered Load
G = i;
T = G/(1 + G/N); %% G = T / (1 - dutyCycle)
G_history_2 = [G_history_2, G]; %% Transmitted Load ======> Useful for plotting the graph between G and T
T_history_2 = [T_history_2, T];
collision1 = 1 - power((1 - dutyCycle), N - 1); %% probability of type-1 collision
P_t = exp(-omega * d);
collision2 = 1 - power(P_t, N - 1); %% Throughoput for unbuffered ALOHA ===> S_unbuff
S_unbuff_tmp = T*(1 - collision1)*(1 - collision2); %% Calculate this value for different values of the parameters and store it in an array
S_unbuff_T = [S_unbuff_T, S_unbuff_tmp]; %% Appending the newest value, for plotting purposes
i = i + 0.01;
end
%%=======================Plotting the graphs=========================================================================================================
plot(x_vals, S_buff_aloha, x_vals, S_unbuff_T); %% plot(x, y) - syntax
title('Throughput(S) versus Offered Load(G), N = 2');
xlabel('Offered Load(G)'); %% G = Average number of frames generated by the system during one frame transmission time (Unitless)
ylabel('Throughput(S)'); %% S = Throughput (Unitless)
i = i + 0.01;
%%===================================================================================================================================================