## 6 Pairwise Synchronization and Localization
\(P_{A}\) and \(P_{S}\) is the position of anchor node and ordinary sensor node respectively, also the coordinates of a sensor node can be expressed as \([x^{s},y^{s},z^{s}]\) and \(v\) is the signal propagation speed in underwater acoustic channels. Here we have the depth information of both sensor and anchor node which are \(z_{i}\) and \(z\) respectively. Also, we have the information on the location, and time of the anchor node. By putting the value of the distance formula in Equation (33), we get Equation (34) as,  
\[\left(\frac{T_{i}-\beta}{\alpha}-\eta_{i}\right)\
u\ =\ \sqrt{\left(x_{i}-x^{s} \right)^{2}\ +\ \left(y_{i}-y^{s}\right)^{2}\ +\ \left(z_{i}-z^{s}\right)^{2}}\,\ i\in\{\,1,\ 2,\ \ldots\.\.\,\ N\} \tag{34}\]  
For simplifying above equation, we use (35) and (36) will become,  
\[T_{i}^{\prime}\triangleq\frac{T_{i}}{\alpha}-\eta_{i},\ i\in\{1,2,\ldots\.\.,\ N\},\ \beta^{\prime}\triangleq\frac{\beta}{\alpha} \tag{35}\]  
\[\sqrt{\left(x_{i}-x^{s}\right)^{2}\ +\ \left(y_{i}-y^{s}\right)^{2}\ +\ \left(z_{i}-z^{s}\right)^{2}}\ =\ \left(T_{i}^{\prime}-\beta^{\prime}\right)\
u \tag{36}\]  
\(\alpha\) has been obtained in the second phase. By using \(\alpha\), we can find \(T_{i}^{j}\). However, \(x\), \(y\), and \(\beta^{\prime}\) are not known to us in the above Equation (36). For the estimation of \(x\), \(y\), and \(\beta^{\prime}\), we must have the information of at least three other anchor nodes to get three equations. Linear least square will be used for estimation. Linear least square solution is given by Equation (37),  
\[L\ast S\ =\ U\,\text{{where},\ S\ =\ [x,y,\beta^{\prime}]} \tag{37}\]  
\[L\ =\ \left[ \begin{array}{ccc}2(x_{2}-x_{1})&2(y_{2}-y_{1})&2\left(T_{2}^{ \prime}-T_{1}^{\prime}\right)\
u^{2}\\ 2\left(x_{3}-x_{1}\right)&2(y_{3}-y_{1})&2\left(T_{3}^{\prime}-T_{1}^{\prime} \right)\
u^{2}\\ \vdots&\vdots&\vdots\\ 2(x_{k}\ -\ x_{1})&2\ (y_{k}\ -\ y_{1})&2\left(T_{k}^{\prime}\ -\ T_{1}^{\prime} \right)\
u^{2}\end{array} \right]\in\ C^{3\times 3} \tag{38}\]  
\[U\ =\ \left[ \begin{array}{ccc}x_{2}^{2}-x_{1}^{2}\ +\ y_{2}^{2}-y_{1}^{2}\ +\ z_{2}^{2}-z_{1}^{2}-2(z_{2}-z_{1})z\ +\ \left(T_{2}^{\prime}-T_{1}^{\prime}\right)\
u^{2}\\ x_{3}^{2}-x_{1}^{2}\ +\ y_{3}^{2}-y_{1}^{2}\ +\ z_{3}^{2}-z_{1}^{2}-2\ (z_{3}-z_{1})z\ +\ \left(T_{3}^{ \prime 2}-T_{1}^{\prime 2}\right)\
u^{2}\\ \vdots\\ x_{k}^{2}-x_{1}^{2}\ +\ \ y_{k}^{2}-y_{1}^{2}\ +\ z_{k}^{2}-z_{1}^{2}-2\ (z_{k}-z_{1})z\ +\ \left(T_{k}^{\prime\,2}-T_{1}^{\prime\,2}\right)\
u^{2}\end{array} \right] \tag{39}\]  
According to Equations (38) and (39) the ordinary sensor node can receive packets from different numbers of anchor nodes for the estimation of its location. Equation (40) estimates the error by using,  
\[min\Big{\{}e^{T}\ e\Big{\}}\ =\ \ min\Big{\{}\left[LS\ -\ U\right]^{T}\left[LS\ -\ U \right]\Big{\}} \tag{40}\]  
\[\frac{\partial}{\partial S}\big{[}LS\ -\ U\big{]}^{T}\ [LS\ -\ U\big{]}\ =\ 0 \tag{41}\]  
As indicated by the Equation (41), we can find out \(S\), or use the Equation below to calculate \(S\). \[L^{T}\ LS\ =\ L^{T}\ U \tag{42}\]  
\[S\ =\ (L^{T}\ L)^{-1}L^{T}\ U \tag{43}\]  
With the help of (43), \(x\), \(y\), and \(\beta^{\prime}\) have now known us. By putting \(\beta^{\prime}\) in Equation (35), the offset will be obtained. By using linear regression twice in the first and second phases of our algorithm, the ordinary sensor node can be synchronized and localized.