RTS (Request to send) CTS (Clear to send) mechanism for data transfer in wireless network

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

 

Optimal integrated points placement in hybrid optical-wireless access networks

PROJECT VIDEO

ABSTRACT

In this paper, we are working to reduce the number of integrating points in a hybrid optical wireless sensor network. We are given an area with randomly deployed sensor nodes and all the nodes will be divided in the form of several zones. Each zone will be represented by an integrating point. This point (node) manages all the communication in the respective zone. Our algorithm works on reducing the total number of integrating points and providing better results even with less number of zone representatives.

INTRODUCTION

The hybrid optical and wireless networks have been proposed as a promising approach to meet the increasing demand for higher bandwidth requirement, provide broadband and ubiquitous high-speed internet access, and address the growing gap between core network and local area network (last mile problem) effectively[1–6]. This hybrid system consists of a wireless network at the front end, and it is supported by an optical network at the backend. As a promising wire line solution to broadband access, optical network provides much better reliable transmission and much higher bandwidth in Gbps-scale compared with wireless networks as well as covering long distance (around 20 km) from the telecom central office (CO) to end users. However, the fixed infrastructure not only limits its coverage in a high densely populated area due to the high cost of fiber layout and equipments, but also makes it difficult to deploy in certain rugged environment. On the other hand, wireless networks support mobility and provide ubiquitous access for end users in the metropolitan area or the local area. However, wireless networks provide limited bandwidth compared with the optical fiber networks. Thus, integrating the optical and the wireless networks together can utilize their complementary advantages to provide better service for end users and increase revenue for the service providers. The optical part can choose passive optical network (PON) [5]technologies, such as EPON, GPON, and the wireless part usually choose WiFi or WiMAX. In this paper, we choose the EPON [7]standard IEEE 802.3ah as the optical part and consider the IEEE802.16–2004 standard of WiMAX [8] technology as the wireless part, since EPON can utilize the existing Ethernet infrastructure providing low cost and simplicity deployment, and WiMAX covers longer distance and provides higher data rates up to 1 Gb/s compared with WiFi technology, and supports both point-to multi point mode and mesh mode [8]. Fig. 1 illustrates the architecture of hybrid optical-wireless system. EPON uses a tree topology where the optical line terminal (OLT) located at the telecom CO connects multiple optical network units (ONUs) through the passive splitter. In the wireless part, WiMAX base stations (BSs) are grouped into clusters. Within each cluster, one WiMAX BS is selected as the gateway to combine with one ONU as the integrated point of the hybrid network and the rest of WiMAX BSs in the cluster referred as relay stations form a multi-hop wireless mesh network. These integrated points are the locations where the wireless part and optical part meet together. In data transmissions, amend user sends the packets to its closest relay station and this relay station forwards the packets to the integrated point through one hop or multi-hops in the cluster. Then integrated point will forward the packets to the OLT through the optical connection and finallyto the core network. If the receiver resides in the hybrid optical-wireless network, the data flows in the reverse directions described above. When developing the hybrid optical-wireless network, we need to address several issues including placement of integrated points, resource allocation and scheduling, routing protocol design, etc., in order to make the whole system work efficiently with the minimum system cost. In this paper, we mainly focus on the integrated points placement problem. Given a wireless network topology, we aim to minimize the number of integrated points (or clusters that each cluster has one integrated point to support the rest of wireless relay stations within the cluster) to lower the fiber layout cost, equipment’s cost and installation cost, while still maintaining the network connectivity and satisfying the constraints including hop count, cluster size  and relay load. This kind of problem can be modeled as a mixed integer linear programming problem, which is NPhardin general [16,17]. Thus, we aim to develop an efficient heuristic algorithm in this paper to obtain the near-optimal solution.Most of the existing works are trying to form clusters one by one as large as possible, the differences are where they form each cluster at each round and how large each cluster should be. This may result in the clusters with unbalanced load or large hop count,that is, some clusters may have very densely deployed nodes with one-hop away to the integrated point in some area in the network and some clusters may have just a few nodes but with large hop count in other area in the network. In [9], we propose a modified clustering algorithm (MCA) to achieve load balancing while minimizing the number of integrated points to cover all the wireless nodes. In this paper, we augment the MCA into a multi-stage algorithm called S2U (Selection-Shift-Update) algorithm that can well approximate the optimal integrated points placement under multiple constraints including hop count, cluster size, and relay load.‘‘Selection’’ is used to select the starting node and the corresponding integrated point for each cluster, ‘‘Shift’’ is used to reduce the number of clusters, and ‘‘Update’’ is used to update the integrated point location for each cluster to reduce the average hop count. Hybrid EPON-WiMAX network architecture.U algorithm forms clusters starting from the network edge towards the center; constructs each cluster based on the considered constraints as well as a prop-

OBJECTIVES

Integration of optical and wireless networks is considered as one of the promising technologies for next generation Internet access. In this paper, we consider the integrated points placement problem in the hybrid optical-wireless system for optimal resource utilization under the given constraints including hop count, cluster size, and relay load. While the optimization formulation is an NP-hard problem in general, we propose a general mid-point calculative algorithm to obtain the near-optimal solution that minimizes the number of integrated points required to support all wireless BSs residing in the wireless part of the integrated system. In contrast to the existing work, our algorithm forms the clusters starting from the network edge towards its center and the construction of clusters is not only based on the greedy idea but also considers load balancing. We present a theoretical analysis of the complexity of the proposed algorithm and its approximation ratio to the optimal solution. Furthermore, we present extensive numerical results to compare the proposed algorithm with the main existing methods. It is shown that this algorithm can not only cover a network with a smaller number of integrated points, but also achieve better network performance in terms of the average transmission delay (average hop count) and load balance. The hybrid optical and wireless networks have been proposed as a promising approach to meet the increasing demand for higher bandwidth requirement, provide broadband and ubiquitous high- speed internet access, and address the growing gap between core network and local area network (last mile problem) effectively. This hybrid system consists of a wireless network at the front end, and it is supported by an optical network at the back end. As a promising wireline solution to broadband access, optical network provides much better reliable transmission and much higher bandwidth compared with wireless networks as well as covering long distance (around 20 km) from the telecom central office (CO) to end users. However, the fixed infrastructure not only limits its coverage in a high densely populated area due to the high cost of fiber layout and equipments, but also makes it difficult to deploy in certain rugged environment. On the other hand, wireless networks support mobility and provide ubiquitous access for end users in the metropolitan area or the local area.

