# Joint Diagnosis of RIS and BS for RIS-Aided Millimeter-Wave System
## 3 Proposed Algorithm
### Fast Algorithm for the Completely Blockage Scenario  
In this subsection, we consider the scenario where RIS and BS are completely blocked [15]. We find that the Algorithm 1 needs multiple iterations to obtain the BS and RIS blockage coefficients, which leads the complexity of Algorithm 1 to be large. Motivated by this, we propose fast Algorithm for estimating the BS and RIS blockage coefficients without iteration.  
In the first stage, we estimate the BS blockage coefficient vector. Due to the fact that we consider the scenario of complete blockage, that is, if the \(n\)-th antenna on the BS is blocked, we have \(1+s_{n}=0\), and we can obtain the estimation of \(s_{n}\) by judging whether \(y_{n}(t)\) is equal to 0 according to (5), where \(y_{n}(t)\) denotes the \(n\)-th element of \(\mathbf{y}(t)\). However, due to the effect of the noise, the value of the received signal \(y_{n}(t)\) may be large even if \(1+s_{n}=0\), which leads us to judge an blocked antenna as free. In order to decrease the effect of noise, we appropriately design the phase coefficients of RIS \(\boldsymbol{\theta}(t)\). Specifically, according to (5), in the \(n\)-th time slot, we have  
\[y_{n}(n)=(1+s_{n})[\mathbf{G}^{BR}\text{diag}(\overline{\mathbf{b}}\circ \mathbf{g}^{RU})]_{n,\boldsymbol{\theta}}(n)+n_{n}(n). \tag{15}\]  
We can increase the amplitude of \([\mathbf{G}^{BR}\text{diag}(\overline{\mathbf{b}}\circ\mathbf{g}^{RU})]_{n, \boldsymbol{\theta}}(n)\) to decrease the effect of noise \(n_{n}(n)\). Due the fact that the element of \(\overline{\mathbf{b}}\) is either 1 or 0, and we know the cascaded channel \(\mathbf{G}^{BR}\text{diag}(\overline{\mathbf{b}}\circ\mathbf{g}^{RU})\), the optimal solution of \(\boldsymbol{\theta}(n)\) for maximizing the function \(||[\mathbf{G}^{BR}\text{diag}(\overline{\mathbf{b}}\circ\mathbf{g}^{RU})]_{n,\boldsymbol{\theta}}(n)|\) can be expressed as \(\boldsymbol{\theta}_{n}(t)=e^{-2\beta\tau\angle(\mathbf{G}^{BR}\text{diag}( \overline{\mathbf{b}}\cdot\mathbf{g}^{RU})]_{n,\boldsymbol{\theta}}(n)}\), where \(\angle(x)\) denotes the angle of complex \(x\). After \(N\) time slots, we can get the estimation of BS blockage coefficients \(\mathbf{b}\).  
In the second stage, we estimate the RIS blockage coefficient vector \(\overline{\mathbf{s}}\). In this stage, we combine \(T\) time slots and the phase coefficients of RIS are generated randomly. According to (6), by combining the \(T\) time slots, we have  
\[\overline{\mathbf{y}}=\overline{\overline{\mathbf{H}}}\overline{\mathbf{s}}+ \overline{\overline{\mathbf{n}}}, \tag{16}\]  
where \(\overline{\overline{\mathbf{y}}}=[\overline{\overline{\mathbf{y}}}^{T}(1), \cdots,\overline{\overline{\mathbf{y}}}^{T}(T)]^{T}\), and where \(\overline{\overline{\mathbf{y}}}(n)\) can be expressed as \(\overline{\overline{\mathbf{y}}}(n)=\mathbf{y}_{\mathcal{I}^{BS_{z}}}(n)- \mathbf{H}_{\mathcal{I}^{BS_{z}}}(n)\mathbf{1}_{M\times 1}\). In addition, \(\overline{\overline{\mathbf{H}}}\) can be expressed as \(\overline{\overline{\overline{\mathbf{H}}}}=[\mathbf{H}_{\mathcal{I}^{BS_{z}} }(1);\cdots;\mathbf{H}_{\mathcal{I}^{BS_{z}}}(T)]\). The vector \(\mathcal{I}^{BS}\) denotes the index of non-zero element of \(\mathbf{s}\), which is obtained in the first stage. We observe that the Equation (16) is similar to (8). Thus, we can utilize the OMP algorithm on (16) to estimate the RIS blockage coefficients \(\overline{\mathbf{s}}\).  
Next, we analyze the complexity of fast Algorithm. The total complexity of fast Algorithm is \(\mathcal{O}(MNT+NT(N_{R})^{2}+(N_{R})^{3}+NT)\). Compared to the complexity of Algorithm 1, the complexity of fast Algorithm is lower than that of Algorithm 1. Furthermore, the number of pilot symbols used in the proposed algorithm in this paper is similar to the algorithm of [9,11]. Our algorithms can be extended to multi-user scenarios. When we adopt the orthogonal code, the code words used by each user are orthogonal, and the algorithms can be used separately without affecting each other, which can realize the multi-user diagnosis.