# Optimization of Virtual Loudspeakers for Spatial Room Acoustics Reproduction with Headphones
## 2 Virtual loudspeaker Position Optimization
### Sample Weighting  
Even though loudspeaker position optimization is calculated from the RIR, optimal results are not achieved with the pressure values of the IR alone. The early part of the RIR, which includes the direct sound and early reflections, can be assumed to contain the most important perceptual information about the acoustic space. As opposed to the late part, the central role of the early part is supported by its significance in the identification of the acoustic space [15]. This is why it is reasonable to emphasize the early part of the response through directionally accurate reproduction. In addition, some of the DOAs calculated by the SDM describe the actual incoming direction of sound more accurately than others, which is discussed below in more detail. To take these presented properties into account in optimization, the first step in the process is to weight each pressure sample in the RIR accordingly. Figure 1: Position optimization system outline. Spatial Decomposition Method (SDM) generated data containing directions of arrival (DOA) the omnidirectional pressure values for each sample are provided to the algorithm, from which the optimized loudspeaker positions are approximated. The numbers inside the boxes refer to the corresponding sections in this paper, spatial downsampling part (in blue) working as an extra acceleration component for the main algorithm (in black). The weighting is based on SDM data points--in other words, pressure and DOA of each audio sample in the RIR. As a whole, this information is called SDM data. The weighting \(\mathbf{w}=\{w_{1}\ldots w_{N}\}\) can be seen as a mapping of this data:  
\[\Big{\{}\,f:(\mathbf{p},\mathbf{u}_{\text{doa}})\mapsto\mathbf{w}\quad\Big{|} \quad\mathbf{p},\mathbf{w}\in\mathbb{R}^{N},\;\mathbf{u}_{\text{doa}}\in \mathbb{R}^{N\times 3},\;||\mathbf{u}_{\text{doa},n}||=1,\;w_{n}\in[0,1]\; \forall\;n=1\ldots N\Big{\}} \tag{1}\]  
where \(\mathbf{p}\) and \(\mathbf{u}_{\text{doa}}\) are the pressure and DOA values of the SDM data, respectively; and \(N\) is the length of the IR in samples. In short, each SDM data point generates one scalar weight to be associated with itself. Each weight consists of four distinct subweights named energy, delay, gradient and direction that are described in more detail below. 1. Energy weighting corresponds to the most traditional form of weighting. Each SDM data point is weighted according to its energy: \[w_{\text{E},n}=\frac{p_{n}^{2}}{\max_{n}(p_{n}^{2})}\] (2) where \(p_{n}\) is the omnidirectional pressure value of the \(n\)th data point. This gives more weight to data points with more incident energy. 2. Delay weighting emphasizes the SDM data points that locate in the earlier part of the RIR. Weighting is computed as a normalized backward Schroeder integral [16] over the RIR: \[w_{\text{T},n}=\frac{\sum_{k=n}^{N}p_{k}^{2}}{\sum_{k=1}^{N}p_{k}^{2}}\] (3) This causes the direct sound and early reflections with distinctively more energy to be weighted more than samples in the later part of the response. This aspect is linked to psychoacoustics, as the early part of the RIR is perceptually more important than the late reverberation [15]. 3. Gradient weighting is used as a reliability measure to the SDM data points. The reliability of one SDM data point is dependent on the data points directly before and after it in time. If DOAs of the neighboring data points are close to the DOA of the current point, the point is given a large weight, and the greater the distance to its neighbors, the smaller the weight. The weight of one SDM data point is resolved as a mean of the distances between the DOA of the point and the DOAs of the previous and next data points: \[w_{\text{G},n} =10^{(min_{n}(d_{\text{G},n})-d_{\text{G},n})/10}\] (4) \[d_{\text{G},n} =\frac{||\mathbf{u}_{\text{doa},n}-\mathbf{u}_{\text{doa},n-1}||+ ||\mathbf{u}_{\text{doa},n+1}-\mathbf{u}_{\text{doa},n}||}{2h}\] (5) where \(h\) is the size of the time step between two SDM samples.