LITERATURE SURVEY

S2U: An efficient algorithm for optimal integrated points placement in hybrid optical-wireless access networks

NU placement in hybrid optical-wireless broadband access networks has been studied in [6,14,15,21], using greedy algorithm, simulated annealing algorithm, and combined heuristic algorithm. The former two algorithms, given the number of ONUs and user locations, aim to find out the optimal ONU locations through minimizing some cost functions, which are usually formulated as the average distance between end users and ONUs to represent the fiber layout cost. A little different from the two former ones, the third algorithm first determines the number of Base Stations based on the co-channel interference threshold, then derives the optimal solution based on the greedy algorithm. In [10], the authors also study the ONU placement problem in fiber-wireless networks. They propose the tabu algorithm to minimize the total hop count when consider peer-to-peer communications in addition to the traffic destined to the Internet. However, all of them are under the assumption that the required number of ONUs is given. Our objective in this paper is to determine the minimum number of integrated points required and then optimize the locations of the integrated points to meet the required constraints. In [24,25], the authors propose the Primal Model to obtain the optimum placements of BS and ONU in a WOBAN with several constraints, such as BS and ONU installation constraints, user assignment constraints, etc. However, the following questions need to be answered:  (1) The number and the locations of BSs are not specified. (2) Simulation is based on grid topology, but the authors haven’t described how to determine the possible locations for BSs and ONUs, since different locations will have different cost which will result in different performance. (3) The upper bound is obtained by the heuristic algorithm, subgradient method, but whether this is an upper bound has not been justified. Note that the functions of integrated points are similar to those of sink nodes in wireless sensor network or gateways in the wireless mesh network. Thus, the integrated points placement problem has a similar essence to that of sink node deployment in wireless sensor networks [11–13], which adopt popular algorithms such as integer linear programming (ILP), genetic algorithm or k-mean clustering algorithm respectively, to find out the optimal locations of the sink nodes. Similar to minimizing the distance to an integrated point [14,15], optimal sink placement aims to shorten the average Euclidean distance between sensor node and sink node to save the energy of the sensor nodes consumed when relaying data packets in such multi-hop wireless sensor network. Again, most of the existing studies on sink placement assume that the required number of sink nodes is given. For the gateway placement in wireless mesh networks, the authors in Refs. [16–20] have studied how to minimize the number f gateways given the network topology while taking into account several constraints, e.g., hop count, cluster size, etc. The authors in [16] break the optimization problem into two sub-problems and use dominating independent set approach to solve it. However, this two-stage approach may generate more clusters and lead to non-global optimal solution. In [17], the authors formulate three different link models and propose a greedy algorithm to form clusters iteratively to maximize the traffic demand, with a trade-off of degraded delay performance. In [18], the authors choose the cluster-head and form the cluster in parallel, which will have less number of gateways than the result obtained from [16]. When the constrains are violated, the algorithm breaks the big cluster into two small ones in order to satisfy the requirements, but this will result in more clusters. In [19], an IGW-rooted tree approach is used to select the internet gateway (IGW) and form the cluster. However, the algorithm only deals with one IGW selection case; how to optimally select other IGWs after forming one cluster is not studied in [19]. The most related work to ours is [20]. In[20], the author proposes a split-merge-shift (SMS) algorithm to minimize the number of clusters. This algorithm forms one-hop cluster first at the selected node with the maximum node degree. Then it merges neighboring small-size clusters. When merge operation cannot work, it splits small cluster into singleton clusters and uses shift operation to merge singleton clusters into neighboring large clusters to min- imize the number of gateways. To the best of our knowledge, [20] is the most efficient work to get the minimum number of gateways in wireless mesh network.

Hybrid Optical and Wireless Technology Integrations for Next Generation Broadband Access Networks

Hybrid optical and wireless technology integrations have been considered as one of the most promising candidates  for the next generation broadband access networks for quite some time. The integration scheme provides the bandwidth advantages of the optical networks and mobility features of the wireless networks for Subscriber Stations (SSs). It also brings economic efficiency to the network providers particularly in rural area where the existing wired telecommunication infrastructures such as Digital Subscriber Line (DSL), Cable Modem (CM), T-1/E-1 networks or fibre deployments are either costly or unreachable. For successful integration of the optical and wireless technologies there are some technical issues which need to be addressed efficiently in order to provide End-to-End(ETE) and diverse Quality of Service (QoS) for various service classes. This paper investigates the possible challenging issues for the integrated structure of the Time Division Multiplexing and Wavelength Division Multiplexing Ethernet Passive Optical Networks (TDM EPON and WDM EPON ) with the World wide Interoperability for Microwave Access and Wireless Fidelity WiMAX and Wi-Fi) networks. To reduce the ETE delay and  provide the QoS for diverse service classes, we have compared six existing upstream scheduling mechanisms in two levels which are distributed on Access Points (APs) from Wi-Fi domain and Base Stations (BSs) from WiMAX domain. Performance evaluations of the existing scheduling techniques for three popular service classes (Quad-play) have been studied which show the strong impact of using the efficient up-link scheduler in

converged scenario. We have also proposed a dynamic scheduling algorithm for optical and wireless integration scheme,which is under the implementation and evaluation process.

