"""
SECTION IV.Proposed Algorithm
On breaking down the properties of LEACH protocol, cluster head selection plays the main role in enhancing and improving the network lifetime, data transmission and energy-efficient. We propose a new algorithm to improve the lifetime of the network by selecting Cluster Head (CH) and Secondary Cluster Head (SCH) in the sensor setup phase of each round. According to previous researches, the nearest the distance between CH and BS, the better lifetime and energy-efficient the network is. Basis equation (1) we choose to select the closest node to the BS as CH and the closest node to the CH as SCH, with considering on energy and distance parameters of the node. Depending on this suggestion, if the CH dead the cluster will not cut off the communication with the sink and the secondary cluster head replace the dead cluster head and pronounces itself as a cluster head. Rather than that, the cluster continuously connecting the sink as long as the active node alive in the cluster.

The threshold in the proposed method is defined as follows:
T(ni)={p1−ps(rmod(1p)i0+⎛⎝⎜2–√−dis(st)(x+y4)⎞⎠⎟/α(3)
View SourceRight-click on figure for MathML and additional features.
\begin{equation*}T\left( {{n_i}} \right) = \begin{cases} {\frac{p}{{1 - {p_s}\left( {r\,\bmod \,{{\left( {\frac{1}{p}} \right)}_i}} \right.}}} \\ 0 \end{cases} + {{\left( {\sqrt 2 - \frac{{dis\left( {st} \right)}}{{\left( {\frac{{x + y}}{4}} \right)}}} \right)} \mathord{\left/ {\vphantom {{\left( {\sqrt 2 - \frac{{dis\left( {st} \right)}}{{\left( {\frac{{x + y}}{4}} \right)}}} \right)} \alpha }} \right.} \alpha }\tag{3}\end{equation*}

The threshold is defined above because we want node energy criteria and node-sink distance to be effective in determining CH and SCH. Although Select secondary cluster head costs more time in the setup phase for the same round, it keeps the cluster communicate with the BS in case it has alive nodes. Equation 4 what we call the distance coefficient,
2–√−dis(st)(x+y4)⎞⎠⎟/α(4)
View SourceRight-click on figure for MathML and additional features.
\begin{equation*}{{\left. {\sqrt 2 - \frac{{dis\left( {st} \right)}}{{\left( {\frac{{x + y}}{4}} \right)}}} \right)} \mathord{\left/ {\vphantom {{\left. {\sqrt 2 - \frac{{dis\left( {st} \right)}}{{\left( {\frac{{x + y}}{4}} \right)}}} \right)} \alpha }} \right.} \alpha }\tag{4}\end{equation*}
increases the likelihood of nodes being shorter than the sink. dis(si) compute the distance of the node i to the sink. This value can be calculated by relying on the Euclidean distance (the distance between two nodes is the line length between them) and as shown in equation (5)
d(p,q)=(q1−p−−−−−−√(5)p2)2¯¯¯¯¯¯¯¯¯.
View SourceRight-click on figure for MathML and additional features.
\begin{equation*}\begin{array}{ccc} {d\left( {{\mathbf{p}},{\mathbf{q}}} \right) = \sqrt {\left( {{q_1} - p} \right.} }&{\left( 5 \right)}&{\overline {{{\left. {{p_2}} \right)}^2}} } \end{array}.\end{equation*}

Where, points p = (p1 p2) and q = (q1 q2) are the locations of the two nodes The number of CH should equal the number of SCH (one SCH for each CH) at the beginning of the round.

Returning to reducing data transmission time, we suggest that the position of BS should be in the center of the WSN as shown in Figure 2 surrounding with four equal-area squares in order to optimize energy consumption for communicating between clusters and BS

Figure 2: - 
Architecture platform of the proposed algorithm
Figure 2:
Architecture platform of the proposed algorithm

Show All

From the perspective of making the network with high latency. we applythe algorithm of node density in the cluster.Some nodes are not able to join the cluster because they have not the range ratio of any cluster, So they connect to BS directly without electing CH by the protocol which called Direct transmission (DTx), where (we assume Figure 3 illustrates this algorithm.

SECTION V.BASE LINE SIMULATION
Considering the major issues of the Wireless Sensor Networks, We focus on the most common algorithm. LEACH protocol, which enhanced the performance of the WSN such as Energy efficient, Transmission time, transmission rate, optimal position of the sink, the optimal position of the cluster head, node density and network lifetime. These are the main performance enhancement factors that we figure out in this paper. Figure 4 shows the initial LEACH protocol with homogenous network topology using MATLAB (Version: 9.2.0,518641) with an area of 100 × 100m. BS is in the center of the network (50,50), with 100 nodes are deployed randomly and certain nodes are randomly selected as cluster heads. We fixed a maximum number of clusters to be 10, a maximum number of rounds is 5000 and the initial energy equal 0.5Joules.

Figure 3: - 
Nodes density in a cluster; LEACH protocol connection and DTx protocol connection with BS
Figure 3:
Nodes density in a cluster; LEACH protocol connection and DTx protocol connection with BS

Show All

Then, we set the data packet size equal to 4000 bits and the number of packets from each node to be 10 each round. We prefer to save the same parameters for all algorithms to gain fair comparison.

Figure 4: - 
LEACH protocol topology in Matlab, where all the nodes are alive
Figure 4:
LEACH protocol topology in Matlab, where all the nodes are alive

Show All

First issue is choosing the cluster head and to build our baseline, we explore the basic LEACH protocol simulation with respect to the fixed parameters and we found that the first dead node is in round 1428, and the last dead node is in round 1934 as shown in the Figure 5. The red dots are the dead nodes in contrast with round value. The process in LEACH protocol is divided into two phases. First, elect the Cluster head which form the clusters (setup phase). Second, data communication start between ordinary nodes and their cluster head and between cluster heads and base station (steady state phase). Because randomly selection of cluster head, all nodes have the same probability to be a cluster head, which increases the energy consumption. As soon as the cluster head is elected, the CH node warns the other nodes that it is the CH. The nodes sense the data and send packets to the CH in the same cluster, CH collect the data from nodes and transmit it to the base station. Data communication is conducted by TDMA routing protocol. Each node takes slot time to send its data packet. Figure 5 illustrates a snapshot of the network during the last period. The small red nodes denotes the dead nodes in the network. While, Figure 6 shows a snapshot of network, while communicating and transferring the data packets.

Figure 5: - 
Snapshot of the network during the last period. red dots (small ones) denote the dead nodes
Figure 5:
Snapshot of the network during the last period. red dots (small ones) denote the dead nodes

Show All

Figure 6: - 
Snapshot of network while communicating and transferring packets
Figure 6:
Snapshot of network while communicating and transferring packets

Show All

Alive nodes counting in contrast with a number of rounds are lustrated in Figure 7. The figure shows alive node analysis of asic LEACH protocol. As shown in the figure, the nodes start dead during round 1547, and then all nodes are dead in round 1934.

Figure 7: - 
Alive node analysis of basic LEACH
Figure 7:
Alive node analysis of basic LEACH

Show All

The network lifetime influenced by the energy consumption of each node. When the consumed energy increases, network lifetime decreases. Figure 8 illustrates the basic LEACH with average consumed energy in each round.

Figure 8: - 
Average consumed energy of basic LEACH
Figure 8:
Average consumed energy of basic LEACH

Show All

Next section, we discuss the simulation results of the proposed algorithm and compare the result with the basic leach protocol.
"""
上述为LEACH算法的改进论文的proposed algorithm和simulation部分，请帮我编写matlab代码复现该实验