?? unicastgprs.m
字號:
% Unicast scheme in GPRS network.
% One cell implementation.
% With Link Adaptation
% Clear workspace
%clear
%clc
% Maximum time for simulation
t_max = 15*60; % seconds
% Sampling time
t_samp = 0.02; % the time is discrete, with sampling time is 1
% RLC blocks
% Number of Time slots
num_ts = 4;
% Carrier to Interference Ratio for user (as an input from channel part)
ctoi = CIR;
%ctoi = 6*ones(30,(t_max/t_samp));
cs = CIR_to_CS(CIR_uni,6,12,19); %coding scheme
% Create Traffic
user_traffic = traff;
% Initialization
buffhist = zeros(1,30);
overall_th = zeros(1,30);
packet_loss = zeros(1,30);
bits_loss = zeros(1,30);
% to make a graph, user 2-50
for N_user = 2:30
N_user
% Create Buffer
buffer = zeros(1,N_user);
%user throughput
average_th = zeros(1,N_user);
data = zeros(1,N_user);
% User's delay
delay = zeros(1,N_user);
% Loss channel
p_loss_chan = zeros(1,N_user); %packet
b_loss_chan = zeros(1,N_user); %bits
% Let it start!!!
t_old = 0;
t_new = t_old + t_samp;
user = 1 ;
index = 1; % number of packets received/enter buffer
while (t_new<t_max-0.0001)
% Update buffer
buffer = buffer + sum(user_traffic(floor(t_old/t_samp+1):floor((t_new/t_samp)))); % fill buffer with packet
%buffhist(state,:) = buffer; % record buffer
% if (user_traffic((2*(t_old/t_samp)+1):(2*t_new/t_samp)) ~= 0)
% index = index + 1; % calculate number of packet ( 1 index = 15 frames/packets)
% end
% transmitting data
switch (cs(user,floor((t_old/t_samp)+1)))
case 1
bitrate = num_ts*9050; %coding scheme 1
case 2
bitrate = num_ts*13400; %coding scheme 2
case 3
bitrate = num_ts*15600; %coding scheme 3
case 4
bitrate = num_ts*21400; %coding scheme 4
end
transmitted = bitrate * 0.0046 * 4; %4 RLC blocks
if (buffer(user) < transmitted)
transmitted = buffer(user);
end
% emptying buffer
buffer(user) = buffer(user)-transmitted;
%calculating throughput
a = per(cs(user,floor((t_old/t_samp)+1)),ctoi(user,floor((t_old/t_samp)+1)));
aa = a*ones(1,num_ts);
b = rand(1,num_ts) ;
success = find (b>=aa);
data(user) = data(user) + ((transmitted/num_ts)*length(success));
fail = find (b<aa);
p_loss_chan(user) = p_loss_chan(user) + length(fail) ;
b_loss_chan(user) = b_loss_chan(user) + ((transmitted/num_ts)*length(fail));
%calculating throughput(OLD)
% a = per(cs(user,floor((t_old/t_samp)+1)),ctoi(user,floor((t_old/t_samp)+1)));
% b = rand ;
% if ( b > a )
% data(user) = data(user) + transmitted;
% else
% p_loss_chan(user) = p_loss_chan(user) + num_ts*1 ;
% b_loss_chan(user) = b_loss_chan(user) + transmitted;
% end
% Next time, next user
user = mod(user,N_user)+1;
t_old = t_new;
t_new = t_new + t_samp; % update time
end
% Overall throughput
average_th = data/t_max;
overall_th(N_user) = sum(average_th)/N_user;
%average packet loss
all_packet = (t_max/t_samp)*4;
packet_loss(N_user) = sum(p_loss_chan)/(all_packet);
%average bits loss
bits_loss(N_user) = sum(b_loss_chan)/(N_user*t_max);
%buffer history
buffhist(N_user) = sum(buffer)/N_user;
end
th_uni = overall_th;
pl_uni = packet_loss;
buff_uni = buffhist;
x = 2:1:30;
figure(4)
subplot(2,2,1);
plot(x,overall_th(2:30));
grid on;title('Unicast Throughput');
subplot(2,2,2);
plot(x,packet_loss(2:30));
grid on;title('Unicast RLC Blocks Loss');
subplot(2,2,3);
plot(x,bits_loss(2:30));
grid on;title('Unicast Bits Loss');
subplot(2,2,4);
plot(x,buffhist(2:30));
grid on;title('Unicast Buffer Occupancy');
% figure(5)
% plot(x,average_delay);
% grid on;
clear overall_th buffhist packet_loss bits_loss ctoi average_th t_old t_new cs data N_user a b p_loss_chan b_loss_chan success fail transmitted user all_packet bitrate delay index user_traffic CIR_multi CIR_uni CIR buffer traff aa
save uni
% Overall delay
% delay counted as the time packet stays/waits in the buffer, thus
%difference between buffhist with value equals to zero (excluding
%consecutive zeros)
% for j = 1:N_user
% A = find(buffhist(:,j)==0);
% for k = 1:length(A)-1
% if( (A(k+1)-A(k)) > 1)
% delay(j) = delay(j) + (t_samp*(A(k+1)-A(k)));
% end
% end
% delay(j) = delay(j)/index;
% end
% average_delay(N_user) = sum(delay)/N_user;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -