资源简介
用matlab写的aloha防碰撞算法,涉及到吞吐量,数据包的数量,成功的数量,进行一个直观的分析。
代码片段和文件信息
function [throughputmeanDelaytrafficOfferedpcktCollisionProb] = saloha(sourceNumberpacketReadyProbmaxBackoffsimulationTimeshowProgressBarniceOutput)
% function [throughputmean delaytraffic offeredpacket collision probability]
% = saloha(source numberpacket ready probability maximum backoffsimulation time
% show progress barnice output)
%
% +++ Function input parameters
%
% source number (positive integer): the number of sources that generate packets.
%
% packet ready probability (real [01]): the probability that a given source has
% a packet ready to be transmitted at any given time slot.
%
% maximum backoff (positive integer): the maximum backoff value that a backlogged
% source must wait before a new transmission attempt.
%
% simulation time (positive integer): the duration of the simulation in time slots.
%
% show progress bar (optional): if true a progress bar showing the simulation
% advance will be displayed. Default behaviour is showProgressBar = false
% for faster simulations.
%
% nice output (optional): if true prints out the function outputs. Default
% behaviour is niceOutput = false.
%
% +++ Function outputs
%
% throughput: normalized throughput of the slotted aloha random access protocol
%
% mean delay: the average delay (in slots) for a packet to be successfully
% transmitted (acknowledge) from the moment it is ready at the source
%
% traffic offered: normalized traffic offered to the systemincluding
% retransmissions
%
% packet collision probability: probability that a packet collides with others
% at any given time slot
sourceStatus = zeros(1sourceNumber);
% legit source statuses are always non-negative integers and equal to:
% 0: source has no packet ready to be transmitted (is idle)
% 1: source has a packet ready to be transmitted either because new data must be sent or a previously collided packet has waited the backoff time
% >1: source is backlogged due to previous packets collision the value of the status equals the number of slots it must wait for the next transmission attempt
sourceBackoff = zeros(1sourceNumber);
pcktTransmissionAttempts = 0;
ackdPacketDelay = zeros(1simulationTime);
ackdPacketCount = 0;
pcktCollisionCount = 0;
pcktGenerationTimestamp = zeros(1sourceNumber);
currentSlot = 0;
if exist(‘showProgressBar‘‘var‘) && showProgressBar == 1
showProgressBar = 1;
progressBar = waitbar(0‘Generating traffic...‘‘CreateCancelBtn‘‘setappdata(gcbf‘‘canceling‘‘1)‘);
setappdata(progressBar‘canceling‘0);
else
showProgressBar = 0;
end
while currentSlot < simulationTime
currentSlot = currentSlot + 1;
if showProgressBar == 1
if getappdata(progressBar‘canceling‘)
delete(progressBar);
fprintf(‘\nWarning: terminated by user!\n‘);
break
end
waitbar(currentSlot / simulationTimeprogressBarsprintf(‘Packets sent: %u; packets acknowledged: %u.‘pcktTran
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-04-27 07:47 aloha-master\
文件 5 2015-04-27 07:47 aloha-master\.gitignore
文件 1042 2015-04-27 07:47 aloha-master\CHANGES.md
文件 18046 2015-04-27 07:47 aloha-master\LICENSE.md
文件 86 2015-04-27 07:47 aloha-master\README.md
文件 6 2015-04-27 07:47 aloha-master\VERSION
文件 4850 2015-04-27 07:47 aloha-master\saloha.m
文件 238 2015-04-27 07:47 aloha-master\slottedAlohaSamplesc
- 上一篇:奇异谱分析MATLAB代码.zip
- 下一篇:ALOHA防碰撞算法_matlab代码
评论
共有 条评论