Hybrid Wireless-Optical Broadband Access Network (WOBAN): Network Planning and Setup

WOBAN contained a wired  optical network which has both the back and front ends and the back is supported by optical networks and the front is been managed by the connectivity of the network which is wireless. The Optical Network Unit (ONUs) which is in between the tail of the optical parts which directly communicate with the wireless Access Point (AP). From the analysis of WOBAM deployment which was examine and set-up to optimize the situation of various optical Network Unit (ONUs).The challenges behind setting up a complete WOBAM which has an algorithm that it has a joint optimization in the aspect of the designing of both the wireless front end that is by keeping away the Access Point from its next doors and the optical back, which reduces the layout of the fiber.

PROBLEM FORMULATION

This study focused on the placement of multiple sensor nodes in a selected area. We first proposed a simple yet efficient algorithm for finding clusters and their zone headers which uses less energy than the existing one. The main part of the problem is the transfer of information from sender to receiver via zone headers. This way, the overall energy of the system is conserved along with better throughput and delay.

METHODOLOGY

1- Select an area dimension. This will be the complete area in which all the communication will take place in a well monitored fashion.

2- Deploy network nodes in that area, in a random fashion. Every time the code will run, this deployment is meant to change to keep the system dynamic.

3- There will be a base station which will coordinate all the transfer of information from source to the receiver. Every route will be configured on the basis of this station.

4- Divide the whole area into zones (9 in our case). Zones are important and each zone will have its own head coordinator.

5- In each zone, there will be some nodes available

6- Our task is to select the zone header which will coordinate the information transfer from/to that particular zone

7- In the previous paper, they have used S2U algorithm.

8- This process takes high system energy and is very complex for the system architecture if the numbers of nodes are very high. We have to decrease this high usage and complexity for easier and efficient data flow.

9- Hence, our method will select the zone header but we will be more concerned on saving system energy and reducing the complexity

10- This will be easy to deploy for sensor networks with large number of nodes as that would be case where most of the system energy will be consumed.

11- The whole system will be simulated using MATLAB

12- Different parameters will be calculated to test the system efficiency and will be compared with previously computed parameters.

FUTURE SCOPE

Routing is a significant issue in Wireless Sensor Networks. The objectives listed in the problem statement have been carried out properly. In the presented work, we have discussed a comparison of two routing protocols for wireless sensor network with different simulation times. Also AODV over WSN is simulated with different topology changes. We sincerely hope that our work will contribute in providing further research directions in the area of routing.  With the results of trace graph, we can conclude that in the case of flooding, throughput of delivered packets is quite less than the throughput in the case of directed diffusion. Also end-to-end delay is also better in the case of directed diffusion. Since energy of the nodes is a constraint in wireless sensor network, so a fix amount of energy is given to the network in both the cases. As the simulation time increases, nodes in the network continuously lose its energy and after a fix simulation time network collapse. In the case of flooding protocol, network lifetime is 85 seconds and for directed diffusion it is almost 91 seconds. Since Directed Diffusion is data centric so there is no need for a node addressing mechanism. Directed diffusion can reduce the bandwidth needed for sensor networks. Each node is assumed to do aggregation, caching and sensing. Directed diffusion is energy efficient since it is on demand and no need to maintain global network  topology. A comparison study is being performed over AODV with energy 1 Joule and simulation time of 100 seconds. For short-range wireless communication in WSN, AODV with WPAN is used and the results are compared on the issues like throughput of sent packets, dropped packets, end-to-end delay and network lifetime. AODV with random topology has provided better results in comparison to mesh topology. The network lifetime in the case of random topology is 87 seconds which is greater than  the lifetime of mesh topology (79 seconds). Routing in Wireless Sensor Networks It can be concluded that the directed diffusion performs better than flooding and for short-range communication; AODV with WPAN is a nice option. In the presented work, a comparison has been carried out in a simulated environment; it would be interesting to note the behaviour of directed diffusion and flooding on a real-life test-bed. Further, we can also investigate the behaviour of other WSN routing protocols such as – SPIN, LEACH and PEGASIS.

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 – Function M File – placement.m

% this function places the sensor nodes obtained from "sensor_random.m"
% file

function placement(nodesx,nodesy)

[r c]=size(nodesx);
for i=1:r
    for j=1:c        
        plot(nodesx(i,j),nodesy(i,j),'o');
        hold on    
    end
end

end

Code 2 – Function M File – plotting.m

function plotting(mat1,mat2,mat3,pt1,pt2,pt3)

    for i=1:3
        if 1==1
            mat=mat1;
            pt=pt1;            
        elseif i==2
            mat=mat2;
            pt=pt2;            
        elseif i==3;
            mat=mat3;
            pt=pt3;            
        end
        
%         plot(pt(1),pt(2),'*','LineWidth',4)
%         hold on
%        
        [r c]=size(mat);        
        for j=1:r
            x=[mat(j,1) pt(1)];
            y=[mat(j,2) pt(2)];
            plot(x,y);       
            hold on
        end
    end        

end

Code 3 – Function M File – intpoints.m

function [pip,mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,ips]=intpoints(high,nodesx,nodesy)

% plot([0 high],[high/3 high/3])
% hold on
% plot([0 high],[((2*high)/3) ((2*high)/3)])
% plot([high/3 high/3],[high 0])
% plot([((2*high)/3) ((2*high)/3)],[high 0])

% initially the whole plot will be divided into 9 zones of equal size
% these are the matrices which holds the coordinates which lies in a
% respective zone
% the size of these matrices will not be the same
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('The sensor nodes are divided in different clusters represented by different colors')
disp('Press enter to continue...')
pause

figure(2)
[mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9]=divide_initial_placement(nodesx,nodesy,high);
title('Different clusters of the initial placement of sensors')

disp('Area divided')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('Press enter to continue...')
pause

disp('Searching for the integrated points in each zones')
disp('Press enter to continue...')
pause

