## 3 Localization Algorithm
### The Optimal Reference Selection Scheme  
As we know, in three-dimensional underwater networks, ordinary node should communicate with at least four anchors to get its position. However, due to the anchor node failure or the harsh underwater communication environment, it is impossible to satisfy the demand of 4-anchor connectivity in DUANs all the time. Therefore, it is critical to develop an optimal reference selection scheme to support insufficient anchors in accomplishing the self-localization process precisely. In this section, an optimal reference selection scheme is proposed to increase the localization accuracy for DUANs with insufficient anchors. The scheme is also the foundation and the initialization of the dynamic reference selection-based self-localization algorithm illustrated in the next section. Assume that there are only three anchors in the network at time \(k\), \((x_{1}(k),y_{1}(k),z_{1}(k))\), \((x_{2}(k),y_{2}(k),z_{2}(k))\) and \((x_{3}(k),y_{3}(k),z_{3}(k))\) which are not sufficient for the localization process conventionally. Therefore, we need to select an extra reference node \((x_{i}(k),y_{i}(k),z_{i}(k))\) to assist the localization procedure. First, we set up a relative coordinate system as shown in Figure 4. In this figure, \(N_{1}\), \(N_{2}\) and \(N_{3}\) are the anchor nodes respectively, while \(N_{i}\) is the selected reference node. Let \(N_{1}N_{2}\) make up the x-axis. \(N_{1}\), \(N_{2}\) and \(N_{3}\) are in the \(xy\) plane. The z-coordinate of node \(N_{i}\) is positive. Thus, the relative coordinates of the three anchors are \((0,0,0)\), \((\hat{x}_{2}(k),0,0)\) and \((\hat{x}_{3}(k),\hat{y}_{3}(k),0)\) respectively. \(\hat{x}_{2}(k),\hat{x}_{3}(k)\)  
Figure 3: The time model of DUANs. and \(\hat{y}_{3}(k)\) are expressed as Equation (1) to Equation (3), where \(\theta\) is the rotation angle between the relative coordinate system and the geodetic coordinate system. \[\hat{x}_{2}(k)=\sqrt{(x_{2}(k)-x_{1}(k))^{2}+(y_{2}(k)-y_{1}(k))^{2}+(z_{2}(k)-z _{1}(k))^{2}} \tag{1}\]  
\[\hat{x}_{3}(k)=cos(\theta)\sqrt{(x_{3}(k)-x_{1}(k))^{2}+(y_{3}(k)-y_{1}(k))^{2}+ (z_{3}(k)-z_{1}(k))^{2}} \tag{2}\]  
\[\hat{y}_{3}(k)=sin(\theta)\sqrt{(x_{3}(k)-x_{1}(k))^{2}+(y_{3}(k)-y_{1}(k))^{2}+ (z_{3}(k)-z_{1}(k))^{2}} \tag{3}\]  
Secondly, as mentioned in [4], we can use the least square method to solve the self-localization problem. Therefore, in this paper, the least square error is adopted to get the localization error as mentioned in Equation (4). \[E_{ij}(k)=b_{ij}(k)^{T}(\mathbf{I}-\mathbf{A}(\mathbf{k})(\mathbf{A}(\mathbf{ k})^{T}\mathbf{A}(\mathbf{k}))^{-1}\mathbf{A}(\mathbf{k})^{T})\mathbf{b_{ij}}( \mathbf{k}) \tag{4}\]  
\(E_{ij}(k)\) is the least square error of unknown ordinary node \(j\) at time \(k\) when node \(i\) is selected as the reference node. \[A(k)= \begin{bmatrix}2(-\hat{x}_{i}(k))&2(-\hat{y}_{i}(k))&2(-\hat{z}_{i}(k))\\ 2(\hat{x}_{2}(k)-\hat{x}_{i}(k))&2(-\hat{y}_{i}(k))&2(-\hat{z}_{i}(k))\\ 2(\hat{x}_{2}(k)-\hat{x}_{i}(k))&2(\hat{y}_{2}(k)-\hat{y}_{i}(k))&2(-\hat{z}_{ i}(k))\end{bmatrix} \]  
\[b_{ij}(k)= \begin{bmatrix}-\hat{x}_{i}(k)^{2}-\hat{y}_{i}(k)^{2}-z_{i}(k)^{2}+d _{i}^{j}(k)^{2}-d_{1}^{j}(k)^{2}\\ \hat{x}_{2}(k)^{2}-\hat{x}_{i}(k)^{2}-\hat{y}_{i}(k)^{2}-\hat{z}_{i}(k)^{2}+d _{j}^{i}(k)^{2}-d_{2}^{j}(k)^{2}\\ \hat{x}_{3}(k)^{2}-\hat{x}_{i}(k)^{2}+\hat{y}_{3}(k)^{2}-\hat{y}_{i}(k)^{2}- \hat{z}_{i}(k)^{2}+d_{i}^{i}(k)^{2}-d_{3}^{i}(k)^{2}\end{bmatrix} \]  
\(d_{1}^{j}(k),d_{2}^{j}(k),d_{3}^{j}(k)\) are the distances between the unknown ordinary node \(j\) and the anchor nodes at time \(k\). \(d_{i}^{j}(k)\) is the distance between the unknown node \(j\) and the selected reference node \(i\) at time \(k\). The aim of reference selection scheme proposed in this section is to accomplish the localization process in DUANs with insufficient anchor nodes and to improve the localization accuracy simultaneously. Therefore, the optimal reference node is selected by minimizing the global localization error in the whole network according to Equation (5).