## 2 Materials and Methods
### IRS-RFL Algorithm
#### 2.2.3 Online Matching Positioning Stage  
Let the coordinates of \(US\) be \(\mathbf{LOC}_{US}=(x_{US},y_{US},z_{US})\), and the data to be compared are \(\boldsymbol{f}_{US}=[\boldsymbol{f}_{\boldsymbol{p}_{1 US}},\ldots,\boldsymbol{ f}_{\boldsymbol{p}_{MUS}}]\). The data combined with the coordinates of \(US\) and the data to be compared of \(US\) are expressed as Equation (31).  
\[\boldsymbol{f}_{US}=[\mathbf{LOC}_{US},\boldsymbol{f}_{\boldsymbol{p}_{1 US}},\ldots,\boldsymbol{f}_{\boldsymbol{p}_{MUS}}]. \tag{31}\]  
The reconstructed fingerprint database \(\mathbf{X}^{\prime}\) was obtained in the offline database building stage, and the online matching and positioning stage employed the maximum ratio [47] merging concept to multiply the fingerprint data of each fingerprint reference point with the corresponding SNR. Here, the SNR \(SNR_{m}\) denotes the SNR of the channel between \(US\) and \(BS\) after reflection through \(IRS_{m}\). Its calculation is given by Equation (32).  
\[SNR_{m}=\frac{\left\|\boldsymbol{H}_{m}\right\|^{2}}{\sigma^{2}}, \tag{32}\]  
where \(\sigma^{2}\) denotes the average power of the noise.  
The data to be compared from the \(US\), combined with the maximum ratio, were then matched to assess similarity with the fingerprint data in the fingerprint database using the WKNN algorithm. Euclidean distance was used to measure the similarity of fingerprints. A larger distance implied lower similarity, whereas a smaller distance implied a higher similarity. Let \(\mathbf{X}_{i}=[\boldsymbol{f}_{\boldsymbol{p}_{1|i}},\ldots,\boldsymbol{f}_{ \boldsymbol{p}_{M|i}}]\) be the \(i\)th fingerprint data in the reconstructed fingerprint database **X**. The formula for calculating the similarity between the data to be compared of _US_ and the _i_th fingerprint data is:  
\[sim_{i}=\sqrt{\sum\limits_{m=1}^{M}\sum\limits_{w=1}^{W}{(\mathbf{f}\mathbf{p}_{mi}(m,w) SNR_{mi}-\mathbf{f}\mathbf{p}_{mUS}(m,w)SNR_{m})^{2}}} \tag{33}\]  
where \(SNR_{im}\) is the SNR of \(BS\) to the channel of the _i_th fingerprint reference point after reflection through \(IRS_{m}\). Following the similarity measurements with all fingerprint data points in the database, the coordinates \([\textbf{LOC}_{1},\ldots,\textbf{LOC}_{S}]\) corresponding to the \(S(S\geq 3)\) fingerprint data points with the highest similarity were selected. Subsequently, the WKNN algorithm was used to assign different weights (_weight_) to the coordinates corresponding to fingerprint data points with different similarities, which were calculated using Equation (34).  
\[weight_{s}=\frac{1/(sim_{s}+\varepsilon)}{\sum\limits_{s=1}^{S}{1/(sim_{s}+ \varepsilon)}}, \tag{34}\]  
where \(\varepsilon\) is a small positive number used to avoid a zero denominator. After obtaining the corresponding weights of the coordinates of the \(S\) reference points, the estimated coordinates \(LOC^{\prime}_{US}\) of \(US\) can be obtained using Equation (35).  
\[\begin{split}\textbf{LOC}^{\prime}_{US}&=\left(x^{ \prime}_{US},y^{\prime}_{US},z^{\prime}_{US}\right)\\ &=\sum\limits_{s=1}^{S}{weight_{s}\textbf{LOC}_{s}}\end{split} \tag{35}\]  
The localization error \(e^{\prime}\) was calculated using the Euclidean distance between the estimated coordinates of _US_ and true coordinates of _US_, as expressed by Equation (36).  
\[e^{\prime}=\sqrt{\left(x_{US}-x^{\prime}_{US}\right)^{2}+\left(y_{US}-y^{ \prime}_{US}\right)^{2}+\left(z_{US}-z^{\prime}_{US}\right)^{2}} \tag{36}\]