Can anyone help me in simulating a Wireless sensor Network with 100 nodes in it.
Show older comments
I want to implement Wireless Sensor Network with following specifications
-> Sensors are sensing data and are at fixed locations. Sensors are to sense signals from body(Wireless Body Area Sensors)
-> Here the spectrum is ISM band, hence we need to have an efficient channel access mechanism ie I have to use CSMA/CA and don't know how to simulate one.
-> Sensors should work at 20Kbps and also the effect of energy needs to be included in the simulation.
-> There cannot be forwarding of data from one sensor to another sensor as each one has their own data to transmit.
-> I am essentially trying to simulate only the MAC and the physical layer.
-> I am also struck up with how to do this synchronization between the nodes, as I want to implement TDM and also FDM if possible between these nodes.
Please let me know if someone can help me. With Reagrds, Shravan
4 Comments
Avinash Chaudhary
on 12 Aug 2020
I want to complete my matlab code and want to get those results
Avinash Chaudhary
on 12 Aug 2020
My code is this.....
clear; %Field Dimensions - x and y maximum (in meters)/ Tarife Size mohite shabake(m) xm=100; ym=100; p=1; %x and y Coordinates of the Sink / sink.x=0.5*xm; sink.y=0.5*ym; %Number of Nodes in the field / Tedade Node haye shabake n=100; number_of_ch=0.1*n; %Optimal Election Probability of a node to become cluster head/ Ehtemale Entekhab Node be onvane Cluster Head %p=0.1; %Energy Model (all values in Joules)/ Energy ha bar hasbe Joule %Initial Energy / Energy Avaliye Eo=0.5; %maximum number of rounds %rmax=input('enter the number of iterations you want to run : '); rmax=3000;
figure(1); for i=1:1:n S(i).xd=rand(1,1)*xm; XR(i)=S(i).xd; S(i).yd=rand(1,1)*ym; YR(i)=S(i).yd; S(i).G=0;
S(i).E=Eo;
% Calculation of distance from sink node to normal node %
D(i)=sqrt(((S(i).xd-50)^2)+ ((S(i).yd-50)^2));
R(i)=(D(i)+Eo*150)*3;
%initially there are no cluster heads only nodes/ Dar ebteda hich Cluster Head i mojud nist
S(i).type='N';
S(i).e=Eo
%temp_rnd0=i;
%Random Election of Normal Nodes/ Entekhabe Tasadofi Node ha
plot(S(i).xd,S(i).yd,'o',...
'markerFace','b');
hold on;
end S(n+1).xd=sink.x; S(n+1).yd=sink.y; plot(sink.x,sink.y,'o', ... 'markerSize',15,'markerFace','r'); hold on;
%Eelec=Etx=Erx ETX=50*0.000000001; ERX=50*0.000000001; %Transmit Amplifier types Efs=10*0.000000000001; Emp=0.0013*0.000000000001; %Data Aggregation Energy EDA=5*0.000000001;
%Computation of do do=sqrt(Efs/Emp); S3=S; totalclust=10; %First Iteration %counter for CHs LcountCHs=0; %counter for CHs per round LrcountCHs=0; Lcluster=1;
%LcountCHs; LrcountCHs=LrcountCHs+LcountCHs; Lflag_first_dead=0;
figure(3) for r=1:rmax r hold off;
clust = randperm(n,totalclust); for i=1:totalclust
% clust=randi(n,1); S3(clust(i)).type='C'; cluster(i)=clust(i); end
for i=1:totalclust
plot(S3(cluster(i)).xd,S3(cluster(i)).yd,'*-g');
hold on;
end
plot(S3(n+1).xd,S3(n+1).yd,'o', 'MarkerSize', 12, 'MarkerFaceColor', 'r');
hold on;
for i=1:totalclust
clster_count(i)=0;
end
for i=1:n
% if(S3(i).type=='N')
% min_dis=sqrt( (S3(i).xd-S3(n+1).xd)^2 + (S3(i).yd-S3(n+1).yd)^2 );
min_dis=999999;
k=n+1;
k1=totalclust+1;
for j=1:totalclust
min_dis2=sqrt( (S3(i).xd-S3(cluster(j)).xd)^2 + (S3(i).yd-S3(cluster(j)).yd)^2 );
if(min_dis2<min_dis)
min_dis=min_dis2;
k=cluster(j);
k1=j;
end
end
% node_number(k1,i)=cluster(j);
S3(i).clustnum= k1;
S3(i).clustnode= k;
line([S3(i).xd, S3(k).xd], [S3(i).yd, S3(k).yd], 'Color', 'b', 'LineWidth', 0.5);
hold on;
clster_count(k1)=clster_count(k1)+1;
% line([S3(i).xd, S3(k).xd], [S3(i).yd, S3(k).yd], 'Color', 'b', 'LineWidth', 0.5);
% hold on;
% end end for j=1:totalclust total_node(j)=0; incre(j)=1; end for i=1:n % if (S3(i).type=='N') for j=1:totalclust if (S3(i).clustnum==j) total_node(j)=total_node(j)+1; node_no(j,incre(j))=i; res_energy(j,incre(j))=S3(i).E; incre(j)=incre(j)+1; end end % end end
for i=1:totalclust
for j=1:total_node(i)
dist_bs(i,j)=sqrt( (S3(node_no(i,j)).xd-S3(n+1).xd)^2 + (S3(node_no(i,j)).yd-S3(n+1).yd)^2 );
end
j=j+1;
dist_bs(i,j)=sqrt( (S3(cluster(i)).xd-S3(n+1).xd)^2 + (S3(cluster(i)).yd-S3(n+1).yd)^2 );
end
for i=1:totalclust
for j=1:total_node(i)
max_dist(i,j)=0;
total_dist(i,j)=0;
for k=1:total_node(i)
max_dis2=sqrt( (S3(node_no(i,j)).xd-S3(node_no(i,k)).xd)^2 + (S3(node_no(i,j)).yd-S3(node_no(i,k)).yd)^2 );
total_dist(i,j)=total_dist(i,j)+ max_dis2;
if(max_dis2>max_dist(i,j))
max_dist(i,j)=max_dis2;
end
end
end
end
for i=1:totalclust
for j=1:total_node(i)
avg_dist(i,j)=total_dist(i,j)/total_node(i);
distance1=sqrt((S3(node_no(i,j)).xd-S3(n+1).xd)^2 + (S3(node_no(i,j)).yd-S3(n+1).yd)^2 );
if(distance1>do)
min_energy(i,j)=4000* total_node(i) * ERX+ 4000* Emp* ETX * distance1*distance1*distance1*distance1;
else
min_energy(i,j)=4000* total_node(i) * ERX+ 4000* Emp* ETX *distance1*distance1;
end
end
end
for i=1:totalclust
for j=1:total_node(i)
delay(i,j)=res_energy(i,j);
end
end
alpha=0.33;
beta=0.33;
gama=0.33;
for i=1:totalclust
for j=1:total_node(i)
fitness(i,j)=delay(i,j);
end
end
[B I]=sort(fitness,2,'descend');
for i=1:totalclust
selected_ch(i)=node_no(i,I(i,total_node(i)));
if (selected_ch(i)==0)
selected_ch(i)=node_no(i,I(i,total_node(i))-1);
end
if (selected_ch(i)==0)
selected_ch(i)=node_no(i,I(i,total_node(i))-2);
end
end
for i=1:n
S3(i).type='N';
end
for j=1:n
for i=1:totalclust
if (j==selected_ch(i))
S3(i).type='C';
end
end
end
% Same for all algorithms
for i=1:n
if (S3(i).type=='N')
for j=1:totalclust
if (S3(i).clustnum==j)
min_dis=sqrt( (S3(i).xd-S3(selected_ch(j)).xd)^2 + (S3(i).yd-S3(selected_ch(j)).yd)^2 );
if (min_dis>do)
S3(i).E=S3(i).E - ( ETX *(4000) + Emp*4000*( min_dis * min_dis * min_dis * min_dis));
end
if (min_dis<=do)
S3(i).E=S3(i).E - ( ETX *(4000) + Efs*4000*( min_dis * min_dis));
end
end
end
else
Ldistance=sqrt( (S3(i).xd-S3(n+1).xd)^2 + (S3(i).yd-S3(n+1).yd)^2 );
if (Ldistance>do)
S3(i).E=S3(i).E- ( (ETX+EDA)*(4000) + Emp*4000*( Ldistance*Ldistance*Ldistance*Ldistance ));
%S2(i).E=S2(i).E- ( (ETX+EDA)*(4000) + Emp*4000*( Ldistance*Ldistance*Ldistance*Ldistance ));
end
if (Ldistance<=do)
S3(i).E=S3(i).E - ( (ETX+EDA)*(4000) + Efs*4000*( Ldistance * Ldistance ));
%S2(i).E=S2(i).E- ( (ETX+EDA)*(4000) + Efs*4000*( Ldistance * Ldistance ));
end
end
end
% Same for all algorithms
for i=1:n
if(S3(i).E>0)
Eres(r,i)=S3(i).E;
else
Eres(r,i)=0;
S3(i).E=0;
end
end
deadnode=0;
%figure(4);
%Same for all algoriths.
for i=1:n
dead(i)=0;
if(S3(i).E<=0)
dead(i)=dead(i)+1;
deadnode=deadnode+1;
%S3(i).type='D'
%plot(S(i).xd,p,'o',...
% 'markerFace','b');
% hold on;
% p=p+1;
end
end
d(r)=deadnode;
end
% no of nodes remaining after each rounds
for r=1:rmax
figure(4);
plot(p,n-d(r),'o',...
'markerSize',5,'markerFace','g');
hold on;
p=p+1;
end

Avinash Chaudhary
on 12 Aug 2020
Please help me soon
Walter Roberson
on 13 Aug 2020
you posted your own Question about this. People should look there rather than working on it here.
Accepted Answer
More Answers (0)
Categories
Find more on WSNs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!