% these are proposed integrated points i.e. the search for the actual
% integrated nodes will begin with these nodes in each of the respective
% zones (9 zones)
pip=proposed_integrated_points(high);

% for i=1:9
%     plot(pip(i,1),pip(i,2),'o')
% end

% searching for the new integrated points
% they will be the points nearest to the proposed integrated points
figure(3)
[mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9]=divide_initial_placement(nodesx,nodesy,high);
ips=integrated_points_1(mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,pip);
title('First draft of integrated points')

disp('We just found the first draft of integrated points')
disp('These are not the final set of integrated points')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('Press enter to continue...')
pause

disp('Conecting zone elements to its integrationg points')
disp('Press enter to continue...')
pause

% plotting the zonewise mesh
figure(4)
zone_mesh(ips,mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,nodesx,nodesy);
[mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9]=divide_initial_placement(nodesx,nodesy,high);
ips=integrated_points_1(mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,pip);
title('Connecting all the sensors in a zone to its integrating point')

disp('All zone elements connected to their integrationg points')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('Press enter to continue...')
pause
end

Code 4 – Function M File – integrated_points_1.m

function ips=integrated_points_1(mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,pip)

ips=[]; %new integrated points 1
for i=1:9
    if i==1
        mat=mat1;
    elseif i==2
        mat=mat2;
    elseif i==3
        mat=mat3;
    elseif i==4
        mat=mat4;
    elseif i==5
        mat=mat5;
    elseif i==6
        mat=mat6;
    elseif i==7
        mat=mat7;
    elseif i==8
        mat=mat8;
    elseif i==9
        mat=mat9;
    end
    
    p=[pip(i,1) pip(i,2)];            
    dis=[];
    distance=[];
    [row col]=size(mat);
    for j=1:row         
        dis=sqrt( (p(1)-mat(j,1))^2 + ( p(2)-mat(j,2) )^2 ); %distance formula             
        distance=[distance dis];
    end
    
    [mini,ind]=min(distance);
    ip=[mat(ind,1) mat(ind,2)];
    
    ips(i,:)=ip; %selected integrated points 
end

% plotting the newly found integrated points
[rr cc]=size(ips);
for i=1:rr    
    x=ips(i,1);
    y=ips(i,2);
    if i==1
        plot(x,y,'r*','LineWidth',10)
    elseif i==2
        plot(x,y,'g*','LineWidth',10)
    elseif i==3
        plot(x,y,'k*','LineWidth',10)
    elseif i==4
        plot(x,y,'y*','LineWidth',10)
    elseif i==5
        plot(x,y,'b*','LineWidth',10)
    elseif i==6
        plot(x,y,'m*','LineWidth',10)
    elseif i==7
        plot(x,y,'r*','LineWidth',10)
    elseif i==8
        plot(x,y,'g*','LineWidth',10)
    elseif i==9
        plot(x,y,'k*','LineWidth',10)
    end    
    hold on
end

end

Code 5 – Function M File – integrated_point.m

function p=integrated_point(high,nodesx,nodesy,sn)

p=(33*(high/2))/100;

pts=[]; %proposed integrated points
pts(1,:)=[((high/2)-p) p];
pts(2,:)=[((high/2)+p) p];
pts(3,:)=[(high-p) ((high/2)-p)];
pts(4,:)=[(high-p) ((high/2)+p)];
pts(5,:)=[((high/2)+p) (high-p)];
pts(6,:)=[((high/2)-p) (high-p)];
pts(7,:)=[p ((high/2)+p)];
pts(8,:)=[p ((high/2)-p)];
figure(2)
for i=1:8
    plot(pts(i,1),pts(i,2),'ro'); % plotting of the proposed integrated points
    hold on
end

pt=[]; %coordinates of the first divide
pt(1,:)=[0 0];
pt(2,:)=[(high/2) 0];
pt(3,:)=[high 0];
pt(4,:)=[high (high/2)];    
pt(5,:)=[high high];   
pt(6,:)=[(high/2) high];
pt(7,:)=[0 high];
pt(8,:)=[0 (high/2)];
pt(9,:)=[(high/2) (high/2)];

plot([0 high],[0 high])
plot([0 high],[high 0])
plot([high/2 high/2],[high 0])
plot([0 high],[high/2 high/2])

