# Numerically Optimized Fourier Transform-Based Beamforming Accelerated by Neural Networks
## 3 Algorithms for Phase Distribution Optimization
### Definition of Cost Function and Sampling Method  
The optimization process strongly depends on the selection of the cost function expressed in terms of the electric field radiation pattern, \(|\mathbf{E}(u,v)|\). Due to the aforementioned reasons, the cost function should include two terms to divide the radiation pattern domain into two regions. The first term should cover the PAs. The second term covers the domains that do not fit into PAs, i.e., the Unprotected Area (UA). Therefore, the cost function \(\Psi\) can be defined as follows:  
\[\Psi=C_{1}\Psi_{PA}+C_{2}\Psi_{UA}. \tag{10}\]  
The optimization goal should be defined so as to minimize the cost function and acquire the desired pattern. Reaching this goal depends on the coefficients \(C_{1}>0\) and \(C_{2}>0\) in Equation (10), which are weights that specify the importance of each region and its influence on the cost function.  
In a practical realization of the optimization algorithm, samples are taken from the electric field pattern to find the radiated power magnitude at every point in the \((u,v)\)-space. The cost function values for each area are calculated using the acquired power samples, as in Equations (11) and (12):  
\[\Psi_{UA}=\sum_{k=1}^{p}|\mathbf{E}(u_{k},v_{k})|^{2}, \tag{11}\]  
where \(k\) and \(p\) are the index and the number of sample points outside the PA, respectively. Here, \(|\mathbf{E}(u_{k},v_{k})|\) is the PMS-generated far-zone electric field taken at the \(k\)-th sample point outside the PA [Equation (6)]. On the other hand, within the PA,  
\[\Psi_{PA}=\sum_{i=1}^{L}\sum_{j=1}^{q}\left||\mathbf{E}(u_{ij},v_{ij})|-\alpha _{i}\beta|F(u_{ij},v_{ij})|\right|^{t}, \tag{12}\]  
where the index \(i\) iterates over \(L\) main beams and \(j\) and \(q\) are the index and the number of sample points inside the \(i\)-th protected area, respectively. Here, \(|\mathbf{E}(u_{ij},v_{ij})|\) is the far-zone electric field updated at every cost function evaluation, and \(|F(u_{ij},v_{ij})|\) is the magnitude of the project pattern defined by Equation (3). Both quantities are evaluated at the points \((u_{ij},v_{ij})\) inside the \(i\)-th protected area. In total, \(p+L\times q\) points are sampled to evaluate the final cost function, Equation (10). In Figure 6, examples of the sampling of \(|\mathbf{E}(u,v)|\) are shown for a couple of considered scenarios.  
Figure 6: Sampling of the reconstructed electric field pattern for the single-beam and dual-beam cases corresponding to a \(10\times 3\) PMS. The green circles delineate the VAs and the red ovals mark the PAs. The background colors represent \(|\mathbf{E}(u,v)|\) values before optimization. (**a**) Single-beam scenario for \((\theta_{0_{1}},\varphi_{0_{1}})=(60.2^{\circ},221.1^{\circ})\). (**b**) Dual-beam scenario for \((\theta_{0_{i}},\varphi_{0_{1}})=(60.2^{\circ},45^{\circ})\) and \((\theta_{0_{2}},\varphi_{0_{2}})=(30^{\circ},225^{\circ})\).  
Furthermore, in Equation (12), \(\alpha_{i}>0\) is a controlling factor that can manipulate the magnitude of a specific main beam in multi-beam scenarios and serve as a scale factor per each beam. Additionally, the quantity \(\beta>0\) must be selected properly to adjust for the difference in scales of the values given by Equations (3) and (6). The gain in the main beams should increase after applying phase distribution optimization due to the law of energy conservation because such optimization leads to a decrease in the overall sidelobe level. This allows the algorithm to properly suppress the sidelobes and increase the main beams' gain at the same time. Finally, the exponent \(t>0\) can be used to adjust the convergence rate of the optimization algorithm.