# Optimization of Virtual Loudspeakers for Spatial Room Acoustics Reproduction with Headphones
## 2 Virtual loudspeaker Position Optimization
### Sample Weighting
The reasoning for this procedure is based on the fact that the SDM provides weighted average of the true DOAs in case of overlapping plane waves [6,10]. The set of samples over which the DOA changes can then be considered as spatially less accurate than samples with more steady DOA estimate. 4. Direction weighting emphasizes the data points that have a lot of energy arriving from their general direction regardless of the temporal information. The operation can be thought as a low-pass filter for directions; a single high-energy sample does not get a large weight unless there are more high energy samples in the same spherical sector. Conversely, the sectors with mainly low-energy samples are given a small weight. Perceptually, this operation can be thought as simulating the limits of perception. A single high energy sample cannot be heard separately but a longer period of time is needed to generate a perceivable acoustic event. Therefore, directions with more high-energy samples should be prioritized when searching for optimal loudspeaker positions. There is also a benefit in algorithmic means as the influence of high-energy sectors are spread, making it easier for the optimization algorithm to iterate to the directions with higher energy density. Similar to the spatial downsampling presented later in Section 2.3, the general energy directions are approximated by calculating an energy map. First, an equidistant grid of points is created on the surface of the unit sphere, representing DOAs in the listener space. Then, each SDM data point is assigned to the closest point in this grid, measuring the distance from the DOA of the data point to the DOA of the grid point. When this nearest-neighbor search is ready, the energies of the assigned data points are accumulated grid point wise. The operation results in an energy map where the energy of different incoming directions has been approximated. Finally, the weight of the SDM data point is calculated from this map by interpolation:  
\[w_{\text{D},n} =\frac{\sum_{i=1}^{3}E_{\min(n,i)}*d_{\min(n,i)}}{\sum_{i=1}^{3}d_ {\min(n,i)}} \tag{6}\] \[d_{\min(n,i)} =i\text{th smallest value of a set}\quad\{||\mathbf{u}_{\text{doa},n}- \mathbf{u}_{\text{grid},m}||,\ m=1\dots M\} \tag{7}\]  
where \(\mathbf{u}_{\text{grid},m}\) is the DOA of \(m\)th grid point, \(M\) is the number of grid points and \(E_{\min(n,i)}\) is the energy value associated with the \(i\)th closest grid point. These four subweights form the final weight vector \(\mathbf{w}_{final}\) through the following equation:  
\[\mathbf{w}_{final}=\prod_{i=1}^{4}\mathbf{w}_{i}^{c_{i}} \tag{8}\]  
where \(\mathbf{w}_{i}\) is a vector containing the values of one of the subweights described above and \(c_{i}\) is the corresponding mixing coefficient. As all \(\mathbf{w}_{i}\) are equalized in range \([0,1]\), mixing coefficients practically adjust how much each partial weight vector reduces the resulting weights. Through the rest of the position optimization process, the weights are combined with their corresponding DOAs and used as a replacement for the pressure of the IR.