# A New Design of Codebook for Hybrid Precoding in Millimeter-Wave Massive MIMO Systems
## 3 Proposed Joint Codebooks Design Algorithm
Finally, we summarize the whole algorithm flow of the proposed Algorithm 1 in Figure 2.  
Figure 2: Flow of the proposed joint codebook design algorithm schemes. ```
Input:\(N_{1},N_{2}\) Output:\(\mathcal{F}_{\text{A}},\mathcal{F}_{\text{D}}\) Step1. The channel samples are generated by the channel model in Formula (2), we can find the optimal unconstrained precoding matrix corresponding to each channel matrix and form them into a training set \(\mathbf{Y}=\big{[}\mathbf{F}_{\text{opt}}(1),\mathbf{F}_{\text{opt}}(1),\cdots, \mathbf{F}_{\text{opt}}(N_{\text{tr}})\big{]}\), and set the initial simulation codebook \(\mathcal{F}_{\text{A}}=\big{[}\mathbf{a}_{i}\big{(}\frac{2\pi}{N_{1}}\big{)}, \mathbf{a}_{i}\big{(}\frac{2\pi}{N_{1}}\big{)},\cdots,\mathbf{a}_{i}(2\pi) \big{]}\); Step2. According to steps 3-12, we can calculate the extended digital precoding matrix \(\widetilde{\mathbf{F}}_{\text{BB}}(i)\) corresponding to each \(\mathbf{F}_{\text{opt}}(i)\), the constraints and objective function can be expressed as \[\widetilde{\mathbf{F}}_{\text{BB}}^{\text{opt}}(i)= \text{arg}\min_{\widetilde{\mathbf{F}}_{\text{BB}}(i)}\big{\|} \mathbf{F}_{\text{opt}}(i)-\mathbf{F}_{\text{A}}\widetilde{\mathbf{F}}_{\text {BB}}(i)\big{\|}_{F},\] (10) \[\text{s.t.}\quad\left\|\text{diag}\big{(}\widetilde{\mathbf{F}}_{ \text{BB}}(i)\widetilde{\mathbf{F}}_{\text{BB}}(i)^{H}\big{)}\right\|_{0}=N_{ \text{t}}^{\text{RF}},\forall i,\] \[\left\|\mathbf{F}_{\text{A}}\widetilde{\mathbf{F}}_{\text{BB}}( i)\right\|_{F}^{2}=N_{\text{s}},\forall i.\] Step3. Let residual \(\mathbf{F}_{\text{res}}=\mathbf{F}_{\text{opt}}\), \(\Omega\) is the empty set \(\varnothing\); Step4. Calculate \(\mathbf{\Phi}=\mathbf{F}_{\text{A}}^{H}\mathbf{F}_{\text{res}}\); Step5. Select the number of \(2N_{\text{s}}\) with the largest value on the diagonal of the matrix \(\mathbf{\Phi}\mathbf{\Phi}^{H}\) and set the corresponding sequence number \(\theta_{1},\theta_{1}=\Big{\{}k|(\mathbf{\Phi}\mathbf{\Phi}^{H})_{(k,k)}\Big{\}}\); Step6. Select the corresponding column from the analog codebook FA to compose a matrix \(\mathbf{A}_{t}\), \(\mathbf{A}_{t}=\mathbf{F}_{\text{A}}(:,\theta)\), where \(\theta=\Omega\cup\theta_{1}\); Step7. The digital precoding matrix \(\mathbf{F}_{\text{BB}}\) can be calculated by the least squares method, \(\mathbf{F}_{\text{BB}}=\big{(}\mathbf{A}_{t}^{H}\mathbf{A}_{t}\big{)}^{-1} \mathbf{A}_{t}^{H}\mathbf{F}_{\text{opt}}\); Step8. Select the number of Ns with the largest value on the diagonal of the matrix \(\mathbf{F}_{\text{BB}}\mathbf{F}_{\text{BB}}^{H}\) and set the corresponding sequence number \(\theta_{2},\theta_{2}=\Big{\{}q|(\mathbf{F}_{\text{BB}}\mathbf{F}_{\text{BB}}^ {H})_{(q,q)}\Big{\}}\); Step9. Let \(\Omega=\theta(:,\theta_{2})\), and select the corresponding \(N_{\text{s}}\) serial numbers from the set \(\theta\); Step10. Update the residual, \(\mathbf{F}_{\text{res}}=\mathbf{F}_{\text{opt}}-\mathbf{F}_{\text{A}}(:,\theta _{2})\mathbf{F}_{\text{BB}}(\theta_{2},:)\); Step11. Determine whether the residual is equal to 0; if it equals to 0, enter Step 12; otherwise, return to Step 4 to continue iterating; Step12. Extend \(\mathbf{F}_{\text{BB}}(\theta_{2},:)\) to \(\widetilde{\mathbf{F}}_{\text{BB}}(i)\), i.e., the elements are all zero in the rows of non-\(\Omega\) in \(\widetilde{\mathbf{F}}_{\text{BB}}(i)\), and the row corresponding to the sequence number in the set \(\Omega\) is composed of the corresponding elements in \(\mathbf{F}_{\text{BB}}(\theta_{2},:)\); Step13. Let \(\mathbf{X}=\big{[}\widetilde{\mathbf{F}}_{\text{BB}}(1),\widetilde{\mathbf{F}}_{ \text{BB}}(2),\cdots,\widetilde{\mathbf{F}}_{\text{BB}}(N_{\text{tr}})\big{]}\), we can update \(\mathbf{Y}\) by \(\mathbf{Y}=\mathbf{F}_{\text{A}}\mathbf{X}\); Step14. Regarding \(\mathbf{Y}\) as the original sample, \(\mathbf{F}_{\text{A}}\) as a dictionary, and \(\mathbf{X}\) as a sparse matrix, by using the dictionary learning algorithm, the analog codebook \(\mathbf{F}_{\text{A}}\) and digital codebook \(\mathbf{X}\) can simultaneously update.