📄 throughput_adaptivep.m
字号:
% adaptive p scheme for bursty traffic
% throughput evaluation
% ZF decoder (Fig. 4 left)
% warning: it can take very long time to run this code
clear all
close all
G=4; % number of subchannels
M=500; % total simulated slots
J=32; % number of users
simurange=10; % largest K to simulate
num_trial=1; % number of Monta-Carlo experiments
WorkLoad=[0:simurange-1]/simurange+0.01; % traffic
load channel_ng
throughput=zeros(G,simurange);
throughput1=zeros(G,simurange);
for ss=1:num_trial
ss
for ii = 1:simurange % K , i.e., K users simulteneously generate high-rate traffic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% at the first 100 slots, generate high-rate traffic then keep silent
Lamda=0.3;
Traffic=zeros(J,M+J);
tmp=randperm(J);
Traffic(tmp(1:ii),1:100) = rand(ii,100)< Lamda;
count_pack=zeros(G,1);
count_pack1=zeros(G,1);
for Np=1:G % for p=1,2,3,4 respectively
num_op(ss,Np,ii)=0; % number of operations (for complexity of ML)
flag=zeros(1,J);
time_table=zeros(J,(M+J)*G);
% the position of packets in time axis
pos_pack=zeros(J,(M+J)*G);
for nn=1:J
temp=find(Traffic(nn,:)>=1);
for mm=1:G
pos_pack(nn,mm:G:G*(length(temp)-1)+mm)=temp;
end
end
sm_traffic = G*Traffic; % one large packet equals G normal packets
Loads = zeros(1,J);
flag_CTE=0;
Relay = 1;
for t1 = 1:M
newLoads = sm_traffic(:,t1)';
Loads = Loads + newLoads; % new traffic
flag_CTE=max(0,flag_CTE-1);
if flag_CTE==0
Trans=Loads>0;
num_active=sum(Trans);
active = find(Trans)';
if num_active>0
% at most transmit p packets
Num_tranpack=min(Np,Loads(active)); % a vector storing number of transmited packet of each active user
% randomly select subchannels
subch=[];
active1=[];
rand('state',sum(100*clock));
for rrr=1:num_active
tmp1=randperm(G);
subch=[subch tmp1(1:Num_tranpack(rrr))];
active1=[active1 active(rrr)*ones(1,Num_tranpack(rrr))];
end
num_active1=length(active1);
% after randomly selecting subchannels, see how
% many packets in each subchannel
for pp=1:G
temp=find(subch==pp);
ch(pp)=length(temp); % number of packets in each subchannel
end
% calculate the successful packets
ML=0; % Zero-forcing equalizer
[succ Raysucc]=allian(t1,HH,HA,active1,subch,ch,G,Relay,ML);
Relay = mod(Relay + (num_active1-G),J)+1;
count_pack(Np)=count_pack(Np)+succ;
ret_array = zeros(1,J);
ret_array(active)=Num_tranpack;
Loads = Loads - ret_array; % update the queue (here we don't consider retransmisssions)
flag_CTE=ceil(num_active1/G); % length of CTE
count_pack1(Np)=count_pack1(Np)+num_active1; % count packets for the ideal case ( no packet loss)
end
end
end
throughput(Np,ii)=throughput(Np,ii)+count_pack(Np)/M/G;
throughput1(Np,ii)=throughput1(Np,ii)+count_pack1(Np)/M/G;
end
end
end
plot(1:simurange,throughput'/num_trial,'linewidth',2)
hold on
plot(1:simurange,throughput1'/num_trial,'k-','linewidth',2)
legend('p=1','p=2','p=3','p=4')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -