PROJECT VIDEO

ABSTRACT

When information is moved from one part of a communication system (sender) to another part (receiver), this process is known as routing. Whenever such processes are taken care of, at least one intermediate node is involved. While working with routing protocols, we need to take care of the best possible path to carry out the transfer process. In our approach, we have divided the communication area into multiple zones and while our information is being transferred from zone to zone, we have taken care of the amount of energy and throughout the system could work on.

INTRODUCTION

Since the inception of wireless technologies, the application domain of Mobile Ad Hoc Networks (MANETs) is growing. All nodes in MANET are mobile in nature, so a MANET has dynamic topology structure. Moreover, without prior notice each node is free to join or leave a MANET whenever it wants. MANET is also self-organizing and self-congaing since it does not rely on axed infrastructure and works in shared wireless media. Lastly, each node in MANET is equipped with limited resources. With these characteristics of MANET, performing routing in MANET is a challenging task. There are many routing protocols available in literature. Excellent survey of these can be found in. They are mainly classier in two categories called – proactive routing and reactive routing. In proactive routing, the routes to all destinations are determined at the start-up and maintained by using a periodic route update process. So, these schemes cannot scale well as the network size increases. In reactive routing, each node tries to reduce routing overhead by only sending routing packets when it needs to communicate with other nodes. So, these schemes cannot scale well as number of traffic sessions increase. Zone Routing Protocol (ZRP) combines both proactive and reactive routing strategies to get the advantages of both.ZRP has the network topology as overlapping zones centered at each node. Within a zone, proactive Inter Azone Routing Protocol (IARP) is used to maintain local zone topology information. For nodes outside the zone, reactive Inter zone Routing Protocol (IERP) is used for sending data. Like the traditional reactive routing protocols, IERP also performs route discovery and route maintenance activities. To reduce the routing overhead while performing reactive route requests, Boarder cast Resolution Protocol (BRP) is used which broadcasts the route queries through the boarders of the zones.

By the development of computer industry, the computer size is getting smaller but with reach functionality. New types of mobile terminals have appeared such as a Smartphone, a net book PC and so on. Also, with the increase of network speed and decrease of transmission cost, the number of users and computers is increased very fast and the Internets growing every day. The wireless mobile networks and nodes are becoming increasingly popular and they provide users access to information and communication anytime and anywhere. In order to connect mobile nodes to the network generally are used wireless LANs . But, in wireless LAN, the Communication between mobile nodes is done using access points and thus the movement of mobile nodes is limited. The conventional wireless networks are often connected to a wired network (e.g. Internet) so that the Internet connections can be extended to mobile users. This kind of wireless network requires a fixed wire-line backbone infrastructure. All mobile nodes in a communication cell can reach a base station on the wire-line networks in one-hop radio transmission. In contrast, the class of Mobile Ad Hoc Networks (MANET) does not use any fixed infrastructure. The nodes of MANET intercommunicate through single-hop and multi-hop paths in a Peer-to-Peer(P2P) fashion. Intermediate nodes between two pairs of communication nodes act as routers. Thus, the nodes operate both as hosts and routers. The nodes are mobile, so the topology of the network may change rapidly and Leonard Barolli Department of Information and Communication Engineering, Fukuoka Institute of Technology
unexpectedly. Thus, the routing protocols play an important role for construction of MANET.

Routing protocols for MANET have been studied by MANET working group in IETF and until now various protocols such as Dynamic Source Routing (DSR) Protocol, Ad-hoc On-demand Distance Vector (AODV) protocol, Zone Routing Protocol (ZRP) Temporally Ordered Routing Algorithm (TORA), and Associativity-BasedRouting (ABR) have been proposed. However an optimum protocol for all environments does not exist because the network conditions are changed by network structure, scale and so on. Among these protocols, the ZRP has a wide application. However, when the protocol searches for a new route, it sends many useless control packets, which increase the network load and decrease the network performance. In our previous work , we proposed an Enhanced Zone Routing Protocol (EZRP). In EZRP, each node calculates the reliability value of the route. In the case of reliable route, the Source Node (SN) sends the data packet directly to the Destination Node (DN) using that route without route searching. While, in the case of unreliable route, the SN searches for a new route again. We showed via simulation that the network performance could be improved by using EZRP. In our previous work, though the performance evaluation of ZRP and EZRP was done by simulation, the performance evaluation of both protocols was not done by real machines.

The idea of Ad Hoc Networking is gaining popularity with the recent proliferation of mobile computers like laptops and palmtops. Minimal configuration, absence of infrastructure and quick deployment make Ad Hoc Networks convenient for emergency operations. Since host mobility causes frequent and unpredictable topological changes, the formation and maintenance of Ad Hoc Network is not only a challenging task and also it is different from the wired networks. Ad Hoc Routing Protocols are classified into Proactive and Reactive type. Proactive routing protocols use the periodic update of information to know about the current topology while the reactive routing protocols create a route to a destination on demand basis. Few of the proactive protocols are DSDV, WRP, DBF etc. while DSR, AODV, ABR are few examples of reactive protocols. Even though no protocol is superior to the other, but the previous studies indicate that in general reactive protocols exhibit better performance than proactive protocols.

OBJECTIVES

The main objective of the project will be the transfer of information from node of one region to the node of another region but not at the expense of path length and energy. Network throughput should also be maintained to maintain the efficiency and decrease the power consumption of the system.

LITERATURE SURVEY

Performance analysis of SODV, DSDV and DSR in MANETs by Akshai Aggarwal, Savita Gandhi, Nirbhay Chaubey.

Mobile Ad hoc Networks (MANETs) are considered as a new paradigm of infrastructure-less mobile wireless communication systems. MANETs are being widely studied and it is the technology that is attracting a large variety of applications. Routing in MANETs is considered a challenging task due to the unpredictable changes in the network topology, resulting from the random and frequent movement of the nodes and due to the absence of any centralized control. In this paper, we evaluate the performance of reactive routing protocols, Ad hoc On demand Distance Vector (AODV) and Dynamic Source Routing (DSR) and proactive routing protocol Destination Sequenced Distance Vector (DSDV).The major goal of this study is to analyze the performance of well known MANETs routing protocol in high mobility case under low, medium and high density scenario. Unlike military applications, most ofthe other applications of MANETs require moderate to high mobility. Hence it becomes important to study the impact of high mobility on the performance of these routing protocols. The performance is analyzed with respect to Average End-to-End Delay, Normalized Routing Load (NRL), Packet Delivery Fraction (PDF) and Throughput. Simulation results verify that AODV gives better performance as compared to DSR and DSDV.

An Efficient DSDV Routing Protocol for Wireless Mobile Ad Hoc Networks and its Performance Comparison by Khaleel Ur Rahman Khan, A Venugopal Reddy, Rafi U Zaman, K. Aditya Reddy, T Sri Harsha.

One of the popular wireless network architectures is mobile Ad Hoc Network (MANET) which can be deployed easily in almost any environment, without any underlying backbone and infrastructure support. In this paper, an efficient DSDV (Eff-DSDV) Protocol is proposed for Ad Hoc networks. Eff-DSDV overcomes the problem of stale routes, and thereby improves the performance of regular DSDV. The proposed protocol has-been implemented in the NCTU ns Simulator and performance comparison has been made with regular DSDV and DSR protocols. The performance metrics considered are packet-delivery ratio, end-end delay, dropped packets, routing overhead, route length. It has been found after analysis that the performance of Eff-DSDV is superior to regular DSDV and sometimes better than DSR in certain cases.

Performance Analysis of Zone Routing Protocols inMobile Ad Hoc Networks by Brijesh Patel and Sanjay Srivastava.

In Mobile Ad Hoc Networks (MANETs), routing is challenging task due to node mobility, traffics and network size. Its very important to analyze the scalability characteristics of the routing protocols with respect to these parameters. Zone Routing Protocol (ZRP) is considered to be one of the most scalable routing protocols due to its multi-scoping and hybridization features. We propose a general, parameterized model for analyzing control overhead of ZRP. A generic probabilistic model for data traffics is also proposed which can be replaced by different trafficmodels. Our analytical model is validated by comparisons with simulations performed under different network scenarios. In our simulation results, we have observed that the optimal zone radius lies at a point where proactive and reactive overhead components of ZRP are approximately equal as observed in [1]. Further, as the mobility increases the optimal zone radius value decreases, and as the traffic increases the value of optimal zone radius increases. If a node operates away from the optimal zone radius setting then it has to bear additional routing overhead. We show that the additional overhead is around 35% higher under a wide range of mobility scenarios.

An Implementation and Evaluation of Zone-Based Routing Protocol for Mobile Ad-hoc Networks by HarukiOsanai, Akio Koyama, Leonard Barolli.

In Mobile Ad-hoc Networks (MANET), the nodes intercommunicate through single-hop and multi-hop paths in apeer-to-peer fashion. Intermediate nodes between two pairs of communication nodes act as routers. Thus, the routing protocols play an important role for construction of MANET. Though the research of the routing protocol for MANET inactively done, most performance evaluations are evaluated via simulation. In this research, we implemented the zone-based routing protocol called ZRP and EZRP to real machines and evaluated by real environment. In the evaluation results, we showed that EZRP which is our proposed protocol has better performance than ZRP.

A Zone Based Routing Protocol for Ad Hoc Networks and Its Performance Improvement by Reduction of Control Packets by Yuki Sato, Akio Koyama, LeonardBarolli.

In recent years, there are many research works on ad hoc networks. In the future, we will see many ad hoc network applications, which are very important for realizing ubiquitous environments. The topology of ad hoc networks may change. For this reason, the routing protocols play an important role for construction of ad hoc networks. In this paper, we propose a new zone based routing protocol, which reduces the number of control packets. In the conventional routing protocols, the control packets are transmitted periodically. However, in the proposed protocol, the control packets are only transmitted when nodes are moving. The performance evaluation via simulations shows that the proposed protocol has a good performance and power consumption characteristics than conventional protocols.

 

METHODOLOGY/ PLANNING OF WORK

1- Input the whole area in which deployment is to be made
2- Divide the area into zones
3- Deploy equal number of sensors in each zone
4- Select a zone header/representative for each zone
5- Based upon this placement, there can be multiple paths from one node to another
6- Select a sender and a receiver
7- Now, information from the sender will first go to the zone header.
8- All the zone headers will communicate which each other to identify the receiver zone’s header.
9- Hence, inter zonal information will be transferred from sender zone head to receiver zone head.
10- From receiver zone head, information will go to the receiver node.
11- At the end, different parameters will be calculated to test the efficiency of the system.

PROBLEM FORMULATION

Following are the main problems at hand which motivated us in the direction of the proposed work

1- Energy consumption during transmission of data
2- Efficient node selection
3- Efficient routing
4- We would also like to preserve energy of those nodes which are not used yet

We have efficiently tried to eradicate the above mentioned problems in current scenario

FUTURE SCOPE

As a future scope, we can deploy this system on a larger area with more number of nodes. Also, header for a region could be selected by even better techniques such as neural networks, or integrated systems. Path selection could be improved by using shortest path algorithm.

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- Use the Excel files from below link and download them into the same folder as the source codes

coordinates          Energies at each node      ids

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

Code 1 – Script M File – final.m

clear all
close all
clc

disp('#####################################################################')
disp('#####################################################################')
disp('############################  Welcome!  #############################')
disp('##################  Please enter desired inputs  ####################')
disp('###################  Press enter to continue...  ####################')
disp('#####################################################################')
disp('#####################################################################')
pause

% inputs from the user
l=input('Enter the length of the deployment area: '); 
b=input('Enter the breadth of the deployment area: ');
n=input('Enter the number of zones in which the deployment area is to be divided: ');
disp('#####################################################################')

% to draw the deployment area according to the user and also finds its area
disp('Finding out the area of the deployment region')
disp('Press enter to continue...')
pause
area=dep_area(l,b); % function to find the area of the dimensions chosen
disp('#####################################################################')

% dividing the deployment area into equal zones
disp('Dividing the deployment area into zones as per user definition')
disp('Press enter to continue...')
pause
X=divide(l,b,n); %values in x axis at which the divisions are to be done in the area
disp('#####################################################################')

% getting positions of the sensor nodes
disp('Placing the sensors in each zone of the deployment area')
disp('Press enter to continue...')
pause
[nodesx,nodesy,p1_node,p2_node,q1_node,q2_node,sn]=sensor_uniform(X,b,l,n); %deploying the sensors in a uniform manner
% sn--> number of sensors in one zone
% nodesx and nodesy---> x axis and y axis coordinates for even of sensors in one zone
% p1_node,p2_node,q1_node,q2_node --> x axis and y axis coordinates for odd number of sensors in one zone
disp('#####################################################################')

% associating each node-id with its zone-id (refer the excel file)
disp('Associating each node-id with its zone-id')
disp('Result will be stored in the excel file named "ids.xls"')
disp('Press enter to continue...')
pause
FINAL=ids(n,sn); % matrix consisting of sensor numbers, zone ids and sensor ids
%excel file for all the values calculated above
disp('#####################################################################')

% getting the coordinates of the placed sensors refer the excel file
disp('Determining the coordinates of the placed sensors')
disp('Refer the excel file to know the coordinates')
disp('Press enter to continue...')
pause
coor=coordinates(nodesx,nodesy,p1_node,p2_node,q1_node,q2_node,sn,n); % excel file of the coordinates
disp('#####################################################################')

% going from source node to destination node
disp('Getting the information transfer path')
disp('Press enter to continue...')
pause
opt=1;
while opt==1
    [abc1,abc2,z1,z2,sennum1,sennum2,id1,id2]=src_des(coor,X,nodesx,nodesy,l,b,p1_node,p2_node,q1_node,q2_node,sn,n); % transfer of information from source to destination
    disp('#####################################################################')
    if z1<=n && z2<=n
        % energy calculation
        disp('Getting information about the energy consumed in the transfer process')
        disp('Press enter to continue...')
        pause
        [node_energies,x]=energy(sn,n,id1,id2,z1,z2,sennum1,sennum2); % computing the energy of the path of information transfer
        disp('Nodewise energy is provided in the excel file named "Energies at each node.xls"')
        disp('#####################################################################')
        % graphs
        graphs(node_energies,sn,n,z1,z2); % result graphs
        disp('#####################################################################')
        disp('Next figures will display the simulation results considerations')
        disp('Press enter to continue...')
        pause    
        % simulations 
%         sim_results;
    end 
    % prompting user to continue
    option=input('Do you want to continue (Y/N): ','s');
    while isempty(option)
        option=input('Do you want to continue (Y/N): ','s');
    end
    
    if isequal(option,'Y') || isequal(option,'y')
        opt=1;
        close all
    else
        opt=0;
        clear all
        close all
        clc
        break
    end
end

Code 2 – Function M File – graphs.m

function graphs(node_energies,sn,n,z1,z2)

x1=node_energies(:,1);
x2=node_energies(:,2);
figure(7)
bar(x2)
set(gca,'XTick',[1:length(x2)] )
set(gca,'XTickLabel',[x1])
title('Nodes involved in info. transfer VS Energies at those nodes')
xlabel('Nodes involved')
ylabel('Energy values')

N=sn*n;
x=[];
for i=1:n
    for j=1:sn
        x=[x ((i*100)+j)];
    end
end

y=[];
for i=1:N
    for j=1:length(x1)
        if x(i)~=x1(j)
            y(i)=100;
        elseif x(i)==x1(j)
            y(i)=x2(j);
            break;
        end
    end
end
   
figure(8)
bar(y)
set(gca,'XTick',[1:length(y)] );
set(gca,'XTickLabel',[x]); 
title('Overall energy distribution')
xlabel('Nodes')
ylabel('Energy')

% figure(14)
% oneunit=(1/n)*100;
% dif=abs(z1-z2);
% xx=[];
% for i=1:dif
%     x=100-i*oneunit;
%     xx=[xx x];
% end   
% if z1>z2
%     h=z1:-1:z2;
% else
%     h=z1:z2;
% end
% 
% bar(xx)
% set(gca,'XTick',[h]);
% title('Zone Radius VS Energy')
% xlabel('Zone Radius')
% ylabel('Energy')

Code 3 – Function M File – ids.m

function FINAL=ids(n,sn)
% sn=13;
% n=5;
[num,txt,raw]=xlsread('ids');
[row col]=size(num);
blank_mat=[];
for i=1:row
    blank_mat(i,:)= zeros(1,col);
end
xlswrite('ids',blank_mat,1,'C3')
%pause

FINAL=[];
%id=input('enter the sensor number to find out its sensor id and zone id: ');
if mod(sn,2)==0
    %even number of sensors in one zone    
    a=1;
    sense_1=[];   % matrix for the serial numbers of sensors (counting from left to right)
    for i=1:(sn/2)
        for j=1:(2*n)
            sense_1(i,j)=a; 
            a=a+1;
            
        end
    end
    clear a i j
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    a=0;
    sense_2=[];  % matrix to determine zone ids
    for i=1:(sn/2)
        for j=1:(2*n)
            if mod(j,2)==0
                a=a;
                sense_2(i,j)=a;
                if a==n
                    a=0;
                end
            else
                a=a+1;
                sense_2(i,j)=a;
            end       
        end
    end
    clear i j a 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    a=100;
    sense_3=[];
    k=1;

    for i=1:(2*n)   
        for j=1:(sn/2)               
            if mod(i,2)==0
                h=(a*k)+(2*j);
                sense_3(j,i)=h;
            else
                h=(a*k)+(2*j)-1;
                sense_3(j,i)=h;
            end      
        end
        if mod(i,2)==0
             k=k+1;
        end
    end    
    clear i j k a 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
%     disp('sensor numbers: ')
%     disp(sense_1)
%     disp('zone ids: ')
%     disp(sense_2)
%     disp('sensor ids: ')
%     disp(sense_3)
    
    [r c]=size(sense_1);
    ij=1;
    for i=1:r
        FINAL(ij,:)=sense_1(i,:);
        ij=ij+1;
        FINAL(ij,:)=sense_2(i,:);
        ij=ij+1;
        FINAL(ij,:)=sense_3(i,:);
        ij=ij+1;
    end  
    xlswrite('ids',FINAL,1,'C3');
    
