?? caltime.m
字號:
% calculate the processing time and maximum time for the adaptive p scheme
% G: number of subchannels
% subch: the subchannel used for each packet
% num_active1: number of totally transmitted packets
function [process_time, maxtime]=caltime(G,subch,num_active1)
% pick subchannels randomly
% find the number of collided packets in each subchannel
for pp=1:G
temp=find(subch==pp);
ch(pp)=length(temp);
end
% collision order
col_order=zeros(num_active1,1);
for tt=1:num_active1
col_order(tt)=ch(subch(tt));
end
% sort the collision order
% use highest-to-lowerest scheme to resolve collisions
sort_order=sort(ch)-1;
num_col_ch=length(find(sort_order>0));
if num_col_ch>0
temp=[];
for iii=1:num_col_ch
temp=[temp zeros(1,sort_order(end+1-iii)-1) sort_order(end+1-iii)];
end
end
% calculate CTE time
for iii=1:G
if ch(iii)==0
time(iii)=0;
elseif ch(iii)==1
time(iii)=1;
elseif ch(iii)>1
temp1=find(temp==(ch(iii)-1));
temp(temp1(1))=0;
time(iii)=1+ceil(temp1(1)/G);
end
end
% maximum time
maxtime=max(time);
for jj=1:num_active1
process_time(jj)= time(subch(jj));
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -