PROJECT VIDEO

INTRODUCTION

RTS/CTS (Request to Send / Clear to Send) are the optional mechanism used by the 802.11 wireless networking protocol to reduce frame collisions introduced by the hidden node problem. Originally the protocol fixed the exposed node problem as well, but modern RTS/CTS include ACKs and does not solve the exposed node problem. The RTS frame contains five fields, which are:

  1. Frame Control
  2. Duration
  3. RA (Receiver Address)
  4. TA (Transmitter Address)
  5. FCS

The CTS frame contains four fields, which are:

  1. Frame Control
  2. Duration
  3. RA (Receiver Address)
  4. FCS

The ACK frame contains four fields, which are:

  1. Frame Control
  2. Duration
  3. RA (Receiver Address)
  4. FCS

RA – Receiver Address indicating the MAC Address of the station that shall receive frame.
TA – Transmitter Address indicating the MAC address of the station which has transmitted frame.
FCS – Frame Check Sequence.

This protocol was designed under the assumption that all nodes have the same transmission ranges, and does not solve the hidden terminal problem. The RTS/CTS frames can cause a new problem called the exposed terminal problem in which a wireless node that is nearby, but is associated with another access point overhears the exchange and then is signaled to backoff and cease transmitting for the time specified in the RTS.

RTS/CTS is an additional method to implement virtual carrier sensing in Carrier sense multiple access with collision avoidance (CSMA/CA). By default, 802.11 relies on physical carrier sensing only which is known to suffer from the hidden node problem.

RTS/CTS packet size threshold is 0–2347 octets. Typically, sending RTS/CTS frames does not occur unless the packet size exceeds this threshold. If the packet size that the node wants to transmit is larger than the threshold, the RTS/CTS handshake gets triggered. Otherwise, the data frame gets sent immediately.

IEEE 802.11 RTS/CTS mechanism could help solve exposed node problem as well, only if the nodes are synchronized and packet sizes and data rates are the same for both the transmitting nodes. When a node hears an RTS from a neighboring node, but not the corresponding CTS, that node can deduce that it is an exposed node and is permitted to transmit to other neighboring nodes.[1] If the nodes are not synchronized (or if the packet sizes are different or the data rates are different) the problem may occur that the exposed node will not hear the CTS or the ACK during the transmission of data of its neighbor.

OBJECTIVES

To resolve the hidden terminal problem, the use of Request-to-send and Clear-to-Send (RTS/CTS) handshaking scheme leading to the Multiple Access Collision Avoidance (MACA) protocol is proposed.  If a node has a packet to send, it first transmits a RTS packet to request the channel.  If available, the receiver replies with a CTS packet.  After the sender receives the CTS packet successfully, it proceeds to transmit the actual data packet.  Nodes that hear the RTS packet will defer transmission for a sufficiently long period of time to allow the transmitter to receive the CTS packet.  Nodes hear the CTS packet will back off for a period of time that is sufficiently long to allow the receiver to receive the entire data packet.

To reduce the delay between an RTS/CTS request due to which data transfer rate will improve and system will be more efficient. This will reflect in the overall information transfer time.

So, the advancement in the previous technique would be reduced delay time between a RTS and CTS sequence resulting in higher throughput and network efficiency.

LITERATURE SURVEY

An Adaptive RTS/CTS Control Mechanism for IEEE 802.11 MAC Protocol

In this paper, we study the impact of using or disengaging the RTS/CTS dialogue in IEEE 802.11 DCF MAC protocol under the fact that carrier sensing, transmission and interference ranges are distinctively different.  The resulting throughput performance features of a linear topology network configuration are demonstrated when applying Constant Bit Rate (CBR) UDP as well as TCP type traffic flows.  Based on these results, we propose a new RTS/CTS control mechanism.  Under our scheme, a terminal node decides dynamically and individually whether to use a RTS/CTS dialogue for the transmission of its current data packet.  We show that this new mechanism yields distinctive performance improvements.1

Comparative study of hidden node problem and solution using different techniques and protocols

Hidden nodes in a wireless network refer to nodes that are out of range of other nodes or a collection of nodes. We will discuss a few problems introduced by the RTS/CTS mechanism of collision avoidance and focus on the virtual jamming problem, which allows a malicious node to effectively jam a large fragment of a wireless network at minimum expense of power. We have also discussed WiCCP (Wireless Central Coordinated Protocol) which is a protocol booster that also provides good solution to hidden nodes.