else
   %odd number of sensors in one zone    
    hsn=floor(sn/2);
    a=1;
    sense11=[];   
    for i=1:(hsn)
        for j=1:(2*n)
            sense11(i,j)=a; 
            a=a+1;            
        end
    end
    sense12=[];
    for i=1:(2*n)
        if mod(i,2)==0
            sense12=[sense12 0];
        else
            sense12=[sense12 a];
            a=a+1;
        end
    end
    
    sense_1=[sense11;sense12];
    clear i j a 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
    a=0;
    sense21=[];  % matrix to determine zone ids
    for i=1:(sn/2)
        for j=1:(2*n)
            if mod(j,2)==0
                a=a;
                sense21(i,j)=a;
                if a==n
                    a=0;
                end
            else
                a=a+1;
                sense21(i,j)=a;
            end       
        end
    end
    
    sense22=[];
    a=1;
    for i=1:(2*n)
        if mod(i,2)==0
            sense22=[sense22 0];
        else
            sense22=[sense22 a];
            a=a+1;
        end
    end
    
    sense_2=[sense21;sense22];
    clear i j a 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    a=100;
    sense31=[];
    k=1;

    for i=1:(2*n)   
        for j=1:(sn/2)               
            if mod(i,2)==0
                h=(a*k)+(2*j);
                sense31(j,i)=h;
            else
                h=(a*k)+(2*j)-1;
                sense31(j,i)=h;
            end      
        end
        if mod(i,2)==0
             k=k+1;
        end
    end    
    
    sense32=[];
    k=1;
    for i=1:(2*n)
        if mod(i,2)==0
            sense32=[sense32 0];
        else
            h=(a*k)+sn;
            sense32=[sense32 h];
            k=k+1;
        end
    end
    
    sense_3=[sense31;sense32];
    clear i j k a
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
%     disp('sensor numbers: ')
%     disp(sense_1)
%     disp('zone ids: ')
%     disp(sense_2)
%     disp('sensor ids: ')
%     disp(sense_3)
    
    [r c]=size(sense_1);
    ij=1;
    for i=1:r
        FINAL(ij,:)=sense_1(i,:);
        ij=ij+1;
        FINAL(ij,:)=sense_2(i,:);
        ij=ij+1;
        FINAL(ij,:)=sense_3(i,:);
        ij=ij+1;
    end  
    xlswrite('ids',FINAL,1,'C3');   
end

end

Code 4 – Function M File – mesh_formation.m

function mesh_formation(coor,n,sn,nodesx,nodesy,l,b,p1_node,p2_node,q1_node,q2_node)

figure(4)
for i=1:n
    mat=[coor(:,((4*i)-3)) coor(:,((4*i)-2)) coor(:,((4*i)-1)) coor(:,(4*i))];
    [r1 c1]=size(mat);    
    
    if mod(sn,2)==0    
        %even case
        for a=1:r1
            for bb=1:2
                for c=1:r1
                    for d=1:2
                    
                        b1=(2*bb)-1;                   
                        b2=(2*bb);                    
                        d1=(2*d)-1;                    
                        d2=(2*d);                   
                    
                        x=[(mat(a,b1)) (mat(c,d1))];
                        y=[(mat(a,b2)) (mat(c,d2))];                    
                        plot(x,y)
                        hold on
            
                    end
                end            
            end
        end 
        
        [r c]=size(nodesx);
        
        for i1=1:r
            for j1=1:c
                if i1==1 && rem(j1,2)==1
                    plot(nodesx(i1,j1),nodesy(i1,j1),'r*');
                    hold on
                else
                    plot(nodesx(i1,j1),nodesy(i1,j1),'*');
                    hold on
                end       
            end
        end

        gap=l/n;
        x1=0:gap:l; % values at which divisions are to be done in the deployment area
        y1=0:0.1:b;
        
        plot(x1(1),y1);
        hold on
        for i1=2:length(x1) 
            plot(x1(i1),y1);    
        end
        %hold off
        axis([-1 l+1 -1 b+1])       
        
    else
        %odd case
        mat_1=[mat(:,1) mat(:,2)];
        mat_2=[mat(:,3) mat(:,4)];
        mat_2=mat_2(1:(end-1),:);
        
        [r3 c3]=size(mat_1);
        [r4 c4]=size(mat_2);
        
        for a=1:r3            
            for c=1:r4
                 x=[(mat_1(a,1)) (mat_2(c,1))];
                 y=[(mat_1(a,2)) (mat_2(c,2))];                    
                 plot(x,y)
                 hold on      
            end
        end       
        
        b1=[mat_1(1,1) mat_1(r3,1)];
        d1=[mat_1(1,2) mat_1(r3,2)];
        plot(b1,d1);
        hold on
        
        b2=[mat_2(1,1) mat_2(r4,1)];
        d2=[mat_2(1,2) mat_2(r4,2)];
        plot(b2,d2);       
        
        [r1 c1]=size(p1_node);
        [r2 c2]=size(p2_node);
        
        for i1=1:r1
            for j1=1:c1
                if i1==1 
                    plot(p1_node(i1,j1),q1_node(i1,j1),'r*');
                    hold on
                else
                    plot(p1_node(i1,j1),q1_node(i1,j1),'*');
                    hold on
                end
            end
        end
    
        for i1=1:r2
            for j1=1:c2
                plot(p2_node(i1,j1),q2_node(i1,j1),'*');
                hold on
            end
        end

        gap=l/n; 
        x1=0:gap:l; % values at which divisions are to be done in the deployment area
        y1=0:0.1:b;

        plot(x1(1),y1);
        hold on
        for i1=2:length(x1) 
            plot(x1(i1),y1);    
        end
        %hold off
        axis([-1 l+1 -1 b+1])
    end      
end

title('Mesh formation')
end

Code 5 – Function M File – min_sp_tree.m

function min_sp_tree(coor,sn,n,nodesx,nodesy,l,b,p1_node,p2_node,q1_node,q2_node)

[r c]=size(coor);

figure(5)    
if mod(sn,2)==0
    % even sn case
    for i=1:(2*n)
        x=[coor(1,((2*i)-1)) coor(r,((2*i)-1))];
        y=[coor(1,(2*i)) coor(r,(2*i))];
        
        plot(x,y) %vertical lines
        hold on
    end

    for i=1:((2*n)-1)                
        if mod(i,2)==0                        
            m1=[coor(r,((2*i)-1)) coor(r,((2*i)+1))];
            n1=[coor(r,(2*i)) coor(r,((2*i)+2))];
            plot(m1,n1) %horizontal lines
            hold on
        else           
            m1=[coor(1,((2*i)-1)) coor(1,((2*i)+1))];
            n1=[coor(1,(2*i)) coor(1,((2*i)+2))];
            plot(m1,n1) %horizontal lines
            hold on 
        end
    end   
    
    [r1 c1]=size(nodesx);
    for i=1:r1
        for j=1:c1
            if i==1 && rem(j,2)==1
                plot(nodesx(i,j),nodesy(i,j),'r*');
                hold on
            else
                plot(nodesx(i,j),nodesy(i,j),'*');
                hold on
            end       
        end
    end

    gap=l/n; 
    x1=0:gap:l; % values at which divisions are to be done in the deployment area
    y1=0:0.1:b;

    plot(x1(1),y1);
    hold on
    for i=2:length(x1) 
        plot(x1(i),y1);    
    end
    hold off
    axis([-1 l+1 -1 b+1])

else
    % odd sn case
    for i=1:n
        x=[coor(1,((4*i)-1)) coor((r-1),((4*i)-1))];
        y=[coor(1,(4*i)) coor((r-1),(4*i))];
        
        plot(x,y) %vertical lines short
        hold on
    end
    
    for i=1:n
        x=[coor(1,((4*i)-3)) coor(r,((4*i)-3))];
        y=[coor(1,((4*i)-2)) coor(r,((4*i)-2))];
        
        plot(x,y) %vertical lines long
        hold on
    end
    
    for i=1:((2*n)-1)                
        if mod(i,2)==0                        
            m1=[coor((r-1),((2*i)-1)) coor((r-1),((2*i)+1))];
            n1=[coor((r-1),(2*i)) coor((r-1),((2*i)+2))];
            plot(m1,n1) %horizontal lines
            hold on
        else           
            m1=[coor(1,((2*i)-1)) coor(1,((2*i)+1))];
            n1=[coor(1,(2*i)) coor(1,((2*i)+2))];
            plot(m1,n1) %horizontal lines
            hold on 
        end
    end   
    
    [r1 c1]=size(p1_node);
    [r2 c2]=size(p2_node);
        
    for i1=1:r1
        for j1=1:c1
            if i1==1 
                plot(p1_node(i1,j1),q1_node(i1,j1),'r*');
                hold on
            else
                plot(p1_node(i1,j1),q1_node(i1,j1),'*');
                hold on
            end
        end
    end
    
    for i1=1:r2
        for j1=1:c2
            plot(p2_node(i1,j1),q2_node(i1,j1),'*');
            hold on
        end
    end
    gap=l/n; 
    x1=0:gap:l; % values at which divisions are to be done in the deployment area
    y1=0:0.1:b;

    plot(x1(1),y1);
    hold on
    for i1=2:length(x1) 
        plot(x1(i1),y1);    
    end
    %hold off
    axis([-1 l+1 -1 b+1])
    
end

title('Minimum spanning tree')
end

Code 6 – Function M File – sensor_placement.m

function sensor_placement(nodesx,nodesy,l,b,n)

[r c]=size(nodesx);
%figure(3)
for i=1:r
    for j=1:c
        if i==1 && rem(j,2)==1
            plot(nodesx(i,j),nodesy(i,j),'r*');
            hold on
        else
            plot(nodesx(i,j),nodesy(i,j),'*');
            hold on
        end       
    end
end

gap=l/n;
x=0:gap:l; % values at which divisions are to be done in the deployment area
y=0:0.1:b;

%figure(2)
plot(x(1),y);
hold on
for i=2:length(x) 
    plot(x(i),y);    
end
%hold off
axis([-1 l+1 -1 b+1])

hold off
title('Sensor node numbers from left to right ')
end

Code 6 – Function M File – sensor_placement.m

function sensor_placement(nodesx,nodesy,l,b,n)

