?? verifyuni.m
字號(hào):
% Unicast Verification in GPRS network.
% One cell implementation.
% Without 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;
% Random Carrier to Interference
rctoi = 10 + 5*randn(30,(t_max/t_samp));
% Create Traffic
user_traffic = traff;
for p = 1:3
% Coding Scheme and user's C/I
% 3 different case
switch p
case 1
ctoi = 6*ones(30,(t_max/t_samp));
case 2
m = min(rctoi,[],2) * ones(1,(t_max/t_samp));
ctoi = rctoi - m + (6*ones(30,(t_max/t_samp)));
case 3
m = max(rctoi,[],2) * ones(1,(t_max/t_samp));
ctoi = rctoi - m + 6*ones(30,(t_max/t_samp));
end
%Fixed Coding Scheme
cs = ones(30,(t_max/t_samp));
% 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 ;
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
% 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));
% 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
x = 2:1:30;
figure(1)
switch p
case 1
th_uni_fixed = overall_th;
pl_uni_fixed = packet_loss;
bf_uni_fixed = buffhist;
subplot(3,1,1);plot(x,overall_th(2:30),'*');hold on;grid on;title('Unicast Throughput');
subplot(3,1,2);plot(x,packet_loss(2:30),'*');hold on;grid on;title('Unicast Block Error Rate');
subplot(3,1,3);plot(x,buffhist(2:30),'*');hold on;grid on;title('Unicast Bits Loss in Buffer');
case 2
th_uni_varplus = overall_th;
pl_uni_varplus = packet_loss;
bf_uni_varplus = buffhist;
subplot(3,1,1);plot(x,overall_th(2:30),'+');hold on;grid on;title('Unicast Throughput');
subplot(3,1,2);plot(x,packet_loss(2:30),'+');hold on;grid on;title('Unicast Block Error Rate');
subplot(3,1,3);plot(x,buffhist(2:30),'+');hold on;grid on;title('Unicast Bits Loss in Buffer');
case 3
th_uni_varmin = overall_th;
pl_uni_varmin = packet_loss;
bf_uni_varmin = buffhist;
subplot(3,1,1);plot(x,overall_th(2:30),'-');hold on;grid on;title('Unicast Throughput');
subplot(3,1,2);plot(x,packet_loss(2:30),'-');hold on;grid on;title('Unicast Block Error Rate');
subplot(3,1,3);plot(x,buffhist(2:30),'-');hold on;grid on;title('Unicast Bits Loss in Buffer');
end
end
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 ver_uni
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -