How can i get a matlab code for csma/ca
显示 更早的评论
I am currently working on cognitive Radio and I need a simulation source code for CSMA/CA. Could anyone please assist.
Thanks
5 个评论
Liliana Cruz
2021-5-17
Can I find the source code?
clear all
close all
clc
cwmax=1023;
n1.datarate=10;
cw=31;
cw_default=31;
reached=0;
toRetransmit=0;
sumDatarate = 8*n1.datarate;
DataSent = sumDatarate;
next_Sent=0;
bw=0;
nodeenergy = 50;
NWEinitial = nodeenergy * 8;
% % % % % % % % % % % % % % % % EXISTING
for i=1:10
if (DataSent<cw)
% next_Sent = sumDatarate+ toRetransmit
fprintf("\n\nPackets sent in iteration %i is: %i\n",i,DataSent);
fprintf("CW size in %i is: %i\n",i,cw);
reached=DataSent;
fprintf("Packets succeeded in iteration %i is: %i\n",i,reached);
lostPackets=0 ;
fprintf("Packets lost in iteration %i is: %i\n",i,lostPackets);
bw_available = cw;
bw_used = DataSent;
bw_wasted = bw_available - bw_used;
bw_available_E(i)=bw_available;
bw_used_E(i) = bw_used;
bw_wasted_E(i) = bw_wasted;
fprintf("Bandwidth wasted_Existing in %i is: %i\n\n",i,bw_wasted);
Eused_E = sum(bw_available_E)/5;
Re = NWEinitial - Eused_E;
Re_E = Re;
fprintf("Energy utilized_Existing in %i is: %i\n",i,Eused_E);
fprintf("Remaining Energy_Existing in %i is: %i\n\n",i,Re);
cw = cw_default
toRetransmit = 0;
fprintf("Packets to Retransmit in iteration %i is: %i\n\n",i,lostPackets);
lost(i) = lostPackets;
succeeded(i)=reached;
DataSent = toRetransmit + sumDatarate;
else
% next_Sent = sumDatarate+ toRetransmit
fprintf("\n\nPackets sent in iteration %i is: %i\n",i,DataSent);
fprintf("CW size in %i is: %i\n",i,cw);
reached=cw;
fprintf("Packets succeeded in iteration %i is: %i\n",i,reached);
lostPackets=DataSent - cw ;
fprintf("Packets lost in iteration %i is: %i\n",i,lostPackets);
bw_available = cw;
bw_used = cw;
bw_wasted = bw_available - bw_used;
bw_available_E(i)=bw_available;
bw_used_E(i) = bw_used;
bw_wasted_E(i) = bw_wasted;
fprintf("Bandwidth wasted in %i is: %i\n\n",i,bw_wasted);
Eused_E = sum(bw_available_E)/5;
Re = NWEinitial - Eused_E;
Re_E = Re;
fprintf("Energy utilized_Existing in %i is: %i\n",i,Eused_E);
fprintf("Remaining Energy_Existing in %i is: %i\n\n",i,Re);
cw = bitsll(cw,1)+3
toRetransmit = lostPackets;
fprintf("Packets to Retransmit in iteration %i is: %i\n\n",i,lostPackets);
lost(i) = lostPackets;
succeeded(i)=reached;
DataSent = toRetransmit + sumDatarate;
end
end
Hi, can some one please help me to modify the code to enable many number of nodes..that is with many sources and destinations with saturated data..Thanks inn advance
Walter Roberson
2022-7-13
You need more comments, such as what cw means.
Which variable(s) represent nodes in your code?
Is bandwidth shared? Are links completely independent, completely shared, partially shared? Which part of your code is modeling how much of a shared band is being currently used?
neethu subash
2022-7-14
the above code is doing contention window size variations as how it works in csma/ca binary backoff. Only one node is sending in my code..that is one sender..
回答(1 个)
Walter Roberson
2017-7-19
0 个投票
The following have all modeled CSMA/CA in MATLAB. Possibly one of them has made the source code available.
2 个评论
neethu subash
2022-7-13
is the code available? could not find one
Walter Roberson
2022-7-13
I do not have code for this purpose; I did a google search to create the list I posted above.
类别
在 帮助中心 和 File Exchange 中查找有关 Wireless Communications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!