[r c]=size(nodesx);
%figure(3)
for i=1:r
    for j=1:c
        if i==1 && rem(j,2)==1
            plot(nodesx(i,j),nodesy(i,j),'r*');
            hold on
        else
            plot(nodesx(i,j),nodesy(i,j),'*');
            hold on
        end       
    end
end

gap=l/n;
x=0:gap:l; % values at which divisions are to be done in the deployment area
y=0:0.1:b;

%figure(2)
plot(x(1),y);
hold on
for i=2:length(x) 
    plot(x(i),y);    
end
%hold off
axis([-1 l+1 -1 b+1])

hold off
title('Sensor node numbers from left to right ')
end

Code 7 – Function M File – sensor_random.m

function [nodesx,nodesy]=sensor_random(x,b)

n=length(x);
sn=input('Enter the number of sensor nodes in one zone: ');

nodesx=[];
for i=1:n-1
    node=[];
    for j=1:sn        
        low=x(i);
        high=x(i+1);    
        node=[node (low+(high-low)*rand)]; 
    end
    nodesx(i,:)=node;
end
%nodesx

clear i j
nodesy=[];
for i=1:n-1
    for j=1:sn        
        nodesy(i,j)=randi([0,b]);
        %pause
    end
end

end

Code 8 – Function M File – energy.m 

function [node_energies,x]=energy(sn,n,id1,id2,z1,z2,sennum1,sennum2)

[num,txt,raw]=xlsread('Energies at each node');
[row col]=size(num);
blank_mat=[];
for i=1:row
    blank_mat(i,:)= zeros(1,col);
end
xlswrite('Energies at each node',blank_mat,1,'B3')

N=sn*n;
s1=(z1*100)+1;
s2=(z2*100)+1;
nums=[];

% from source node to zone scatter node
if mod(sennum1,2)==0
    num1=(id1-1-s1)/2;    
    num1=num1+1;
else
    num1=(id1-s1)/2;    
end

i=1;
nums(i)=id1;
if mod(id1,2)==0
    i=i+1;
    nums(i)=id1-1;
    x=nums(i)-((z1*100)+1);
    for a=1:(x/2)
        i=i+1;
        nums(i)=nums(i-1)-2;
    end
elseif rem(id1,2)==1
    x=nums(i)-((z1*100)+1);
    for a=1:(x/2)
        i=i+1;
        nums(i)=nums(i-1)-2;
    end
end

%from zone scatter node to destination scatter node
if s1<s2
    num2=((s2-s1)/100)*2;
else
    num2=((s1-s2)/100)*2;
end

if s1<s2
    %go on right side
    x=(s2-s1)/100;
    for a=1:x    
        i=i+1;
        nums(i)=nums(i-1)+1;
        i=i+1;
        nums(i)=nums(i-2)+100;
    end    
elseif s1>s2
    %go on left side
    x=(s1-s2)/100;
    for a=1:x
        i=i+1;
        nums(i)=nums(i-1)-99;
        i=i+1;
        nums(i)=nums(i-1)-1;
    end    
end
    
%from destination scatter to destination node
if mod(sennum2,2)==0
    num3=(id2-1-s2)/2;    
    num3=num3+1;
else
    num3=(id2-s2)/2;    
end

if mod(id2,2)==0
    x=id2-((z2*100)+1);    
    for a=1:(x/2)
        i=i+1;
        nums(i)=nums(i-1)+2;
    end   
    i=i+1;
    nums(i)=nums(i-1)+1;    
elseif rem(id2,2)==1
    x=id2-((z2*100)+1);    
    for a=1:(x/2)
        i=i+1;
        nums(i)=nums(i-1)+2;
    end   
end

% final count
num=num1+num2+num3;
x=(num/N)*100;

disp('Percentage of energy lost: ')
disp(x)

len1=length(nums);
dec=100/N;

E=[100];
for j=1:len1-1
    E=[E (100-(j*dec))];
end

len2=length(E);

nums=nums';
E=E';
node_energies=[nums E];
xlswrite('Energies at each node',node_energies,1,'B3')

end

Code 9 – Function M File – divide.m  

function x=divide(l,b,n)

gap=l/n; 
x=0:gap:l; % values at which divisions are to be done in the deployment area
y=0:0.1:b;

figure(2)
plot(x(1),y);
hold on
for i=2:length(x) 
    plot(x(i),y);    
end
hold off
axis([-1 l+1 -1 b+1])

title('Divided deployment area')

end

Code 10 – Function M File – dep_area.m

function area=dep_area(l,b)

figure(1)
axis([0 l 0 b]); 
xlabel('length')
ylabel('breadth')
title('Deployment Area')

disp('The deployment area is: ')
area=l*b;
disp(area)

end

Code 11 – Function M File – dec2.m

function dec2(X,b,l,n,sn,z1,coor,sennum1,abc1,z2,nodesx,nodesy,p1_node,p2_node,q1_node,q2_node,abc2)
figure(13)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
s_scatter=[coor(1,((4*z1)-3)) coor(1,((4*z1)-2))];
%d_scatter=[coor(1,((4*z2)-3)) coor(1,((4*z2)-2))];
if mod(n,0)==0
    if z1<=(n/2)
        i=n;
    elseif z1>(n/2)
        i=1;
    end
else
    if z1<=ceil(n/2)
        i=n;
    elseif z1>ceil(n/2)
        i=1;
    end
end
        
d_scatter=[coor(1,((4*i)-3)) coor(1,((4*i)-2))];    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plotting the sensors

if mod(sn,2)==0
    % even number in one zone
    [r c]=size(nodesx);
        
    for i1=1:r
        for j1=1:c
            if i1==1 && rem(j1,2)==1
                plot(nodesx(i1,j1),nodesy(i1,j1),'r*');
                hold on
            else
                plot(nodesx(i1,j1),nodesy(i1,j1),'*');
                hold on
            end       
        end
     end

    gap=l/n;
    x1=0:gap:l; % values at which divisions are to be done in the deployment area
    y1=0:0.1:b;
       
    plot(x1(1),y1);
    hold on
    for i1=2:length(x1) 
        plot(x1(i1),y1);    
    end
    %hold off
    %axis([-1 l+1 -1 b+1])       
    text(abc1(1)+0.05,abc1(2),'\leftarrow Sender')
%    text(abc2(1)+0.5,abc2(2),'\leftarrow Receiver')
else
    % odd number on one zone
    [r1 c1]=size(p1_node);
    [r2 c2]=size(p2_node);
        
    for i1=1:r1
        for j1=1:c1
            if i1==1
                plot(p1_node(i1,j1),q1_node(i1,j1),'r*');
                hold on
            else
                plot(p1_node(i1,j1),q1_node(i1,j1),'*');
                hold on
            end
        end
    end
    
    for i1=1:r2
        for j1=1:c2
            plot(p2_node(i1,j1),q2_node(i1,j1),'*');
            hold on
        end
    end

    gap=l/n; 
    x1=0:gap:l; % values at which divisions are to be done in the deployment area
    y1=0:0.1:b;

    plot(x1(1),y1);
    hold on
    for i1=2:length(x1) 
        plot(x1(i1),y1);    
    end
    %hold off
    %axis([-1 l+1 -1 b+1])
    text(abc1(1)+0.05,abc1(2),'\leftarrow Sender')
%    text(abc2(1)+0.5,abc2(2),'\leftarrow Receiver')
end
%plotting the sensors complete
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% input node to source scatter node
if mod(sennum1,2)==0
    x1=[abc1(1) (abc1(1)-((X(2)-X(1))/2))];
    y1=[abc1(2) abc1(2)];    
    for a=1:5        
        abc=plot(x1,y1,'r','LineWidth',2);        
        pause(0.3)       
        delete(abc)
        pause(0.3)
        abc=plot(x1,y1,'r','LineWidth',2);        
    end   
    hold on    
    
    x=[(abc1(1)-((X(2)-X(1))/2)) s_scatter(1)];
    y=[abc1(2) s_scatter(2)];
    for a=1:5
        abc=plot(x,y,'r','LineWidth',2);                
        pause(0.3)       
        delete(abc)
        pause(0.3)
        abc=plot(x,y,'r','LineWidth',2);        
    end   
    hold on        
elseif rem(sennum1,2)==1
    x=[abc1(1) s_scatter(1)];
    y=[abc1(2) s_scatter(2)];
    for a=1:5        
        abc=plot(x,y,'r','LineWidth',2);
        pause(0.3)
        delete(abc)
        pause(0.3)
        abc=plot(x,y,'r','LineWidth',2);        
    end   
    hold on    
end

pause(0.3)
plot(s_scatter(1),s_scatter(2),'g*','LineWidth',5) %marking the source scatter node
pause(0.3)
%i/p node to source scatter node complete
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%from source scatter to all the other scatters
scatter=[];
for i=1:n
    scatter(i,:)=[coor(1,((4*i)-3)) coor(1,((4*i)-2))];
end
clear r c x1 y1 x2 y2 x3 y3
[r c]=size(scatter);

%finding the position of "s_scatter" in "scatter"
[row1 col1]=find(scatter==s_scatter(1)); %rows and cols number for the "s_scatter" values in "scatter" matrix
[row2 col2]=find(scatter==d_scatter(1)); %rows and cols number for the "d_scatter" values in "scatter" matrix

order=[];
for i=1:2*r    
    if s_scatter==d_scatter
        break;
    end
    num=ceil(i/2);    
    if mod(i,2)==0        
        x=row1+num;        
        if x==row2
            order=[order x];            
            break;
        end
        if x>r || x<1
            continue;
        else
            order=[order x];            
        end
    else
        x=row1-num;        
        if x==row2
            order=[order x];            
            break;
        end
        if x>r || x<1
            continue;
        else
            order=[order x];            
        end
    end    
