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 commentaires

Liliana Cruz
Liliana Cruz le 17 Mai 2021
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
Packets sent in iteration 1 is: 80
CW size in 1 is: 31
Packets succeeded in iteration 1 is: 31
Packets lost in iteration 1 is: 49
Bandwidth wasted in 1 is: 0
Energy utilized_Existing in 1 is: 6.200000e+00
Remaining Energy_Existing in 1 is: 3.938000e+02
cw = 65
Packets to Retransmit in iteration 1 is: 49
Packets sent in iteration 2 is: 129
CW size in 2 is: 65
Packets succeeded in iteration 2 is: 65
Packets lost in iteration 2 is: 64
Bandwidth wasted in 2 is: 0
Energy utilized_Existing in 2 is: 1.920000e+01
Remaining Energy_Existing in 2 is: 3.808000e+02
cw = 133
Packets to Retransmit in iteration 2 is: 64
Packets sent in iteration 3 is: 144
CW size in 3 is: 133
Packets succeeded in iteration 3 is: 133
Packets lost in iteration 3 is: 11
Bandwidth wasted in 3 is: 0
Energy utilized_Existing in 3 is: 4.580000e+01
Remaining Energy_Existing in 3 is: 3.542000e+02
cw = 269
Packets to Retransmit in iteration 3 is: 11
Packets sent in iteration 4 is: 91
CW size in 4 is: 269
Packets succeeded in iteration 4 is: 91
Packets lost in iteration 4 is: 0
Bandwidth wasted_Existing in 4 is: 178
Energy utilized_Existing in 4 is: 9.960000e+01
Remaining Energy_Existing in 4 is: 3.004000e+02
cw = 31
Packets to Retransmit in iteration 4 is: 0
Packets sent in iteration 5 is: 80
CW size in 5 is: 31
Packets succeeded in iteration 5 is: 31
Packets lost in iteration 5 is: 49
Bandwidth wasted in 5 is: 0
Energy utilized_Existing in 5 is: 1.058000e+02
Remaining Energy_Existing in 5 is: 2.942000e+02
cw = 65
Packets to Retransmit in iteration 5 is: 49
Packets sent in iteration 6 is: 129
CW size in 6 is: 65
Packets succeeded in iteration 6 is: 65
Packets lost in iteration 6 is: 64
Bandwidth wasted in 6 is: 0
Energy utilized_Existing in 6 is: 1.188000e+02
Remaining Energy_Existing in 6 is: 2.812000e+02
cw = 133
Packets to Retransmit in iteration 6 is: 64
Packets sent in iteration 7 is: 144
CW size in 7 is: 133
Packets succeeded in iteration 7 is: 133
Packets lost in iteration 7 is: 11
Bandwidth wasted in 7 is: 0
Energy utilized_Existing in 7 is: 1.454000e+02
Remaining Energy_Existing in 7 is: 2.546000e+02
cw = 269
Packets to Retransmit in iteration 7 is: 11
Packets sent in iteration 8 is: 91
CW size in 8 is: 269
Packets succeeded in iteration 8 is: 91
Packets lost in iteration 8 is: 0
Bandwidth wasted_Existing in 8 is: 178
Energy utilized_Existing in 8 is: 1.992000e+02
Remaining Energy_Existing in 8 is: 2.008000e+02
cw = 31
Packets to Retransmit in iteration 8 is: 0
Packets sent in iteration 9 is: 80
CW size in 9 is: 31
Packets succeeded in iteration 9 is: 31
Packets lost in iteration 9 is: 49
Bandwidth wasted in 9 is: 0
Energy utilized_Existing in 9 is: 2.054000e+02
Remaining Energy_Existing in 9 is: 1.946000e+02
cw = 65
Packets to Retransmit in iteration 9 is: 49
Packets sent in iteration 10 is: 129
CW size in 10 is: 65
Packets succeeded in iteration 10 is: 65
Packets lost in iteration 10 is: 64
Bandwidth wasted in 10 is: 0
Energy utilized_Existing in 10 is: 2.184000e+02
Remaining Energy_Existing in 10 is: 1.816000e+02
cw = 133
Packets to Retransmit in iteration 10 is: 64
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
Walter Roberson le 13 Juil 2022
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
neethu subash le 14 Juil 2022
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..

Connectez-vous pour commenter.

Catégories

En savoir plus sur Wireless Communications dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by