N=input('please input the number of nodes:')
M=input('please input the Transmission window size:')
D=input('please input the maximum number of slot a node will wait after a collision:')
L=0; %L is the average CW size
for k=1:1:100000 %for 10 thousand loops
T=ones(1,N); %for simplicity,we assume at one moment, all the nodes get collision,assume all the nodes get collision,we set them in one position,that is '1' as a matrix
%for k=1:100000
for i=1:1:N
rand_slot=randint(1,D,[1,D]);%generate a waiting-slot sequence which max number is S,which is randomly distribute
T(i)=T(i)+rand_slot(D); %after a random waiting slot(D),some users may transmit,some user may get collision
end
S=sort(T);
if S(1)~=S(2) %try to find the number which only show once.it means this user has transmit success and no collision with others
S(1)=0; %and put this success nodes '0'
end
if S(N)~=S(N-1)
S(N)=0;
end
for i=2:1:(N-1)
if (S(i)~=S(i+1))&&(S(i)~=S(i-1))
S(i)=0;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%
while S(N-1)~=0 %in the end,all the nodes will finish the transmit.the last number in matrix S will be one contention window
S=sort(S);
for i=1:1:N
rand_slot=randint(1,D,[1,D]);
if S(i)~=0
S(i)=S(i)+rand_slot(D);
end
end
S=sort(S);
j=1;
while S(j)==0
j=j+1;
end
if S(j)~=S(j+1)
S(j)=0;
end
for j=(j+1):1:(N-1)
if (S(j)~=S(j+1))&&(S(j)~=S(j-1))
S(j)=0;
end
end
%if S(N)~=S(N-1)
% S(N)=0;
end
L=S(N)+L;
end
L=L/1000;
L
%the output will be the matrix S,which the last number will be the size of contention window
%However I did not know how to make 100000 trails for loop, I will keep
%thinking the way to implement it. I will sent the revised one as soon as I make this improvent.
%this is a .m file:double click the MATLAB 7.5 and click File,Open this
%file(maybe it require to add this file to the path), and click Run
%Thank you very much and I am will to explain my code by myself
%copyright@Yuan Song
slotted_ALHOA.rar_Contention Window_Slotted-Aloha_slotted_slotte
版权申诉
77 浏览量
2022-09-24
00:01:42
上传
评论
收藏 1KB RAR 举报
周楷雯
- 粉丝: 78
- 资源: 1万+
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