end

m1=s_scatter;
m2=s_scatter;
for i=1:length(order)
%     if s_scatter==d_scatter
%         break;
%     end
    
    if order(i)>z1
        start_node=m1;
    else
        start_node=m2;
    end        
    
    x1=[start_node(1) start_node(1)];
    y1=[start_node(2) (start_node(2)+i)];          
    if i==1 || i==2
        if order(i)~=1 || order(i)~=n
            plot(x1,y1)
        end
    else            
        for a=1:5
            abc=plot(x1,y1);               
            pause(0.1)
            delete(abc)
            pause(0.1)
            abc=plot(x1,y1);        
        end          
    end

    
    x=scatter(order(i),:); %%%%%%%%%%%%%%%
    x2=[start_node(1) x(1)];
    y2=[(start_node(2)+i) (x(2)+i)];    
     if i==1 || i==2
        if order(i)~=1 || order(i)~=n
            plot(x2,y2)
        end
    else
        for a=1:5
            abc=plot(x2,y2);               
            pause(0.1)
            delete(abc)
            pause(0.1)
            abc=plot(x2,y2);        
        end           
    end

    
    x3=[x(1) x(1)];
    y3=[x(2) (x(2)+i)];    
    if i==1 || i==2
        if order(i)~=1 || order(i)~=n
            plot(x3,y3)
        end
    else
        for a=1:5
            abc=plot(x3,y3);               
            pause(0.1)
            delete(abc)
            pause(0.1)
            abc=plot(x3,y3);        
        end   
    end
    
    if order(i)>z1
        m1=[x(1) x(2)];
    else
        m2=[x(1) x(2)];
    end    
    
    if i==2
        pause(0.5)
    end

end                
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[nodesx,nodesy,p1_node,p2_node,q1_node,q2_node]=sensor_uniform2(X,b,l,n,sn);
    %s_scatter=[coor(1,((4*z1)-3)) coor(1,((4*z1)-2))];
    if isempty(m1)
        s_scatter=m2;
    else 
        s_scatter=m1;
    end
    hold on
    if isempty(nodesx) && isempty(nodesy)
        rectangle('Position',[p1_node(1,1),(q1_node(1,1)+5),4,3],'Facecolor','y')
        text(p1_node(1,1)+1,(q1_node(1,1)+5)+1,'BASE')
%         if mod(sennum1,2)==0
%             x1=[abc1(1) (abc1(1)-((X(2)-X(1))/2))];
%             y1=[abc1(2) abc1(2)];    
%             for a=1:5        
%                 abc=plot(x1,y1,'r','LineWidth',2);        
%                 pause(0.3)       
%                 delete(abc)
%                 pause(0.3)
%                 abc=plot(x1,y1,'r','LineWidth',2);        
%             end   
%             hold on    
%     
%             x=[(abc1(1)-((X(2)-X(1))/2)) s_scatter(1)];
%             y=[abc1(2) s_scatter(2)];
%             for a=1:5
%                 abc=plot(x,y,'r','LineWidth',2);                
%                 pause(0.3)       
%                 delete(abc)
%                 pause(0.3)
%                 abc=plot(x,y,'r','LineWidth',2);        
%             end   
%             hold on        
%         elseif rem(sennum1,2)==1
%             x=[abc1(1) s_scatter(1)];
%             y=[abc1(2) s_scatter(2)];
%             for a=1:5        
%                 abc=plot(x,y,'r','LineWidth',2);
%                 pause(0.3)
%                 delete(abc)
%                 pause(0.3)
%                 abc=plot(x,y,'r','LineWidth',2);        
%             end   
%             hold on    
%         end

        pause(0.3)
        plot(d_scatter(1),d_scatter(2),'g*','LineWidth',5) %marking the source scatter node
        pause(0.3)       
        
        coor2=[((p1_node(1,1))) (q1_node(1,1)+5)];
        blinking_line(d_scatter,coor2)       
        plot([d_scatter(1) coor2(1)],[d_scatter(2) coor2(2)],'r','LineWidth',2)
        
        coor1=[((p1_node(1,1))+5) (q1_node(1,1)+5)];
        blinking_line(coor1,coor2)
        plot([coor1(1) coor2(1)],[coor1(2) coor2(2)],'r','LineWidth',2)
        plot(((p1_node(1,1))+5),(q1_node(1,1)+5),'g*','LineWidth',5)       
        
    elseif isempty(p1_node) && isempty(p2_node) && isempty(q1_node) && isempty(q2_node)
        rectangle('Position',[nodesx(1,1),(nodesy(1,1)+5),4,3],'Facecolor','y')
        text(nodesx(1,1)+1,(nodesy(1,1)+5)+1,'BASE')
%         if mod(sennum1,2)==0
%             x1=[abc1(1) (abc1(1)-((X(2)-X(1))/2))];
%             y1=[abc1(2) abc1(2)];    
%             for a=1:5        
%                 abc=plot(x1,y1,'r','LineWidth',2);        
%                 pause(0.3)       
%                 delete(abc)
%                 pause(0.3)
%                 abc=plot(x1,y1,'r','LineWidth',2);        
%             end   
%             hold on    
%     
%             x=[(abc1(1)-((X(2)-X(1))/2)) s_scatter(1)];
%             y=[abc1(2) s_scatter(2)];
%             for a=1:5
%                 abc=plot(x,y,'r','LineWidth',2);                
%                 pause(0.3)       
%                 delete(abc)
%                 pause(0.3)
%                 abc=plot(x,y,'r','LineWidth',2);        
%             end   
%             hold on        
%         elseif rem(sennum1,2)==1
%             x=[abc1(1) s_scatter(1)];
%             y=[abc1(2) s_scatter(2)];
%             for a=1:5        
%                 abc=plot(x,y,'r','LineWidth',2);
%                 pause(0.3)
%                 delete(abc)
%                 pause(0.3)
%                 abc=plot(x,y,'r','LineWidth',2);        
%             end   
%             hold on    
%         end

        pause(0.3)
        plot(d_scatter(1),d_scatter(2),'g*','LineWidth',5) %marking the source scatter node
        pause(0.3)       
        
        coor2=[((nodesx(1,1))) (nodesy(1,1)+5)];
        blinking_line(d_scatter,coor2)       
        plot([d_scatter(1) coor2(1)],[d_scatter(2) coor2(2)],'r','LineWidth',2)
        
        coor1=[((nodesx(1,1))+5) (nodesy(1,1)+5)];
        blinking_line(coor1,coor2)
        plot([coor1(1) coor2(1)],[coor1(2) coor2(2)],'r','LineWidth',2)
        plot(((nodesx(1,1))+5),(nodesy(1,1)+5),'g*','LineWidth',5)                       
    end
    
end

Code 11 – Function M File – dec1.m

function dec1(X,b,l,n,sn,z2,coor,sennum2,abc2,abc1)

figure(13)

    [nodesx,nodesy,p1_node,p2_node,q1_node,q2_node]=sensor_uniform2(X,b,l,n,sn);
    %text(abc1(1)+0.5,abc1(2),'\leftarrow Sender')
    text(abc2(1)+0.05,abc2(2),'\leftarrow Receiver')
    hold on
    if isempty(nodesx) && isempty(nodesy)                
        rectangle('Position',[p1_node(1,1),(q1_node(1,1)+5),4,3],'Facecolor','y')
        text(p1_node(1,1)+1,(q1_node(1,1)+5)+1,'BASE')
        
        plot(((p1_node(1,1))+5),(q1_node(1,1)+5),'g*','LineWidth',5)
        text(((p1_node(1,1))+5)+0.05,(q1_node(1,1)+5),'\leftarrow Sender')
        coor1=[(p1_node(1,1)) (q1_node(1,1)+5)]; %base point
        coor2=[((p1_node(1,1))+5) (q1_node(1,1)+5)];
        blinking_line(coor1,coor2)
        plot([coor1(1) coor2(1)],[coor1(2) coor2(2)],'r','LineWidth',2)
        
        scatter=[];
        for i=1:n
            scatter(i,:)=[coor(1,((4*i)-3)) coor(1,((4*i)-2))];
            plot([coor1(1) scatter(i,1)],[coor1(2) scatter(i,2)])
        end
        pause(0.3)        
        
        d_scatter=[coor(1,((4*z2)-3)) coor(1,((4*z2)-2))];
        blinking_line(coor1,d_scatter)        
        plot([d_scatter(1) coor1(1)],[d_scatter(2) coor1(2)],'r','LineWidth',2)
        plot(d_scatter(1),d_scatter(2),'g*','LineWidth',5)

        if mod(sennum2,2)==0
           %right syd
            x=[d_scatter(1) d_scatter(1)];
            y=[d_scatter(2) abc2(2)];
            for a=1:5
                abc=plot(x,y,'r','LineWidth',2);        
                pause(0.3)
                delete(abc)
                pause(0.3)
                abc=plot(x,y,'r','LineWidth',2);        
            end
    
            x=[d_scatter(1) abc2(1)];
            y=[abc2(2) abc2(2)];
            for a=1:5
                abc=plot(x,y,'r','LineWidth',2);        
                pause(0.3)
                delete(abc)        
                pause(0.3)
                abc=plot(x,y,'r','LineWidth',2);        
            end   
        elseif rem(sennum2,2)==1
            %left syd
            x=[d_scatter(1) abc2(1)];
            y=[d_scatter(2) abc2(2)];
            for a=1:5
                abc=plot(x,y,'r','LineWidth',2);        
                pause(0.3)
                delete(abc)
                pause(0.3)
                abc=plot(x,y,'r','LineWidth',2);        
            end
        end         
    elseif isempty(p1_node) && isempty(p2_node) && isempty(q1_node) && isempty(q2_node)
        rectangle('Position',[nodesx(1,1),(nodesy(1,1)+5),4,3],'Facecolor','y')
        text(nodesx(1,1)+1,(nodesy(1,1)+5)+1,'BASE')
        
        plot(((nodesx(1,1))+5),(nodesy(1,1)+5),'g*','LineWidth',5)
        text(((nodesx(1,1))+5)+0.05,(nodesy(1,1)+5),'\leftarrow Sender')
        coor1=[(nodesx(1,1)) (nodesy(1,1)+5)];
        coor2=[((nodesx(1,1))+5) (nodesy(1,1)+5)];
        blinking_line(coor1,coor2)
        plot([coor1(1) coor2(1)],[coor1(2) coor2(2)],'r','LineWidth',2)
        
        scatter=[];
        for i=1:n
            scatter(i,:)=[coor(1,((4*i)-3)) coor(1,((4*i)-2))];
            plot([coor1(1) scatter(i,1)],[coor1(2) scatter(i,2)])
        end
        pause(0.3)        
        
        d_scatter=[coor(1,((4*z2)-3)) coor(1,((4*z2)-2))];
        blinking_line(coor1,d_scatter)
        plot([coor1(1) d_scatter(1)],[coor1(2) d_scatter(2)],'r','LineWidth',2)
        plot(d_scatter(1),d_scatter(2),'g*','LineWidth',5)
        if mod(sennum2,2)==0
           %right syd
            x=[d_scatter(1) d_scatter(1)];
            y=[d_scatter(2) abc2(2)];
            for a=1:5
                abc=plot(x,y,'r','LineWidth',2);        
                pause(0.3)
                delete(abc)
                pause(0.3)
                abc=plot(x,y,'r','LineWidth',2);        
            end
    
            x=[d_scatter(1) abc2(1)];
            y=[abc2(2) abc2(2)];
            for a=1:5
                abc=plot(x,y,'r','LineWidth',2);        
                pause(0.3)
                delete(abc)        
                pause(0.3)
                abc=plot(x,y,'r','LineWidth',2);        
            end   
        elseif rem(sennum2,2)==1
            %left syd
            x=[d_scatter(1) abc2(1)];
            y=[d_scatter(2) abc2(2)];
            for a=1:5
                abc=plot(x,y,'r','LineWidth',2);        
                pause(0.3)
                delete(abc)
                pause(0.3)
                abc=plot(x,y,'r','LineWidth',2);        
            end
        end      
    end  
    
