# Joint Diagnosis of RIS and BS for RIS-Aided Millimeter-Wave System
## 3 Proposed Algorithm
### Algorithm 1 for the Partial Blockage Scenario  
In this subsection, we will propose an iterative compressed-based algorithm for the joint estimation of the RIS blockage and BS blockage. We define \(\mathbf{s}^{i}\) and \(\mathbf{\bar{s}}^{i}\) as the estimation of RIS/BS blockage in the \(i\)-th iteration. In the first stage, we estimate the blockage coefficient vector of RIS. We split the Equation (7) and have  
\[\mathbf{\bar{y}}=\mathbf{A}\mathbf{\bar{s}}^{i+1}+\mathbf{n}, \tag{8}\]  
where \(\mathbf{\bar{y}}\in\mathbb{C}^{NT\times 1}\) and \(\mathbf{A}\in\mathbb{C}^{NT\times M}\) can be defined as  
\[\mathbf{\bar{y}}=\mathbf{y}-\left[ \begin{array}{c}\mathbf{H}(1)\mathbf{1}_{ M}\\ \vdots\\ \mathbf{H}(T)\mathbf{1}_{M}\end{array} \right]-\left[ \begin{array}{c}\text{ diag}(\mathbf{s}^{i})\mathbf{H}(1)\mathbf{1}_{M}\\ \vdots\\ \text{diag}(\mathbf{s}^{i})\mathbf{H}(T)\mathbf{1}_{M}\end{array} \right], \tag{9}\]  
and  
\[\mathbf{A}=\left[ \begin{array}{c}\text{diag}(\mathbf{1}_{N}+\mathbf{s}^{i}) \mathbf{H}(1)\\ \vdots\\ \text{diag}(\mathbf{1}_{N}+\mathbf{s}^{i})\mathbf{H}(T)\end{array} \right]. \tag{10}\]  
From (9) and (10), we observe that the vector \(\overline{\mathbf{y}}\) and matrix \(\mathbf{A}\) are the function of \(\mathbf{s}^{i}\) and \(\mathbf{H}(t)\). Thus, the problem of estimating the spare vector \(\overline{\mathbf{s}}^{i+1}\) becomes the sparse recovery problem. In this way, we utilize the OMP algorithm for estimating \(\overline{\mathbf{s}}^{i+1}\). The details are shown in Steps 4-8 of Algorithm 1. Furthermore, we do not know the number of the RIS blockage in advance, thus, we need to design an appropriate stop condition to terminate the algorithm. The stop condition can be expressed as \(\frac{||\vec{\mathbf{r}}||_{2}^{2}}{||\mathbf{y}||_{2}^{2}}\geq\zeta\), which is shown in Step 3. Actually, due to the impact of the inaccurate BS blockage \(\mathbf{s}^{i}\) estimation in the initial iterative process, the error \(\frac{||\vec{\mathbf{r}}||_{2}^{2}}{||\mathbf{y}||_{2}^{2}}\) is usually large. After multiple iterations, we can have the accurate estimation of BS blockage, thus, the error \(\frac{||\vec{\mathbf{r}}||_{2}^{2}}{||\mathbf{y}||_{2}^{2}}\) is small. Thus, the stop condition can be designed dynamically, that is, we set the value of \(\zeta\) large in the initial process and decrease the value of \(\zeta\) appropriately after multiple iterations. In the second stage, we estimate the blockage vector of BS. We reshape the Equation (7) and have  
\[\widetilde{\mathbf{Y}}=\text{diag}(\mathbf{s}^{i+1})\mathbf{B}+\mathbf{N}, \tag{11}\]  
where \(\widetilde{\mathbf{Y}}=[\widetilde{\mathbf{y}}(1),\widetilde{\mathbf{y}}(2), \cdots,\widetilde{\mathbf{y}}(T)]\in\mathbb{C}^{N\times T}\), \(\mathbf{N}=[\mathbf{n}(1),\mathbf{n}(2),\cdots,\mathbf{n}(T)]\in\mathbb{C}^{ N\times T}\), and \(\widetilde{\mathbf{y}}(t)\) can be expressed as  
\[\widetilde{\mathbf{y}}(t)=\mathbf{y}(t)-\mathbf{H}(t)\mathbf{1}_{M}-\mathbf{ H}(t)\overline{\mathbf{s}}^{i+1}. \tag{12}\]  
Additionally, the matrix \(\mathbf{B}\) can be expressed as  
\[\mathbf{B}=[\mathbf{H}(1)(\mathbf{1}_{M}+\overline{\mathbf{s}}^{i+1}), \mathbf{H}(2)(\mathbf{1}_{M}+\overline{\mathbf{s}}^{i+1}),\cdots,\mathbf{H}( T)(\mathbf{1}_{M}+\overline{\mathbf{s}}^{i+1})]\in\mathbb{C}^{N\times T}.\]  
From (12) and (13), we find that matrix \(\widetilde{\mathbf{Y}}\) and \(\mathbf{B}\) are functions of the RIS blockage \(\overline{\mathbf{s}}^{i+1}\) and \(\mathbf{H}(t)\). In addition, we observe that the \(k\)-th row of matrix \(\widetilde{\mathbf{Y}}\) is affected by the \(k\)-th element of \(\mathbf{s}^{i+1}\) and that the other elements of the vector \(\mathbf{s}^{i+1}\) have no effect on the \(k\)-th row of matrix \(\widetilde{\mathbf{Y}}\).