资源简介
RFID中的Aloha算法,希望对大家有所帮助。
代码片段和文件信息
%function [ output_args ] = aloha( input_args )
%ALOHA Summary of this function goes here
% Detailed explanation goes here
%SIMULATION PARAMETERS
%simulation for pure Aloha protocol
%total simulation time in seconds
runtime=0.2;
%total number of stations
nstation=10;
%transmission throughput of the media in bits per second
netthrou=10e6;
%frame size in bits
fsize=8000;
%avarage frame arrival rate per second for each station
%frate=10;
for frate=1:5:150
%average frame arrival rate per simulation iteration
trh=frate/10000;
%random wait window in number of simulation iterations
wwind=100;
%EVENTS VARIABLES
%transmit active
tr=zeros(1nstation);
%transmit queue
tq=zeros(1nstation);
%transmit progress counter
tcnt=zeros(1nstation);
%collision keeper
colis=zeros(110000*runtime);
%collision station index
colin=zeros(1nstation);
%random wait after collision
rwait=zeros(1nstation);
%transmit keeper
trkeep=zeros(nstation10000*runtime);
%packet arrival keeper
pakeep=0;
for i=1:10000*runtime
for j=1:nstation
%check if the transmitter is active
if tr(j)==1
trkeep(ji)=1;
end
%check if the packet has been sent
if tcnt(j)>0
tcnt(j)=tcnt(j)-1;
if tcnt(j)==0
tr(j)=0;
%check if the transmission is collision free
if colin(j)==1
rwait(j)=ceil(wwind*rand(11));
tq(j)=tq(j)+1;
colin(j)=0;
end
end
else
if tq(j)>0 & rwait(j)==0
tr(j)=1;
tcnt(j)=ceil(fsize/netthrou*10000);
tq(j)=tq(j)-1;
end
end
%check if a new packet has arrived
pa=rand(11);
if pa pakeep=pakeep+1;
%if the transmit is ready
if tr(j)==0 & rwait(j)==0
tr(j)=1;
tcnt(j)=ceil(fsize/netthrou*10000);
else
tq(j)=tq(j)+1;
end
end
%decrease random waiting count
if rwait(j)>0
rwait(j)=rwait(j)-1;
end
end
%check for collision
if sum(tr)>1
colis(i)=1;
for k=1:nstation
if tr(k)==1
colin(k)=1;
end
end
end
end
px1(frate)=(pakeep-sum(tq));
py1(frate)=pakeep;
end
g1=[0:0.01:1.2];
s1=g1.*exp(-2*g1);
figure(1)
plot(px1*8000/runtimepy1*8000/runtime‘x‘s1*1e7g1*1e7‘-‘)
grid
xlabel(‘Throughput (bps)‘)
ylabel(‘Arrival Rate (bps)‘)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2383 2009-11-10 00:24 aloha.m
- 上一篇:matlab蔡氏电路
- 下一篇:灰度共生矩阵提取结肠癌图像特征,利用SVM分类
评论
共有 条评论