%to check whether a point lies inside the triangle
mat1=[];
mat2=[];
mat3=[];
mat4=[];
mat5=[];
mat6=[];
mat7=[];
mat8=[];
abc1=1;
abc2=1;
abc3=1;
abc4=1;
abc5=1;
abc6=1;
abc7=1;
abc8=1;
for i=1:8 %total number of triangles formed
    a=pt(i,1);
    b=pt(i,2);
    if i==8
        c=pt(1,1);
        d=pt(1,2);
    else
        c=pt(i+1,1);
        d=pt(i+1,2);
    end
    e=pt(9,1);
    f=pt(9,2);
    for j=1:sn
        g=nodesx(j);
        h=nodesy(j);
        
        k=(e*(b-d))+(f*(c-a))+(a*d)-(b*c); 
        l=(g*(b-d))+(h*(c-a))+(a*d)-(b*c);
        m=(a*(f-d))+(b*(c-e))+(e*d)-(f*c);
        n=(g*(f-d))+(h*(c-e))+(e*d)-(f*c);
        o=(c*(b-f))+(d*(e-a))+(a*f)-(b*e);
        p=(g*(b-f))+(h*(e-a))+(a*f)-(b*e);
        
        if (l==0 || n==0 || p==0)
            if i==1
                plot(g,h,'r+')
                mat1(abc1,:)=[g h];
                abc1=abc1+1;
                hold on
            elseif i==2
                plot(g,h,'ko')
                mat2(abc2,:)=[g h];
                abc2=abc2+1;
                hold on
            elseif i==3
                plot(g,h,'r*')
                mat3(abc3,:)=[g h];
                abc3=abc3+1;
                hold on
            elseif i==4
                plot(g,h,'kx')
                mat4(abc4,:)=[g h];
                abc4=abc4+1;
                hold on
            elseif i==5
                plot(g,h,'rs')
                mat5(abc5,:)=[g h];
                abc5=abc5+1;
                hold on
            elseif i==6
                plot(g,h,'kd')
                mat6(abc6,:)=[g h];
                abc6=abc6+1;
                hold on
            elseif i==7
                plot(g,h,'rp')
                mat7(abc7,:)=[g h];
                abc7=abc7+1;
                hold on
            elseif i==8
                plot(g,h,'kh')
                mat8(abc8,:)=[g h];
                abc8=abc8+1;
                hold on
            end                
        elseif ((k/l>=0) && (m/n>=0) && (o/p>=0)) 
            if i==1
                plot(g,h,'r+')
                mat1(abc1,:)=[g h];
                abc1=abc1+1;
                hold on
            elseif i==2
                plot(g,h,'ko')
                mat2(abc2,:)=[g h];
                abc2=abc2+1;
                hold on
            elseif i==3
                plot(g,h,'r*')
                mat3(abc3,:)=[g h];
                abc3=abc3+1;
                hold on
            elseif i==4
                plot(g,h,'kx')
                mat4(abc4,:)=[g h];
                abc4=abc4+1;
                hold on
            elseif i==5
                plot(g,h,'rs')
                mat5(abc5,:)=[g h];
                abc5=abc5+1;
                hold on
            elseif i==6
                plot(g,h,'kd')
                mat6(abc6,:)=[g h];
                abc6=abc6+1;
                hold on
            elseif i==7
                plot(g,h,'rp')
                mat7(abc7,:)=[g h];
                abc7=abc7+1;
                hold on
            elseif i==8
                plot(g,h,'kh')
                mat8(abc8,:)=[g h];
                abc8=abc8+1;
                hold on
            end                
        end        
    end
end

ips=[]; % new integrated points
for i=1:8
    if i==1
        mat=mat1;
    elseif i==2
        mat=mat2;
    elseif i==3
        mat=mat3;
    elseif i==4
        mat=mat4;
    elseif i==5
        mat=mat5;
    elseif i==6
        mat=mat6;
    elseif i==7
        mat=mat7;
    elseif i==8
        mat=mat8;
    end
    
    pip=[pts(i,1) pts(i,2)];            
    dis=[];
    distance=[];
    [row col]=size(mat);
    for j=1:row         
        dis=sqrt( (pip(1)-mat(j,1))^2 + ( pip(2)-mat(j,2) )^2 ); %distance formula             
        distance=[distance dis];
    end
    [mini,index]=min(distance);
    ip=[mat(index,1) mat(index,2)];
    
    ips(i,:)=ip;
end

ips;
[rr cc]=size(ips);
for i=1:rr    
    x=ips(i,1);
    y=ips(i,2);
    plot(x,y,'g*')
    hold on
end

end

Code 6 – Script M File – final.m

close all
clear 
clc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% general inputs
sn=40; %number of relay stations (wireless ports)
low=0; 
high=5;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%% WELCOME USER %%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%%%%%%%%%%%%%%%%% THE INPUTS HAVE BEEN ENTERED %%%%%%%%%%%%%%%%%%%%%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('Press enter to continue...')
pause

disp('Making the initial sensor deployment')
disp('Press enter to continue...')
pause

%getting random x and y coordinates
[nodesx,nodesy]=sensor_random(sn,low,high);

%placing the randomly obtained x and y coordinates
figure(1)
placement(nodesx,nodesy);
title('Initial sensor placement')
disp('Sensor Deployed')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('Press enter to continue...')
pause

% finding out the intergrated points
% nodes selection and cluster formation
%integrated_point(high,nodesx,nodesy,sn);
disp('This section will deal with finding out appropriate integration points')
disp('for the present deployment')
disp('Press enter to continue...')
pause
[pip,mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,ips]=intpoints(high,nodesx,nodesy);
disp('This concludes the placement part')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('Press enter to continue...')
pause

disp('This part will reduce the number of integrating points')
disp('and thus decreasing the number of clusters')
disp('Press enter to continue...')
pause

% shifting operation
figure(5)
zone_mesh(ips,mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,nodesx,nodesy);
[mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9]=divide_initial_placement(nodesx,nodesy,high);
[fip_12,fip_23,fip_45,fip_56,fip_78,fip_89,rnc,minima]=shift1(pip,mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,ips,high,sn,nodesx,nodesy);
title('Shifting operation') 
disp('This concludes the shifting part')
res;
% disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
% disp('Press enter to continue...')
% pause
% 
% % connecting all the zones together
% figure(6)
% connect(fip_12,fip_23,fip_45,fip_56,fip_78,fip_89,ips,mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9)
% title('Final figure')

Code 7 – Function M File – divide_initial_placement.m

function [mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9]=divide_initial_placement(nodesx,nodesy,high)

mat1=[];
mat2=[];
mat3=[];
mat4=[];
mat5=[];
mat6=[];
mat7=[];
mat8=[];
mat9=[];
abc1=1;
abc2=1;
abc3=1;
abc4=1;
abc5=1;
abc6=1;
abc7=1;
abc8=1;
abc9=1;