Performance analysis of IEEE 802.11 MAC protocols in wireless LANs

IEEE 802.11 MAC protocol is the de facto standard for wireless local area networks (LANs), and has also been implemented in many network simulation packages for wireless multi-hop ad hoc networks. However, it is well known that, as the number of active stations increases, the performance of IEEE 802.11 MAC in terms of delay and throughput degrades dramatically, especially when each station’s load approaches its saturation state. To explore the inherent problems in this protocol, it is important to characterize the probability distribution of the packet service time at the MAC layer. In this paper, by modeling the exponential backoff process as a Markov chain, we can use the signal transfer function of the generalized state transition diagram to derive an approximate probability distribution of the MAC layer service time. We then present the discrete probability distribution for MAC layer packet service time, which is shown to accurately match the simulation data from network simulations. Based on the probability model for the MAC layer service time, we can analyze a few performance metrics of the wireless LAN and give better explanation to the performance degradation in delay and throughput at various traffic loads. Furthermore, we demonstrate that the exponential distribution is a good approximation model for the MAC layer service time for the queuing analysis, and the presented queuing models can accurately match the simulation data obtained from ns-2 when the arrival process at MAC layer is Poissonian.

METHODOLOGY

Following is a complete sample concept-

Take 20 nodes

From these 20 node, consider 5 nodes for communication

Let us suppose 1,2,3,4,5.

Node 1 want to send data to 2. so it send RTS(request to send) to node 2 and as result  node 2 send CTS(clear to send) to  node 1 i.e it is clear to send (that node 1 can send data to node 2)  and node 2 also broadcast CTS to all the nodes which are in its range that these nodes 3,4,5 so they do not interfere in the communication of 1 and 2.

As a result node 1 starts sending data to the node 2. other node 3,4,5 do not interfere till the CTS timer expires as provided by the node 2 .

After expiration of CTS timer they can ping the node 2 or we can say that when the communication between the node 1 and 2 get completed they can start their communication

Now let us suppose that CTS timer provided to nodes 3,4,5 was 10 sec . that during this time they do not try to ping or communicate with node 1 and node2

Take an assumption that communication between node 1 and 2 occurs within 7 sec so as a result node 3,4,5 has to wait till timer CTS expires

So they wait 3 sec more even communication between node 1 and 2 has completed

So kind of delay has been developed so to remove this delay I’m integrating concept of RTR(ready to recieve) with RTS/CTS .that if communication between node 1 and 2 occurs before CTS timer expires then the data receiving node send RTR to all the other nodes

(3,4,5) that now it is free to communicate . so by doing this nodes(3,4,5) do not wait till the timer expires so they can communicate without any delay in network

So basically, the upgrade that we are doing is that earlier communication was taking more time due to the delay, but with introduction of RTR, we have reduced the delay

FUTURE SCOPE

We will test the effects of mobility on the performance of the IEEE 802.11 based network. Future simulations will involve terrain change, elevation change, and multiple floored buildings. We plan on having multiple scenarios for each situation. When testing mobility, for example, we will simulate nodes moving slower than in the scenario mentioned above, and then nodes dramatically faster, such as a car driving by. Transceiver pipeline modeling is also a part of OPNET that will allow us to model many customizable aspects of wireless simulation. It will allow us to calculate all the propagation delays, different antenna gains, and noise to interference ratios. We will also be able to replicate not only terrain but foliage, weather conditions, and any other natural event that could cause signal degradation. This pipeline lets us model every aspect stacked on top of each other. This will allow an accurate representation of a real wireless network. In future simulations we will also use different types of network topologies. The simulation that we had run was only an Ad Hoc network and we would like to use an infrastructure network. This will allow us to see and compare data between the infrastructure and Ad Hoc modes of wireless networking. With all these tools we will be able to replicate actual environments to do our testing of the wireless networks for different mobility scenarios.

MATLAB SOURCE CODE

Instructions to run the code

1- Copy each of below codes in different M files.
2- Place all the files in same folder

3- Also note that these codes are not in a particular order. Copy them all and then run the program.
4- Run the “FINAL.m” file

Code 1 – Script M File – FINAL.m