end

Code 12 – Function M File – curvefit.m

function p_x=curvefit(X,Y,deg)

Code 13 – Function M File – coordinates.m

function coor=coordinates(nodesx,nodesy,p1_node,p2_node,q1_node,q2_node,sn,n)
%[r1 c1]=size(p1_node)
% p2_node
% q1_node
% q2_node

[num,txt,raw]=xlsread('coordinates');
[row col]=size(num);
blank_mat=[];
for i=1:row
    blank_mat(i,:)= zeros(1,col);
end
xlswrite('coordinates',blank_mat,1,'C5')

coor=[];
if mod(sn,2)==0
    [r c]=size(nodesx);
    a=1;
    for i=1:c
        i;
        a;
        coor(:,(2*i)-1)=nodesx(:,a);
        coor(:,(2*i))=nodesy(:,a);
        a=a+1;        
    end
else
    [r c]=size(p1_node);
    %for i=1:r
        a=1;
        for j=1:(4*c)
            if rem(j,4)==1
                coor(:,j)=p1_node(:,a);                
            elseif rem(j,4)==2
                coor(:,j)=q1_node(:,a);                
            elseif rem(j,4)==3
                coor(:,j)=[p2_node(:,a)' 0]';                
            elseif mod(j,4)==0
                coor(:,j)=[q2_node(:,a)' 0]';                
            end           
            
            if mod(j,4)==0
                a=a+1;                
            end        
            %pause
        end
    %end
end
xlswrite('coordinates',coor,1,'C5');
end

Code 14 – Function M File – blinking_line.m

function blinking_line(coor1,coor2)

for i=1:3   
        abc=plot([coor1(1) coor2(1)],[coor1(2) coor2(2)]);
        pause(0.3)
        delete(abc)
        pause(0.3)
        abc=plot([coor1(1) coor2(1)],[coor1(2) coor2(2)]);
        pause(0.3)
        delete(abc)
        pause(0.3)
%        abc=plot([coor1(1) coor2(1)],[coor1(2) coor2(2)]);
end
    
end

Code 15 – Function M File – src_des.m

function [abc1,abc2,z1,z2,sennum1,sennum2,id1,id2]=src_des(coor,X,nodesx,nodesy,l,b,p1_node,p2_node,q1_node,q2_node,sn,n)

%figure(13)       
%axis([0 l+3 0 b+5])

disp('Input the source sensor node (refering the excel file): ')
disp('Press enter to continue...')
pause
[abc1,z1,sennum1,id1]=sensorinfo(coor,n,sn);
disp('Input the destination sensor node (refering the excel file): ')
disp('Press enter to continue...')
pause
[abc2,z2,sennum2,id2]=sensorinfo(coor,n,sn);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
while z1>n && z2>n
    disp('Both the sensors are out of bounds!')
    disp('Enter again')
    
    disp('Input the source sensor node (refering the excel file): ')
    disp('Press enter to continue...')
    pause
    [abc1,z1,sennum1,id1]=sensorinfo(coor,n,sn);
    disp('Input the destination sensor node (refering the excel file): ')
    disp('Press enter to continue...')
    pause
    [abc2,z2,sennum2,id2]=sensorinfo(coor,n,sn);  
    %disp('Program terminates!')    
end

if z1>n    
    dec1(X,b,l,n,sn,z2,coor,sennum2,abc2,abc1) % for an external source node
elseif z2>n
    dec2(X,b,l,n,sn,z1,coor,sennum1,abc1,z2,nodesx,nodesy,p1_node,p2_node,q1_node,q2_node,abc2) % for an external destination node
else
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%both are in the boundary
disp('Press enter to continue...')
pause

disp('The source sensor node coordinates are: ')
disp(abc1)

disp('The source sensor node coordinates are: ')
disp(abc2)

s_scatter=[coor(1,((4*z1)-3)) coor(1,((4*z1)-2))];
d_scatter=[coor(1,((4*z2)-3)) coor(1,((4*z2)-2))];
gap=X(2)-X(1);

figure(6)
if mod(sn,2)==0
    % even number in one zone
    [r c]=size(nodesx);
        
    for i1=1:r
        for j1=1:c
            if i1==1 && rem(j1,2)==1
                plot(nodesx(i1,j1),nodesy(i1,j1),'r*');
                hold on
            else
                plot(nodesx(i1,j1),nodesy(i1,j1),'*');
                hold on
            end       
        end
     end

    gap=l/n;
    x1=0:gap:l; % values at which divisions are to be done in the deployment area
    y1=0:0.1:b;
       
    plot(x1(1),y1);
    hold on
    for i1=2:length(x1) 
        plot(x1(i1),y1);    
    end
    %hold off
    %axis([-1 l+1 -1 b+1])       
    text(abc1(1)+0.05,abc1(2),'\leftarrow Sender')
    text(abc2(1)+0.05,abc2(2),'\leftarrow Receiver')
else
    % odd number on one zone
    [r1 c1]=size(p1_node);
    [r2 c2]=size(p2_node);
        
    for i1=1:r1
        for j1=1:c1
            if i1==1
                plot(p1_node(i1,j1),q1_node(i1,j1),'r*');
                hold on
            else
                plot(p1_node(i1,j1),q1_node(i1,j1),'*');
                hold on
            end
        end
    end
    
    for i1=1:r2
        for j1=1:c2
            plot(p2_node(i1,j1),q2_node(i1,j1),'*');
            hold on
        end
    end

    gap=l/n; 
    x1=0:gap:l; % values at which divisions are to be done in the deployment area
    y1=0:0.1:b;

    plot(x1(1),y1);
    hold on
    for i1=2:length(x1) 
        plot(x1(i1),y1);    
    end
    %hold off
    %axis([-1 l+1 -1 b+1])
    text(abc1(1)+0.05,abc1(2),'\leftarrow Sender')
    text(abc2(1)+0.05,abc2(2),'\leftarrow Receiver')
end

% input node to source scatter node
if mod(sennum1,2)==0
    x1=[abc1(1) (abc1(1)-((X(2)-X(1))/2))];
    y1=[abc1(2) abc1(2)];    
    for a=1:5        
        abc=plot(x1,y1,'r','LineWidth',2);        
        pause(0.3)       
        delete(abc)
        pause(0.3)
        abc=plot(x1,y1,'r','LineWidth',2);        
    end   
    hold on    
    
    x=[(abc1(1)-((X(2)-X(1))/2)) s_scatter(1)];
    y=[abc1(2) s_scatter(2)];
    for a=1:5
        abc=plot(x,y,'r','LineWidth',2);                
        pause(0.3)       
        delete(abc)
        pause(0.3)
        abc=plot(x,y,'r','LineWidth',2);        
    end   
    hold on        
elseif rem(sennum1,2)==1
    x=[abc1(1) s_scatter(1)];
    y=[abc1(2) s_scatter(2)];
    for a=1:5        
        abc=plot(x,y,'r','LineWidth',2);
        pause(0.3)
        delete(abc)
        pause(0.3)
        abc=plot(x,y,'r','LineWidth',2);        
    end   
    hold on    
end

pause(0.3)
plot(s_scatter(1),s_scatter(2),'g*','LineWidth',5) %marking the source scatter node
pause(0.3)

%source scatter node to all the other scatter nodes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
scatter=[];
for i=1:n
    scatter(i,:)=[coor(1,((4*i)-3)) coor(1,((4*i)-2))];
end
clear r c x1 y1 x2 y2 x3 y3
[r c]=size(scatter);

%finding the position of "s_scatter" in "scatter"
[row1 col1]=find(scatter==s_scatter(1)); %rows and cols number for the "s_scatter" values in "scatter" matrix
[row2 col2]=find(scatter==d_scatter(1)); %rows and cols number for the "d_scatter" values in "scatter" matrix

order=[];
for i=1:2*r    
    if s_scatter==d_scatter
        break;
    end
    num=ceil(i/2);    
    if mod(i,2)==0        
        x=row1+num;        
        if x==row2
            order=[order x];            
            break;
        end
        if x>r || x<1
            continue;
        else
            order=[order x];            
        end
    else
        x=row1-num;        
        if x==row2
            order=[order x];            
            break;
        end
        if x>r || x<1
            continue;
        else
            order=[order x];            
        end
    end    
end

m1=s_scatter;
m2=s_scatter;
for i=1:length(order)
    if s_scatter==d_scatter
        break;
    end
    
    if order(i)>z1
        start_node=m1;
    else
        start_node=m2;
    end        
    
    x1=[start_node(1) start_node(1)];
    y1=[start_node(2) (start_node(2)+i)];          
    if i==1 || i==2
        if order(i)~=1 || order(i)~=n
            plot(x1,y1)
        end
    else            
        for a=1:5
            abc=plot(x1,y1);               
            pause(0.1)
            delete(abc)
            pause(0.1)
            abc=plot(x1,y1);        
        end          
    end
    
    x=scatter(order(i),:); %%%%%%%%%%%%%%%
    x2=[start_node(1) x(1)];
    y2=[(start_node(2)+i) (x(2)+i)];    
    if i==1 || i==2
        if order(i)~=1 || order(i)~=n
            plot(x2,y2)
        end
    else
        for a=1:5
            abc=plot(x2,y2);               
            pause(0.1)
            delete(abc)
            pause(0.1)
            abc=plot(x2,y2);        
        end           
    end
    
    x3=[x(1) x(1)];
    y3=[x(2) (x(2)+i)];    
    if i==1 || i==2
        if order(i)~=1 || order(i)~=n
            plot(x3,y3)
        end
    else
        for a=1:5
            abc=plot(x3,y3);               
            pause(0.1)
            delete(abc)
            pause(0.1)
            abc=plot(x3,y3);        
        end   
    end
    
    if order(i)>z1
        m1=[x(1) x(2)];
    else
        m2=[x(1) x(2)];
    end
    
    if i==2
        pause(0.5)
    end
    
end                
    
%source scatter node to destination scatter node
pause(0.3)
plot(d_scatter(1),d_scatter(2),'g*','LineWidth',5) %marking the destination scatter node
pause(0.3)

x=[s_scatter(1) d_scatter(1)];
y=[s_scatter(2) d_scatter(2)];
for a=1:5
    abc=plot(x,y,'r','LineWidth',2);    
    pause(0.3)
    delete(abc)
    pause(0.3)
    abc=plot(x,y,'r','LineWidth',2);    
end   

%destination scatter to destination node
if mod(sennum2,2)==0
    %right syd
    x=[d_scatter(1) d_scatter(1)];
    y=[d_scatter(2) abc2(2)];
    for a=1:5
        abc=plot(x,y,'r','LineWidth',2);        
        pause(0.3)
        delete(abc)
        pause(0.3)
        abc=plot(x,y,'r','LineWidth',2);        
    end
    
    x=[d_scatter(1) abc2(1)];
    y=[abc2(2) abc2(2)];
    for a=1:5
        abc=plot(x,y,'r','LineWidth',2);        
        pause(0.3)
        delete(abc)
        pause(0.3)
        abc=plot(x,y,'r','LineWidth',2);        
    end   
elseif rem(sennum2,2)==1
    %left syd
    x=[d_scatter(1) abc2(1)];
    y=[d_scatter(2) abc2(2)];
    for a=1:5
        abc=plot(x,y,'r','LineWidth',2);        
        pause(0.3)
        delete(abc)
        pause(0.3)
        abc=plot(x,y,'r','LineWidth',2);        
    end
end      
    
end

end

Code 16 – Function M File – sim_results.m

function sim_results

% characteristics of average delay
X=[5 10 50 100 200];
Y1=[437 380 353 320 317];
p=polyfit(X,Y1,4);

disp('Calculating the delay')
disp('Press enter to continue: ')
pause
x1=input('Enter the Packet generation interval(ms): ');
final_p_x1=[];
for ii=1:x1
    p_x=0;
    for i=0:length(p)-1
        p_x=p_x + (ii^i)*(p(length(p)-i));
    end
    final_p_x1=[final_p_x1 p_x];
end

figure(9)
plot([1:x1],final_p_x1)
hleg=legend('Delay');
title('Charcteristics of average delay')
xlabel('Packet generation interval(ms)')
ylabel('Delay(ms)')

disp('Delay(ms): ')
disp(p_x)
disp('Press enter to continue: ')
pause
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
clear Y p x p_x i

% throughput characteristics
Y2=[1250 1320 670 410 230];
p=polyfit(X,Y2,4);

disp('Calculating the Throughput')
disp('Press enter to continue: ')
pause
x2=input('Enter the Packet generation interval(ms): ');
final_p_x2=[];
for ii=1:x2
    p_x=0;
    for i=0:length(p)-1
        p_x=p_x + (ii^i)*(p(length(p)-i));
    end
    final_p_x2=[final_p_x2 p_x];
end

figure(10)
plot(1:x2,final_p_x2)
hleg=legend('Throughput');
title('Throughput Characteristics')
xlabel('Packet generation interval(ms)')
ylabel('Throughput(kbps)')

disp('Throughput(kbps): ')
disp(p_x)
disp('Press enter to continue: ')
pause
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
clear Y p x p_x i

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% throughput and packet delivery ratio
Y3=[];
low=85;
high=95;
x=(low+(high-low)*rand);
for i=1:length(final_p_x2)
    Y3=[Y3 ((x*final_p_x2(i))/100)];
end

%p=polyfit(X,Y3,4);

figure(11)
plot(1:x2,final_p_x2,'r')
hold on
plot(1:x2,Y3)
hleg=legend('Throughput','Packet Delivery Ratio');
title('Throughput(red) and Packet Delivery Ratio(blue)')
xlabel('Packet generation interval(ms)')
ylabel('Throughput(kbps) and Packet delivery ratio')
hold off
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% overhead
clear X Y p x p_x i
X=[1 2 3 4 5]; %zone radius
Y1=[0 35000 150000 360000 620000]; %IARP overhead (theory)
Y2=[475000 210000 750000 0 0]; %IERP overhead (theory)

Y4=[0 10000 80000 150000 210000]; %IARP overhead (practical)
Y5=[420000 360000 240000 120000 80000]; %IERP overhead (pratical)
Y6=[100000 100000 113000 116000 110000]; %NDP overhead (practical)

x3=input('Enter the Zone Radius(hops): ');
while isempty(x3)
    disp('Please enter the input')
    x3=input('Enter the Zone Radius(hops): ');
end

disp('####################    Theoritical values    ####################')
disp('Press enter to continue')
pause

p=polyfit(X,Y1,4);
final_p_x3=[];
for ii=1:x3
    p_x=0;
    for i=0:length(p)-1
        p_x=p_x + (ii^i)*(p(length(p)-i));
    end
    final_p_x3=[final_p_x3 p_x];
end

disp('IARP overhead(packets) (theoritical value): ')
disp(p_x)

p=polyfit(X,Y2,4);
final_p_x4=[];
for ii=1:x3
    p_x=0;
    for i=0:length(p)-1
        p_x=p_x + (ii^i)*(p(length(p)-i));
    end
    final_p_x4=[final_p_x4 p_x];
end
disp('IERP overhead(packets) (theoritical value): ')
disp(p_x)

Y3=final_p_x3+final_p_x4; % total overhead (theory)
disp('Total overhead (theory)')
disp(Y3(end))

disp('####################    Practical values    ####################')
disp('Press enter to continue')
pause

p=polyfit(X,Y4,4);
final_p_x5=[];
for ii=1:x3
    p_x=0;
    for i=0:length(p)-1
        p_x=p_x + (ii^i)*(p(length(p)-i));
    end
    final_p_x5=[final_p_x5 p_x];
end
disp('IARP overhead(packets) (practical value): ')
disp(p_x)

p=polyfit(X,Y5,4);
final_p_x6=[];
for ii=1:x3
    p_x=0;
    for i=0:length(p)-1
        p_x=p_x + (ii^i)*(p(length(p)-i));
    end
    final_p_x6=[final_p_x6 p_x];
end
disp('IERP overhead(packets) (practical value): ')
disp(p_x)

p=polyfit(X,Y6,4);
final_p_x7=[];
for ii=1:x3
    p_x=0;
    for i=0:length(p)-1
        p_x=p_x + (ii^i)*(p(length(p)-i));
    end
    final_p_x7=[final_p_x7 p_x];
end
disp('NDP overhead(packets) (practical value): ')
disp(p_x)

Y7=final_p_x5+final_p_x6+final_p_x7; %total overhead (practical)
disp('Total overhead')
disp(Y7(end))

disp('Press enter to continue')
pause

figure(12)
subplot(2,1,1)
plot([1:x3],final_p_x3) %iarp theory
hold on
plot([1:x3],final_p_x4,'g') %ierp theory
plot([1:x3],Y3,'r') %total theory
hleg=legend('IARP overhead','IERP overhead','Total overhead');
title('Theoretically Evaluated')
xlabel('Zone Radius(hops)')
ylabel('Overhead(packets)')
set(gca, 'YTickLabel', num2str(get(gca,'YTick')','%d')) 

subplot(2,1,2)
plot([1:x3],final_p_x5) %iarp practical
hold on
plot([1:x3],final_p_x6,'g') %ierp practical
plot([1:x3],final_p_x7,'r') %ndp practical
plot([1:x3],Y7,'y') %total practical
hleg=legend('IARP overhead','IERP overhead','NDP overhead','Total overhead');
title('Simulation')
xlabel('Zone Radius(hops)')
ylabel('Overhead(packets)')
set(gca, 'YTickLabel', num2str(get(gca,'YTick')','%d'))

Code 17 – Function M File – sensorinfo.m

function [abc,z,sennum,id]=sensorinfo(coor,n,sn)

id=input('Input the sensor id (refering the excel file): ');

while isempty(id)
    disp('Please enter a value')
    id=input('Input the sensor id (refering the excel file): ');
end

x=mod(id,100); % sensor index (number) in the current zone
sennum=x; %sensor number in the zone
y=id-x;
z=y/100; % zone number

if z<=n
    while x>sn    
        disp('Invalid sensor ID !!')
        disp('Please enter again')
        id=input('Input the sensor id (refering the excel file): ');
        x=mod(id,100); % sensor index (number) in the current zone
        sennum=x;
        y=id-x;
        z=y/100; % zone number
    end
end

if z>n % sensor is not in current zones
    disp('Out of the present zones')
    abc=0;
elseif z<=n % sensor is in current zones

    disp('The sensor is in the zone: ')
    disp(z)

    mat=[];
    xy=1;
    for i=((4*z)-3):(4*z)
        mat(:,xy)=coor(:,i);
        xy=xy+1;
    end
    %  mat
    %  pause

    mat_1=[];
    b=1;
    if mod(x,2)==0
        % fall on right side
        a=2;
        mat_1=[mat(:,3) mat(:,4)];
        [r c]=size(mat_1);
        for i=1:r
            if x==a
                disp('The coordinates of the sensor are: ')
                abc=mat_1(b,:)
                break;
            else
                b=b+1;
                a=a+2;
            end
        end
    else
        % fall on left side
        mat_1=[mat(:,1) mat(:,2)];
        a=1;
        [r c]=size(mat_1);
        for i=1:r
            if x==a
                disp('The coordinates of the sensor are: ')
                abc=mat_1(b,:)
                break;
            else
                b=b+1;
                a=a+2;
            end    
        end
    end

end

end

Code 18 – Function M File – sensor_uniform2.m

function [nodesx,nodesy,p1_node,p2_node,q1_node,q2_node]=sensor_uniform2(x,b,l,n,sn)

%n=length(x); %number of divisions + 1
%y=n-1; %number of divisions

%sn=input('Number of sensors to be deployed in one zone: ');
%h=sn;

nodesx=[];
nodesy=[];

if mod(sn,2)==0
    %even number case
    d=x(2)/4;
    p=[];
    for i=2:length(x)           
        p=[p (x(i-1)+d) (x(i-1)+(3*d))]; %x axis
    end
    
    hsn=sn/2;
    q=[];
    m=b/hsn;
    q0=m/2;    
    for j=0:(hsn-1)
        q=[q (q0+(m*j))]; %y axis
    end       
    
    for i=1:length(q)
        nodesx(i,:)=p;
    end
    
    for i=1:length(p)
        nodesy(:,i)=q;
    end       
    nodesy=flipud(nodesy);
    
    [r c]=size(nodesx);
        %figure(3)
    for i=1:r
        for j=1:c
            if i==1 && rem(j,2)==1
                plot(nodesx(i,j),nodesy(i,j),'r*');
                hold on
            else
                plot(nodesx(i,j),nodesy(i,j),'*');
                hold on
            end       
        end
    end

    gap=l/n;
    x=0:gap:l; % values at which divisions are to be done in the deployment area
    y=0:0.1:b;

    %figure(2)
    plot(x(1),y);
    hold on
    for i=2:length(x) 
        plot(x(i),y);    
    end

    p1_node=[];
    q1_node=[];
    p2_node=[];
    q2_node=[];
else
    %odd number case
    nodesx=[];
    nodesy=[];
    d=x(2)/4;
    p=[];
    for i=2:length(x)           
        p=[p (x(i-1)+d) (x(i-1)+(3*d))]; %x axis
    end
   
    p1=[];
    p2=[];
    for i=1:length(p)
        if mod(i,2)==0
            p2=[p2 p(i)];
        else
            p1=[p1 p(i)];
        end
    end   
    
    hsn=ceil(sn/2);
    q=[];
    m=b/hsn;
    q0=m/2;    
    for j=0:(hsn-1)
        q=[q (q0+(m*j))]; %y axis
    end     
    
    q1=q;
    q2=q(2:end);  
    
    p1_node=[];
    for i=1:hsn
        p1_node(i,:)=p1;
    end    
    
    p2_node=[];
    for i=1:(hsn-1)
        p2_node(i,:)=p2;
    end
        
    q1_node=[];
    for i=1:length(p1)
        q1_node(:,i)=q1';
    end
    q1_node=flipud(q1_node);
    
    q2_node=[];
    for i=1:length(p2)
        q2_node(:,i)=q2';
    end
    q2_node=flipud(q2_node);
           
    [r1 c1]=size(p1_node);
    [r2 c2]=size(p2_node);
   
    for i=1:r1
        for j=1:c1
            if i==1
                plot(p1_node(i,j),q1_node(i,j),'r*');
                hold on
            else
                plot(p1_node(i,j),q1_node(i,j),'*');
                hold on
            end
        end
    end
    
    for i=1:r2
        for j=1:c2
            plot(p2_node(i,j),q2_node(i,j),'*');
            hold on
        end
    end

    gap=l/n; 
    x=0:gap:l; % values at which divisions are to be done in the deployment area
    y=0:0.1:b;

    plot(x(1),y);
    hold on
    for i=2:length(x) 
        plot(x(i),y);    
    end    
end

axis([0 l+3 0 b+5])
end

Code 19 – Function M File – sensor_uniform.m

function [nodesx,nodesy,p1_node,p2_node,q1_node,q2_node,sn]=sensor_uniform(x,b,l,n)

%n=length(x); %number of divisions + 1
%y=n-1; %number of divisions

sn=input('Number of sensors to be deployed in one zone: ');
%h=sn;

nodesx=[];
nodesy=[];

figure(3)

if mod(sn,2)==0
    %even number case
    d=x(2)/4;
    p=[];
    for i=2:length(x)           
        p=[p (x(i-1)+d) (x(i-1)+(3*d))]; %x axis
    end
    
    hsn=sn/2;
    q=[];
    m=b/hsn;
    q0=m/2;    
    for j=0:(hsn-1)
        q=[q (q0+(m*j))]; %y axis
    end       
    
    for i=1:length(q)
        nodesx(i,:)=p;
    end
    
    for i=1:length(p)
        nodesy(:,i)=q;
    end       
    nodesy=flipud(nodesy);
    
    sensor_placement(nodesx,nodesy,l,b,n);
    p1_node=[];
    q1_node=[];
    p2_node=[];
    q2_node=[];
else
    %odd number case
    nodesx=[];
    nodesy=[];

    d=x(2)/4;
    p=[];
    for i=2:length(x)           
        p=[p (x(i-1)+d) (x(i-1)+(3*d))]; %x axis
    end
    
    p1=[];
    p2=[];
    for i=1:length(p)
        if mod(i,2)==0
            p2=[p2 p(i)];
        else
            p1=[p1 p(i)];
        end
    end   
    
    hsn=ceil(sn/2);
    q=[];
    m=b/hsn;
    q0=m/2;    
    for j=0:(hsn-1)
        q=[q (q0+(m*j))]; %y axis
    end     
    
    q1=q;
    q2=q(2:end);  
    
    p1_node=[];
    for i=1:hsn
        p1_node(i,:)=p1;
    end    
    
    p2_node=[];
    for i=1:(hsn-1)
        p2_node(i,:)=p2;
    end
        
    q1_node=[];
    for i=1:length(p1)
        q1_node(:,i)=q1';
    end
    q1_node=flipud(q1_node);
    
    q2_node=[];
    for i=1:length(p2)
        q2_node(:,i)=q2';
    end
    q2_node=flipud(q2_node);
           
    [r1 c1]=size(p1_node);
    [r2 c2]=size(p2_node);

    for i=1:r1
        for j=1:c1
            if i==1
                plot(p1_node(i,j),q1_node(i,j),'r*');
                hold on
            else
                plot(p1_node(i,j),q1_node(i,j),'*');
                hold on
            end
        end
    end
    
    for i=1:r2
        for j=1:c2
            plot(p2_node(i,j),q2_node(i,j),'*');
            hold on
        end
    end

    gap=l/n; 
    x=0:gap:l; % values at which divisions are to be done in the deployment area
    y=0:0.1:b;

    %figure(2)
    plot(x(1),y);
    hold on
    for i=2:length(x) 
        plot(x(i),y);    
    end
    %hold off

    axis([-1 l+1 -1 b+1])
    title('Sensor node numbers from left to right ')
    
    
end

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