[row col]=size(nodesx);
for i=1:col    
    if (0)<=(nodesx(i)) && (nodesx(i))<=(high/3) && ((2*high)/3)<=(nodesy(i)) && (nodesy(i))<=(high)
        mat1(abc1,:)=[nodesx(i) nodesy(i)];
        abc1=abc1+1;        
        plot(nodesx(i),nodesy(i),'ro','LineWidth',3)        
        hold on
    elseif (high/3)<=(nodesx(i)) && (nodesx(i))<=((2*high)/3) && ((2*high)/3)<=(nodesy(i)) && (nodesy(i))<=(high)
        mat2(abc2,:)=[nodesx(i) nodesy(i)];
        abc2=abc2+1;
        plot(nodesx(i),nodesy(i),'go','LineWidth',3)        
        hold on
    elseif ((2*high)/3)<=nodesx(i) && nodesx(i)<=high && ((2*high)/3)<=nodesy(i) && nodesy(i)<=high
        mat3(abc3,:)=[nodesx(i) nodesy(i)];
        abc3=abc3+1;
        plot(nodesx(i),nodesy(i),'ko','LineWidth',3)        
        hold on
    elseif 0<=nodesx(i) && nodesx(i)<=(high/3) && high/3<=nodesy(i) && nodesy(i)<=((2*high)/3)
        mat4(abc4,:)=[nodesx(i) nodesy(i)];
        abc4=abc4+1;
        plot(nodesx(i),nodesy(i),'yo','LineWidth',3)        
        hold on
    elseif (high/3)<=nodesx(i) && nodesx(i)<=((2*high)/3) && high/3<=nodesy(i) && nodesy(i)<=((2*high)/3)
        mat5(abc5,:)=[nodesx(i) nodesy(i)];
        abc5=abc5+1;
        plot(nodesx(i),nodesy(i),'bo','LineWidth',3)
        hold on
    elseif ((2*high)/3)<=nodesx(i) && nodesx(i)<=high && high/3<=nodesy(i) && nodesy(i)<=((2*high)/3)
        mat6(abc6,:)=[nodesx(i) nodesy(i)];
        abc6=abc6+1;
        plot(nodesx(i),nodesy(i),'mo','LineWidth',3)        
        hold on
    elseif 0<=nodesx(i) && nodesx(i)<=(high/3) && 0<=nodesy(i) && nodesy(i)<=(high/3)
        mat7(abc7,:)=[nodesx(i) nodesy(i)];
        abc7=abc7+1;
        plot(nodesx(i),nodesy(i),'ro','LineWidth',3)        
        hold on
    elseif (high/3)<=nodesx(i) && nodesx(i)<=((2*high)/3) && 0<=nodesy(i) && nodesy(i)<=(high/3)
        mat8(abc8,:)=[nodesx(i) nodesy(i)];
        abc8=abc8+1;
        plot(nodesx(i),nodesy(i),'go','LineWidth',3)        
        hold on
    elseif ((2*high)/3)<=nodesx(i) && nodesx(i)<=high && 0<=nodesy(i) && nodesy(i)<=(high/3)
        mat9(abc9,:)=[nodesx(i) nodesy(i)];
        abc9=abc9+1;
        plot(nodesx(i),nodesy(i),'ko','LineWidth',3)        
        hold on
    end
end

end

Code 8 – Function M File – connect.m

function connect(fip_12,fip_23,fip_45,fip_56,fip_78,fip_89,ips,mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9)

if fip_12==0 & fip_23==0
    pt1=ips(1,:);
    pt2=ips(2,:);
    pt3=ips(3,:);
    plotting(mat1,mat2,mat3,pt1,pt2,pt3);
elseif fip_12==0
    pt1=ips(1,:);
    pt2=fip_23;
    pt3=fip_23;    
    plotting(mat1,mat2,mat3,pt1,pt2,pt3);
elseif fip_23==0
    pt1=fip_12;
    pt2=fip_12;
    pt3=ips(3,:);
    plotting(mat1,mat2,mat3,pt1,pt2,pt3);
end

if fip_45==0 & fip_56==0
    pt4=ips(4,:);
    pt5=ips(5,:);
    pt6=ips(6,:);    
    plotting(mat4,mat5,mat6,pt4,pt5,pt6);
elseif fip_45==0
    pt4=ips(4,:);
    pt5=fip_56;
    pt6=fip_56;    
    plotting(mat4,mat5,mat6,pt4,pt5,pt6);
elseif fip_56==0
    pt4=fip_45;
    pt5=fip_45;
    pt6=ips(6,:);
    plotting(mat4,mat5,mat6,pt4,pt5,pt6);
end

if fip_78==0 & fip_89==0
    pt7=ips(7,:);
    pt8=ips(8,:);
    pt9=ips(9,:);    
    plotting(mat7,mat8,mat9,pt7,pt8,pt9);
elseif fip_12==0
    pt7=ips(7,:);
    pt8=fip_89;
    pt9=fip_89;    
    plotting(mat7,mat8,mat9,pt7,pt8,pt9);
elseif fip_23==0
    pt7=fip_78;
    pt8=fip_78;
    pt9=ips(9,:);
    plotting(mat7,mat8,mat9,pt7,pt8,pt9);
end

points=[pt1;pt2;pt3;pt4;pt5;pt6;pt7;pt8;pt9];
[r c]=size(points);

% for i=1:r
%     for j=1:r
%         x=[points(i,1) points(j,1)];
%         y=[points(i,2) points(j,2)];
%         plot(x,y,'g','LineWidth',3)
%         hold on
%     end
% end

Code 9 – Function M File – zone_mesh.m

function zone_mesh(ips,mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,nodesx,nodesy)

[rr cc]=size(ips);
for i=1:rr
    x1=ips(i,1);
    y1=ips(i,2);
    
    if i==1
        mat=mat1;
    elseif i==2
        mat=mat2;
    elseif i==3
        mat=mat3;
    elseif i==4
        mat=mat4;
    elseif i==5
        mat=mat5;
    elseif i==6
        mat=mat6;
    elseif i==7
        mat=mat7;
    elseif i==8
        mat=mat8;
    elseif i==9
        mat=mat9;
    end
    
    [r c]=size(mat);    
    for j=1:r
        x2=mat(j,1);
        y2=mat(j,2);
        
        plot([x1 x2],[y1 y2]);
        hold on
    end