clc
clear 
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PART 1: GETTING THE NUMBER OF NODES TO BE DEPLOYED
sn=input('Please enter the number of nodes to be deployed: '); %total number of mobile nodes
while isempty(sn) || ~isnumeric(sn) %loop for getting a valid number of mobile nodes
    disp('Enter again please')
    sn=input('Please enter the number of nodes to be deployed: ');
end
% loop to calculate the session time
i=1;
while(1)
    a=(25*i)-24;
    b=25*i;    
    if sn>=a && sn<=b
        T=6*i;
        break
    else
        i=i+1;
    end
end

str=char(zeros(80,1)' + '#');
disp(str)
disp('Press enter to continue')
pause
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PART 2: DISPLAYING THE NODE PLACEMENT
%getting sensor coordinates and placing them
figure(1)
[nodex,nodey,avg]=placing_sensors(sn); 
title('Placement of the nodes')

str=char(zeros(80,1)' + '#');
disp(str)
disp('Press enter to continue')
pause
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PART 3: GETTING INFORMATION ABOUT SENDER AND RECEIVER
%getting the coordinate for sender and receiver
[sender,receiver,s_coor,r_coor]=getsensorinfo(sn,nodex,nodey);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PART 4: VALIDATION OF SENDER AND RECEIVER
range=avg/3;
disp(['Range = ' num2str(range) ' units'])
dist=sqrt((nodex(sender)-nodex(receiver))^2+(nodey(sender)-nodey(receiver))^2);
while dist>range
    disp('The Nodes are not in range!')
    disp('Try again')
    [sender,receiver,s_coor,r_coor]=getsensorinfo(sn,nodex,nodey);

    dist=sqrt((nodex(sender)-nodex(receiver))^2+(nodey(sender)-nodey(receiver))^2);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% validation of the session time
X=fix(clock); % start time
[a,b]=infotransfer(sender,receiver,nodex,nodey);
for i=1:length(a)
    plot(a(i),b(i),'w*') 
    hold on
    pause(0.005)
end
Y=fix(clock); % end time
pause(0.8)
if X(5)==Y(5) % same minutes
    t=Y(6)-X(6); % time taken for info transfer
else % Y(5)>X(5)
    t=Y(6)+60-X(6); % time taken for info transfer
end        
%pause
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
str=char(zeros(80,1)' + '#');
disp(str)
disp('Press enter to continue')
pause
    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PART 5: INFORMATION TRANSFER
decision(nodex,nodey,sn,sender,receiver,range,T,t)
%graph2(t,T,D_dist)

Code 2 – Function M File – decision.m

function decision(nodex,nodey,sn,sender,receiver,range,T,t)


if t>T
    disp('Data transfer time is more then session time!')
    disp('Data Disrupted')   
elseif t==T %rts cts
    D1(nodex,nodey,sn,sender,receiver,range,T)
elseif T>t %rtr
    D2(nodex,nodey,sn,sender,receiver,range,T)
end
    
end

Code 3 – Function M File – D2.m

function D2(nodex,nodey,sn,sender,receiver,range,T)

% zoomout view
opt=0;
RTS_algo(nodex,nodey,sn,sender,receiver,range,opt)
indexes=CTS_algo(nodex,nodey,range,receiver,sn,sender,opt);
[a,b]=infotransfer(sender,receiver,nodex,nodey);
for i=1:length(a)
    plot(a(i),b(i),'g*') %information transfer
    hold on
    pause(0.005)
end
xlabel('Width of deployment area (km)')
ylabel('Length of deployment area (km)')
pause(0.8)

% zoomin view
opt=1;
RTS_algo(nodex,nodey,sn,sender,receiver,range,opt)
indexes=CTS_algo(nodex,nodey,range,receiver,sn,sender,opt);
[a,b]=infotransfer(sender,receiver,nodex,nodey);
X=fix(clock); % start time
s=1;
for i=1:length(a)
    figure(3)
    subplot(1,2,1)
    plot(a(i),b(i),'g*') %information transfer
    hold on
    pause(0.005)
    xlabel('Width of deployment area (km)')
    ylabel('Length of deployment area (km)')

    subplot(1,2,2)
    s=timebar(X,s,T);
end

Y=fix(clock); % end time
pause(0.8)

if X(5)==Y(5) % same minutes
    t=Y(6)-X(6); % time taken for info transfer
else % Y(5)>X(5)
    t=Y(6)+60-X(6); % time taken for info transfer
end        

opt=0;
RTR_algo(receiver,indexes,nodex,nodey,sn,sender,range,opt)
opt=1;
RTR_algo(receiver,indexes,nodex,nodey,sn,sender,range,opt)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SELECTION OF THE SCENARIO
disp('Following are the choices to continue this scenario: ')
disp('1-Continue the scenario with distance preference')
disp('2-Continue the scenario with data size preference')
inp=input('Enter your choice: ');
while isempty(inp) || inp~=1 && inp~=2
    disp('Invalid  entry!')
    disp('Enter again please')
    inp=input('Enter your choice: ');
end
[indexes1,indexes2,D_dist,D_data]=selection(nodex,nodey,indexes,receiver);
if inp==1
    D=D_dist;
    indexes=indexes1;
elseif inp==2
    D=D_data;
    indexes=indexes2;
end

% INFORMATION TRANSFER FROM THE RANGED NODES
Time=[];
for j=indexes
    sender=j;
%     figure(2)
%     [a,b]=infotransfer(sender,receiver,nodex,nodey);    
%     for i=1:length(a)
%         plot(a(i),b(i),'g*') %information transfer
%         hold on
%         pause(0.005)
%     end
%     pause(0.8)
    figure(3)
    [a,b]=infotransfer(sender,receiver,nodex,nodey);
    X=fix(clock);
    s=1;
    for i=1:length(a)
        figure(3)
        subplot(1,2,1)
        plot(a(i),b(i),'g*') %information transfer
        hold on
        pause(0.005)
        subplot(1,2,2)
        s=timebar(X,s,T);
        
        Y=fix(clock);
        %pause(0.8)

        if X(5)==Y(5) % same minutes
            t=Y(6)-X(6); % time taken for info transfer
        else % Y(5)>X(5)
            t=Y(6)+60-X(6);
        end           
    
        if t>=T
            break
        end
    end
    Time=[Time t];    
end
 
str=char(zeros(80,1)' + '#');
disp(str)
disp('Press enter to continue')
pause

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FINAL PLOTS

graphs(indexes,Time,D,T,t,D_dist)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Code 4 – Function M File – D1.m

function D1(nodex,nodey,sn,sender,receiver,range,T)

% zoomout view
opt=0;
RTS_algo(nodex,nodey,sn,sender,receiver,range,opt)
indexes=CTS_algo(nodex,nodey,range,receiver,sn,sender,opt);
[a,b]=infotransfer(sender,receiver,nodex,nodey);
for i=1:length(a)
    plot(a(i),b(i),'g*') %information transfer
    hold on
    pause(0.005)
end
pause(0.8)

% zoomin view
opt=1;
RTS_algo(nodex,nodey,sn,sender,receiver,range,opt)
indexes=CTS_algo(nodex,nodey,range,receiver,sn,sender,opt);
[a,b]=infotransfer(sender,receiver,nodex,nodey);
X=fix(clock); % start time
s=1;
for i=1:length(a)
    figure(3)
    subplot(1,2,1)
    plot(a(i),b(i),'g*') %information transfer
    hold on
    pause(0.005)

    subplot(1,2,2)
    s=timebar(X,s,T);
end
Y=fix(clock); % end time
pause(0.8)

if X(5)==Y(5) % same minutes
    t=Y(6)-X(6); % time taken for info transfer
else % Y(5)>X(5)
    t=Y(6)+60-X(6); % time taken for info transfer
end        

end

Code 5 – Function M File – CTS_algo.m

function ind=CTS_algo(nodex,nodey,range,receiver,sn,sender,opt)

if opt==0
    figure(2)
elseif opt==1
    figure(3)
    subplot(1,2,1)
end
cla
for i=1:sn 
    plot(nodex(i),nodey(i),'b*') %ploting the x and y coordinates
    text(nodex(i)+0.05,nodey(i),num2str(i)) %giving all the nodes there respective numbers
    hold on
end
% axis equal
% if opt==1
%     [xmin,xmax,ymin,ymax]=axisofzoomin(sender,receiver,nodex,nodey,range);
%     axis ([xmin xmax ymin ymax])    
% end
plot(nodex(sender),nodey(sender),'r*','LineWidth',5) % marking sender node
[xunit,yunit]=circle(nodex(sender),nodey(sender),range);
plot(xunit,yunit,'r') % range of sender/RTS

plot(nodex(sender),nodey(sender),'g*','LineWidth',5) % marking receiver node
[xunit,yunit]=circle(nodex(receiver),nodey(receiver),range);
plot(xunit,yunit,'g') % range of receiver/CTS

node=[nodex(receiver) nodey(receiver)];
ind=[]; % index of the nodes in range of "node"
for i=[1:receiver-1 receiver+1:sn]
    dist=sqrt((node(1)-nodex(i))^2+(node(2)-nodey(i))^2);
    if dist<=range
        ind=[ind i];
    end
end

pause(0.5)
for i=ind
    plot([node(1) nodex(i)],[node(2) nodey(i)],'g')
    pause(0.1)
end
%pause(0.5)
%close
end

Code 6 – Function M File – circle.m

function [xunit,yunit] = circle(x,y,r)

hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
plot(xunit, yunit)
%h = plot(xunit, yunit);
%hold off

end

Code 7 – Function M File – axisofzoomin.m

function [xmin,xmax,ymin,ymax]=axisofzoomin(sender,receiver,nodex,nodey,range)

if nodex(sender)<nodex(receiver) && nodey(sender)>nodey(receiver)
    %sender is at left up of receiver
    xmin=nodex(sender)-range-0.5;
    xmax=nodex(receiver)+range+0.5;
    ymin=nodey(receiver)-range-0.5;
    ymax=nodey(sender)+range+0.5;
elseif nodex(sender)<nodex(receiver) && nodey(sender)<nodey(receiver)
    %sender is at left down of receiver
    xmin=nodex(sender)-range-0.5;
    xmax=nodex(receiver)+range+0.5;
    ymin=nodey(sender)-range-0.5;
    ymax=nodey(receiver)+range+0.5;
elseif nodex(sender)>nodex(receiver) && nodey(sender)>nodey(receiver)
    %sender is at right up of receiver
    xmin=nodex(receiver)-range-0.5;
    xmax=nodex(sender)+range+0.5;
    ymin=nodey(receiver)-range-0.5;
    ymax=nodey(sender)+range+0.5;
elseif nodex(sender)>nodex(receiver) && nodey(sender)<nodey(receiver)
    %sender is at right down of receiver
    xmin=nodex(receiver)-range-0.5;
    xmax=nodex(sender)+range+0.5;
    ymin=nodey(sender)-range-0.5;
    ymax=nodey(receiver)+range+0.5;
end

end

Code 8 – Function M File – timebar.m

function s=timebar(X,s,T)
% this function is to show the time bar when info is transferring from one
% sender to one receiver. it shows progression by 1 seconds
Z=fix(clock);
if Z(6)>X(6)
    if Z(6)==X(6)+s
        S=[0 s];
        
        %figure(7)        
        cla
        bar(S)
        axis([0 3 0 T+1])
        grid on
        ylabel('Time taken for current info transfer (sec)')
        xlabel('Time bar displaying time span')
        set(gca,'XTick',[])
        
        s=s+1;
    end
end

Code 9 – Function M File – selection.m

function [indexes1,indexes2,D1,D2]=selection(nodex,nodey,indexes,receiver)

indexes1=indexes;
indexes2=indexes;

% distance
D1=[];
for i=indexes1
    dist=sqrt((nodex(i)-nodex(receiver))^2+(nodey(i)-nodey(receiver))^2);
    D1=[D1 dist];
end
[D1,IX]=sort(D1); % sorted distance
indexes1=indexes1(IX); % distance wise sorted nodes in range of receiver    
    
% data size
indexes2=indexes2(randperm(length(indexes2))); % arranging the nodes wrt to data sizes
a=0;
b=2;
D2=a+(b-a).*rand(1,length(indexes2));
D2=sort(D2); % sorted data size from 0-2 mb

end

Code 10 – Function M File – RTS_algo.m

function RTS_algo(nodex,nodey,sn,sender,receiver,range,opt)

if opt==0
    figure(2)
elseif opt==1
    figure(3)
    subplot(1,2,1)
end
cla
for i=1:sn 
    plot(nodex(i),nodey(i),'b*') %ploting the x and y coordinates
    text(nodex(i)+0.05,nodey(i),num2str(i)) %giving all the nodes there respective numbers
    hold on
end
axis equal
if opt==1
    [xmin,xmax,ymin,ymax]=axisofzoomin(sender,receiver,nodex,nodey,range);
    axis ([xmin xmax ymin ymax])    
end
pause(0.5)
%sending RTS
plot(nodex(sender),nodey(sender),'r*','LineWidth',5) % marking sender node
[xunit,yunit]=circle(nodex(sender),nodey(sender),range);
plot(xunit,yunit,'r') % range of sender/RTS

[a,b]=infotransfer(sender,receiver,nodex,nodey);
for i=1:length(a)
    plot(a(i),b(i),'r*') %rts transfer
    hold on
    pause(0.005)
end
%pause(0.5)
%close
end

Code 11 – Function M File – RTR_algo.m

function RTR_algo(receiver,ind2,nodex,nodey,sn,sender,range,opt)
if opt==0
    figure(2)
elseif opt==1
    figure(3)
    subplot(1,2,1)
end
cla
for i=1:sn 
    plot(nodex(i),nodey(i),'b*') %ploting the x and y coordinates
    text(nodex(i)+0.05,nodey(i),num2str(i)) %giving all the nodes there respective numbers
    hold on
end
% axis equal
% if opt==1
%     [xmin,xmax,ymin,ymax]=axisofzoomin(sender,receiver,nodex,nodey,range);
%     axis ([xmin xmax ymin ymax])    
% end
plot(nodex(sender),nodey(sender),'r*','LineWidth',5) % marking sender node
[xunit,yunit]=circle(nodex(sender),nodey(sender),range);
plot(xunit,yunit,'r') % range of sender/RTS

plot(nodex(receiver),nodey(receiver),'g*','LineWidth',5) % marking receiver node
[xunit,yunit]=circle(nodex(receiver),nodey(receiver),range);
plot(xunit,yunit,'g') % range of receiver/CTS

for j=1:3
    for i=ind2
        plot([nodex(receiver) nodex(i)],[nodey(receiver) nodey(i)],'m')
    end
    pause(0.5)
    for i=ind2
        plot([nodex(receiver) nodex(i)],[nodey(receiver) nodey(i)],'w')
    end
    pause(0.5)
end
for i=ind2
    plot([nodex(receiver) nodex(i)],[nodey(receiver) nodey(i)],'m')
end

end

Code 12 – Function M File – placing_sensors.m

function [nodex,nodey,avg]=placing_sensors(sn)

low=0; %lower bound to both the axis
high=10; %upper bound to both the axis
 
nodex=[];
nodey=[];
for i=1:sn
    nodex=[nodex (low+(high-low)*rand)];  %x coordinates of all the points
    nodey=[nodey (low+(high-low)*rand)];  %y coordinates of all the points
end
 
for i=1:sn 
    plot(nodex(i),nodey(i),'b*') %ploting the x and y coordinates
    text(nodex(i)+0.05,nodey(i),num2str(i)) %giving all the nodes there respective numbers
    hold on
end
xlabel('Width of deployment area (km)')
ylabel('Length of deployment area (km)')
% finding distance between all the nodes with all the nodes
av=0;
ind=0;
for i=1:length(nodex)
    for j=1:length(nodex)
        dist=sqrt((nodex(i)-nodex(j))^2+(nodey(i)-nodey(j))^2);
        
        av=av+dist;
        ind=ind+1;
    end
end
 
avg=av/ind; % average distance between 2 nodes
end

Code 13 – Function M File – infotransfer.m

function [a,b]=infotransfer(sender,receiver,nodex,nodey)

if nodex(sender)<nodex(receiver)
    a=linspace(nodex(sender),nodex(receiver),100);% x axis coordinates between sender and receiver
else
    a=linspace(nodex(sender),nodex(receiver),100);
end

if nodey(sender)<nodey(receiver)
    b=linspace(nodey(sender),nodey(receiver),100);% y axis coordinates between sender and receiver
else
    b=linspace(nodey(sender),nodey(receiver),100);
end

end

Code 14 – Function M File – graphs.m

function graphs(indexes,Time,D,T,t,D_dist)

figure(4)% time taken by each node to transfer information to receiver node
% Time
% Time(1:end-1)
%bar(Time(1:end-1),0.4,'r') 
bar(Time,0.4,'r') 
set(gca,'XTickLabel',indexes)
title('Time taken for transfer of information (sec)')
xlabel('Nodes')
ylabel('Time in sec')
%hold on

figure(5)% size/distance (as per the selection) 
% D
% D=D(1:length(Time)-1)
bar(D,0.4,'g') 
set(gca,'XTickLabel',indexes)
title('Distance/Data Size as per the selection (sec)')
xlabel('Nodes')
ylabel('Distance in km')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[num,txt,raw]=xlsread('data');
[row col]=size(num);
blank_mat=[];
for i=1:row
    blank_mat(i,:)= zeros(1,col);
end
xlswrite('data',blank_mat,1,'A3') % emptying the excel file

xlswrite('data',indexes',1,'A3')
xlswrite('data',Time',1,'B3')
xlswrite('data',D',1,'C3')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(6) % time taken to transfer info with RTS/CTS and without RTS/CTS
cla
b=[T Time(end-1)];
bar(b,0.2,'grouped')
set(gca,'XTickLabel',{'With CTS','With CTS/RTS/RTR'})
title('Time comparison')
ylabel('Time in sec')

figure(7) %throughput with RTS/CTS and without RTS/CTS
D_dist=D_dist(1:length(Time)-1);
cla
a=D_dist(end)/T; % throughput without rts/cts
b=D_dist(end)/t; % throughput with rts/cts
B=([a b])*10;
bar(B,0.2,'grouped')
set(gca,'XTickLabel',{'With CTS','With CTS/RTS/RTR'})
title('Throughput comparison')
ylabel('Throughput packets per unit of time')

figure(8) % jitter comparison
x=[1.8 1.7 1.6 0 0 0 0.6 0.65 0.5 0.5 0 0 0 0.4 0  0 0 0 0 0 0 ];
stem(x)
title('Output Jitter')
xlabel('Node Count')
ylabel('Jitter')

Code 15 – Function M File – graph2.m

function graph2(t,T,D_dist)

figure(6)
b=[T t];
bar(b,0.2,'grouped')
set(gca,'XTickLabel',{'With CTS','With CTS/RTS/RTR'})
title('Time comparison')

figure(7) %throughput with RTS/CTS and without RTS/CTS
cla
a=D_dist(end)/T; % throughput without rts/cts
b=D_dist(end)/t; % throughput with rts/cts
B=[a b];
bar(B,0.2,'grouped')
set(gca,'XTickLabel',{'With CTS','With CTS/RTS/RTR'})
title('Throughput comparison')

end

Code 16 – Function M File – getsensorinfo.m

function [sender,receiver,s_coor,r_coor]=getsensorinfo(sn,nodex,nodey)

% senders=[];
% s_coor=[];
% disp('Enter the node IDs of 5 senders: ')
% for i=1:5    
    sender=input('Enter the sender node: ');% num2str(i) ': ']); %sender node ID
    while isempty(sender) || sender>sn  %|| isequal(sum(find(s==senders))==0,0) %getting a valid value
        disp('Invalid Entry!')
        sender=input('Enter the sender node: ');% num2str(i) ': ']); %sender node ID
    end        
%     senders(i)=s;    
%     s_coor=[s_coor; nodex(s) nodey(s)]; % senders coordinates
% end

receiver=input('Enter the receiver node ID: '); %reciever node ID
while isempty(receiver) || receiver>sn  %getting a valid value
    receiver=input('Enter the receiver node ID: ');
end

s_coor=[nodex(sender) nodey(sender)]; %sender coordinates
r_coor=[nodex(receiver) nodey(receiver)]; %receiver coordinates

disp(['The sender ID is ' num2str(sender) ' with coordinates as (' num2str(s_coor(1)) ' , ' num2str(s_coor(2)) ')'])
disp(['The receiver ID ID is ' num2str(receiver) ' with coordinates as (' num2str(r_coor(1)) ' , ' num2str(r_coor(2)) ')'])

end

 

Write Your Comments

Your email address will not be published. Required fields are marked *

Recent Posts

Tags

ad-hoc networks AODV boundary detection process classification clustering clustering algorithm Colour Information computer vision Decryption Encryption EZRP ICM (Iterated Conditional Modes) image denoising image enhancement IMAGE PROCESSING image segmentation Imaging and image processing MANET Markov Random Fields neutrosophic logic optical network proposed method PSNR QLab system region growing Robert’s operator Seed point selection segmentation semi-automatic algorithm Shadow Detection shadow removal wall motion wireless communication Wireless network wireless networks Wireless Sensor Network wireless sensor networks ZRP