## 6 Pairwise Synchronization and Localization  
We are considering the three-dimensional network with four anchor nodes. We assume that the anchor nodes are synchronized, and locations are known to calculate the ordinary sensor node's skew, offset, and location. The ordinary sensors clock is:  
\[T\ =\ \alpha\eta\ +\ \beta \tag{23}\]  
In the above Equation (23), \(\alpha\) and \(\beta\) are the clock skew and clock offset respectively whereas \(\eta\) is the reference time and \(T\) is the time of the sensor node. As defined earlier in phase I the anchor nodes will broadcast one-way timestamps packets until the sensor node has got enough information about the timestamps. After receiving enough packets from all anchor nodes, initially, the ordinary sensor node will perform the calculation of propagation delay along with the calculation of velocity as described above. Propagation delay, between anchor nodes and ordinary sensor node, will be estimated in the first phase, which is further used as input for the next phase. In the second phase, we compute clock skew by using the linear regression on the difference between the received timestamp and the time stamp in the packets. These packets only contain the time stamp information of the first phase. As defined earlier, in underwater communication, propagation is generated due to the low signal propagation, by using linear regression all the above-mentioned parameters can write as,  
\[T_{i}\ =\ \alpha\ (\eta_{i}\ +\ t_{i})\ +\ \beta,\,i\in\{1,2,\ldots\ \ldots,\ N\} \tag{24}\]  
where \(T_{i}\) is the time of the sensor node B (node that needs to be synchronized and localized), \(\eta_{i}\) and \(t_{i}\) are the reference time and the propagation delay of \(i\)th anchor node respectively in Equation (24). Note that we required sufficient packets for the accurate calculation of skew, as the error of skew will affect the accuracy of our algorithm. To simplify the linear regression of skew, we have:  
\[\varepsilon_{i}^{j}\triangleq\ \alpha t_{i}^{j}\ +\ \beta,\,j\in\{1,2,\ldots\ \ldots,\ N\} \tag{25}\]  
Equation (25) shows the for \(j\)th packets of \(i\)th anchor node, where \(\varepsilon_{i}\) is the difference of clock skew. By subtracting Equations (24) and (25) we get:  
\[T_{i}^{j}\ =\ \alpha\eta_{i}^{j}\ +\ \varepsilon_{i}^{j},\,j\in\{1,2,\ldots\ \ldots,\ N\} \tag{26}\]  
For solving Equation (26) from linear regression we consider,  
\[P\ =\ Q\ast M \tag{27}\]  
\[P\ =\ \big{[}T_{i}^{1},\ T_{i}^{2},\ \ldots\ \ldots,\ T_{i}^{N}\big{]}^{T},M \ =\ [\alpha,\varepsilon]^{T} \tag{28}\]  
\[Q\ =\ \left[ \begin{array}{cc}\eta_{i}^{1}&1\\ \vdots&\vdots\\ \eta_{i}^{N}&1\end{array} \right]\]  
We assumed the skew is unchanged in the received only synchronization mechanism. For minimizing the error, we are using the equations as follows:  
\[min\ \{E\}=min\ \{e^{T}\,e\}=min\ \{[QM-P]\ ^{T}\,[QM-P]\} \tag{29}\]  
\[\frac{\partial}{\partial M}[QM-P]^{T}[QM-P]\ =\ 0 \tag{30}\]  
In the above Equation (29) \(E\) is the least square error of the estimation (LS estimator). Equation (30) can estimate \(M\), also \(M\,(\alpha,\varepsilon)\) can be calculated by (20),  
\[M=(Q^{T}\,Q)^{-1}\,(Q^{T}P) \tag{31}\]  
Our next step is to calculate the error due to clock offset to obtain more accuracy of the ordinary sensor node and its position as well. As the local time of sensor node contains both skew and offset error. Now by using the known locations of different anchors and the time with the help of time, we carry out our above linear regression equation for the position and the offset of the ordinary sensor node. \[T_{i}\ =\ \alpha\ \Big{(}\eta_{i}\ +\ \frac{\gamma_{i}}{\
u}\Big{)}\ +\ \beta \tag{32}\]  
\[\gamma_{i}\ =\ \bigg{(}\frac{T_{i}-\beta}{\alpha}-\eta_{i}\bigg{)}\
u\ =\ \parallel P_{A}-P_{S}\parallel \tag{33}\]  
In the above Equation (32) \(\gamma_{i}\) is the distance between anchor A and the ordinary sensor node.