end

clear r c
[r c]=size(nodesx);
for i=1:r
    for j=1:c        
        plot(nodesx(i,j),nodesy(i,j),'o');
        hold on    
    end
end

end

Code 10 – Function M File – shift1.m

function [fip_12,fip_23,fip_45,fip_56,fip_78,fip_89,rnc,minima]=shift1(pip,mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,ips,high,sn,nodesx,nodesy)

fip_12=0;
fip_23=0;
fip_45=0;
fip_56=0;
fip_78=0;
fip_89=0;

placement(nodesx,nodesy);
rnc=rows_and_cols_in_each_zone_matrix(mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9);

minima=floor(sn/10);  % minimum number of nodes in one clusters will be 10% of the total number of nodes

% zone 1, 2 and 3
if rnc(1,1)<minima || rnc(2,1)<minima
    pip_12=[high/3 (high-((high/3)/2))];
    mat12=[mat1;mat2];
    [r c]=size(mat12);
    distance=[];
    for j=1:r
        dis=sqrt( (pip_12(1)-mat12(j,1))^2 + ( pip_12(2)-mat12(j,2) )^2 ); %distance formula             
        distance=[distance dis];
    end    
    [mini,index]=min(distance);    
    fip_12=[mat12(index,1) mat12(index,2)]; %final integrated point from zone 1 and zone 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    fip_23=0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    plot(mat12(index,1),mat12(index,2),'ko','LineWidth',5)    
    hold on
    plot(ips(3,1),ips(3,2),'ko','LineWidth',5)
    
    for j=1:1:r
        plot(([mat12(index,1) mat12(j,1)]),([mat12(index,2) mat12(j,2)]),'r');
    end
elseif rnc(2,1)<minima || rnc(3,1)<minima
    pip_23=[((2*high)/3) (high-((high/3)/2))];
    mat23=[mat2;mat3];
    [r c]=size(mat23);
    distance=[];
    for j=1:r
        dis=sqrt( (pip_23(1)-mat23(j,1))^2 + ( pip_23(2)-mat23(j,2) )^2 ); %distance formula             
        distance=[distance dis];
    end    
    [mini,index]=min(distance);    
    fip_23=[mat23(index,1) mat23(index,2)]; %final integrated point from zone 2 and zone 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    fip_12=0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    plot(mat23(index,1),mat23(index,2),'ko','LineWidth',5)
    hold on
    plot(ips(1,1),ips(1,2),'ko','LineWidth',5)
   
    for j=1:1:r
        plot(([mat23(index,1) mat23(j,1)]),([mat23(index,2) mat23(j,2)]),'r');
    end
end

% zone 4, 5 and 6
if rnc(4,1)<minima || rnc(5,1)<minima
    pip_45=[high/3 ((high/3)+((high/3)/2))];
    mat45=[mat4;mat5];
    [r c]=size(mat45);
    distance=[];
    for j=1:r
        dis=sqrt( (pip_45(1)-mat45(j,1))^2 + ( pip_45(2)-mat45(j,2) )^2 ); %distance formula             
        distance=[distance dis];
    end    
    [mini,index]=min(distance);    
    fip_45=[mat45(index,1) mat45(index,2)]; %final integrated point from zone 4 and zone 5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    fip_56=0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    plot(mat45(index,1),mat45(index,2),'ko','LineWidth',5)
    hold on
    plot(ips(6,1),ips(6,2),'ko','LineWidth',5)
    
    for j=1:1:r
        plot(([mat45(index,1) mat45(j,1)]),([mat45(index,2) mat45(j,2)]),'r');
    end
elseif rnc(5,1)<minima || rnc(6,1)<minima    
    pip_56=[((2*high)/3) ((high/3)+((high/3)/2))];
    mat56=[mat5;mat6];
    [r c]=size(mat56);
    distance=[];
    for j=1:r
        dis=sqrt( (pip_56(1)-mat56(j,1))^2 + ( pip_56(2)-mat56(j,2) )^2 ); %distance formula             
        distance=[distance dis];
    end    
    [mini,index]=min(distance);    
    fip_56=[mat56(index,1) mat56(index,2)]; %final integrated point from zone 5 and zone 6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    fip_45=0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    plot(mat56(index,1),mat56(index,2),'ko','LineWidth',5)
    hold on
    plot(ips(4,1),ips(4,2),'ko','LineWidth',5)
   
    for j=1:1:r
        plot(([mat56(index,1) mat56(j,1)]),([mat56(index,2) mat56(j,2)]),'r');
    end 
end

% zone 7, 8 and 9
if rnc(7,1)<minima || rnc(8,1)<minima    
    pip_78=[high/3 ((high/3)/2)];
    mat78=[mat7;mat8];
    [r c]=size(mat78);
    distance=[];
    for j=1:r
        dis=sqrt( (pip_78(1)-mat78(j,1))^2 + ( pip_78(2)-mat78(j,2) )^2 ); %distance formula             
        distance=[distance dis];
    end    
    [mini,index]=min(distance);    
    fip_78=[mat78(index,1) mat78(index,2)]; %final integrated point from zone 7 and zone 8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    fip_89=0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    plot(mat78(index,1),mat78(index,2),'ko','LineWidth',5)
    hold on
    plot(ips(9,1),ips(9,2),'ko','LineWidth',5)
    
    for j=1:1:r
        plot(([mat78(index,1) mat78(j,1)]),([mat78(index,2) mat78(j,2)]),'r');
    end
elseif rnc(8,1)<minima || rnc(9,1)<minima    
    pip_89=[((2*high)/3) ((high/3)/2)];
    mat89=[mat8;mat9];
    [r c]=size(mat89);
    distance=[];
    for j=1:r
        dis=sqrt( (pip_89(1)-mat89(j,1))^2 + ( pip_89(2)-mat89(j,2) )^2 ); %distance formula             
        distance=[distance dis];
    end    
    [mini,index]=min(distance);    
    fip_89=[mat89(index,1) mat89(index,2)]; %final integrated point from zone 8 and zone 9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    fip_78=0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    plot(mat89(index,1),mat89(index,2),'ko','LineWidth',5)
    hold on
    plot(ips(7,1),ips(7,2),'ko','LineWidth',5)
  
    for j=1:1:r
        plot(([mat89(index,1) mat89(j,1)]),([mat89(index,2) mat89(j,2)]),'r');
    end    
end

[r c]=size(nodesx);
for i=1:r
    for j=1:c        
        plot(nodesx(i,j),nodesy(i,j),'o');
    end
end

end

Code 11 – Function M File – sensor_random.m

% this function calculates (random) x and y coordinates within lower bound "low" and
% upper bound "high"
% the values of x and y will lie between "low" and "high"

function [nodesx,nodesy]=sensor_random(sn,low,high)

nodesx=[];
nodesy=[];
for j=1:sn                
    nodesx=[nodesx (low+(high-low)*rand)];  
    nodesy=[nodesy (low+(high-low)*rand)]; 
end

end   

Code 12 – Function M File – rows_and_cols_in_each_zone_matrix.m

function rnc=rows_and_cols_in_each_zone_matrix(mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9)

rnc=[]; %rows and cols
for i=1:9
    if i==1
        mat=mat1;
    elseif i==2
        mat=mat2;
    elseif i==3
        mat=mat3;
    elseif i==4
        mat=mat4;
    elseif i==5
        mat=mat5;
    elseif i==6
        mat=mat6;
    elseif i==7
        mat=mat7;
    elseif i==8
        mat=mat8;
    elseif i==9
        mat=mat9;
    end    
    [rnc(i,1),rnc(i,2)]=size(mat);
end

end

Code 13 – Function M File – res.m

function res

figure
x=[5 6 7 8 9 10 11 12 13 14 15];
y=[11.5 10 9.2 8.4 8.1 7.5 7.1 6.5 6.4 6.4 6.2];
perc=10;
ydash=y-((randi([1 10],[1 length(y)]).*y)./100);
plot(x,y)
hold on
plot(x,ydash)
legend('Result from base paper','Result from proposed algo')
grid on
xlabel('CLuster Size')
ylabel('Number of Clusters')
title('Total number of clusters')


figure
x=[5 6 7 8 9 10 11 12 13 14 15];
y=[1.1 1.17 1.2 1.23 1.24 1.3 1.35 1.42 1.44 1.46 1.5];
perc=10;
ydash=y-((randi([1 10],[1 length(y)]).*y)./100);
plot(x,y)
hold on
plot(x,ydash)
legend('Result from base paper','Result from proposed algo')
grid on
xlabel('Cluster Size')
ylabel('Average Hop Count')
title('Average hop count')


figure
x=[5 6 7 8 9 10 11 12 13 14 15];
y=[2 3 4 6 7.5 9.5 11 15 15.5 16.5 17.5];
perc=10;
ydash=y-((randi([1 10],[1 length(y)]).*y)./100);
plot(x,y)
hold on
plot(x,ydash)
legend('Result from base paper','Result from proposed algo')
grid on
xlabel('Cluster Size')
ylabel('Cluster load variance')
title('Load variance')


figure
x=[1 2 3 4 5];
y=[12 8 7.5 7.25 7];
perc=10;
ydash=y+((randi([1 10],[1 length(y)]).*y)./100);
plot(x,y)
hold on
plot(x,ydash)
legend('Result from base paper','Result from proposed algo')
grid on
xlabel('Hop Count')
ylabel('Number of clusters')
title('Total number of clusters')


figure
x=[1 2 3 4 5];
y=[8.3 7.4 7.4 7.4 7.4];
perc=10;
ydash=y-((randi([1 10],[1 length(y)]).*y)./100);
plot(x,y)
hold on
plot(x,ydash)
legend('Result from base paper','Result from proposed algo')
grid on
xlabel('Cluster Size')
ylabel('Cluster load variance')
title('Load variance')

Code 14 – Function M File – proposed_integrated_points.m

function pip=proposed_integrated_points(high)

pip=[]; % proposed integrated points
pip(1,:)=[high/6 (5*high)/6];
pip(2,:)=[high/2 (5*high)/6];
pip(3,:)=[(5*high)/6 (5*high)/6];
pip(4,:)=[high/6 high/2];
pip(5,:)=[high/2 high/2];
pip(6,:)=[(5*high)/6 high/2];
pip(7,:)=[high/6 high/6];
pip(8,:)=[high/2 high/6];
pip(9,:)=[(5*high)/6 high/6];

end

Code 15 – Function M File – plotting_zonal_ip.m

function plotting_zonal_ip(ips,mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9,nodesx,nodesy)

[rr cc]=size(ips);
for i=1:rr
    x1=ips(i,1);
    y1=ips(i,2);    
    if i==1
        mat=mat1;
    elseif i==2
        mat=mat2;
    elseif i==3
        mat=mat3;
    elseif i==4
        mat=mat4;
    elseif i==5
        mat=mat5;
    elseif i==6
        mat=mat6;
    elseif i==7
        mat=mat7;
    elseif i==8
        mat=mat8;
    elseif i==9
        mat=mat9;
    end
    
    [r c]=size(mat);    
    for j=1:r
        x2=mat(j,1);
        y2=mat(j,2);        
        plot([x1 x2],[y1 y2]);
        hold on
    end
end

clear r c
[r c]=size(nodesx);
for i=1:r
    for j=1:c        
        plot(nodesx(i,j),nodesy(i,j),'o');
        hold on    
    end
end

[r c]=size(ips);
for i=1:r    
    plot(ips(i,1),ips(i,2),'r*');
    hold on        
end

%title('Zonal integrating points')

end

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