# Closed-Loop Cognitive-Driven Gain Control of Competing Sounds Using Auditory Attention Decoding
## 2 Methods
### Correlation Coefficient Generation  
To generate the correlation coefficients of speaker 1 and speaker 2, we adopted the least-squares-based AAD method from Reference [3], which estimates the attended speech envelope from the EEG responses using a spatio-temporal envelope estimator trained during the calibration phase. 1. _Training step (calibration phase):_ In the training step, the attended speaker is assumed to be known. The attended speech envelope is then estimated from the  
Figure 4: Real-time AAD (RAAD) and adaptive gain controller (AGC): (a) block diagram and (b) process flow. pre-processed EEG responses \(r_{c,k}\), with \(c\) the electrode index for \(1\ldots C\), using a spatio-temporal envelope estimator \(\mathbf{g}\)[3], i.e.,  
\[\hat{e}_{a,k}=\mathbf{g}^{T}\mathbf{r}_{k}, \tag{1}\]  
with  
\[\mathbf{g}=\left[\mathbf{g}_{1}^{T}\,\mathbf{g}_{2}^{T}\ldots\,\mathbf{g}_{C}^ {T}\right]^{T}, \tag{2}\]  
\[\mathbf{g}_{c}=\left[g_{c,0}\,\,\,g_{c,1}\ldots\,\,g_{c,J-1}\right]^{T}, \tag{3}\]  
\[\mathbf{r}_{k}=\left[\mathbf{r}_{1,k}^{T}\,\mathbf{r}_{2,k}^{T}\,\,\ldots\, \,\mathbf{r}_{C,k}^{T}\right]^{T}, \tag{4}\]  
\[\mathbf{r}_{c,k}=\left[r_{c,k}\,r_{c,k+1}\,\,\ldots\,\,r_{c,k+J-1}\right]^{T}, \tag{5}\]  
where \(J\) denotes the number of envelope estimator coefficients per electrode. The trained envelope estimator \(\mathbf{g}\) is obtained by minimizing the least-squares error between the (known) attended speech envelope \(e_{a,k}\) and the reconstructed envelope \(\hat{e}_{a,k}\), regularized with the squared norm of the derivative of the envelope estimator coefficients to avoid over-fitting [3; 14; 29], i.e.,  
\[\min_{\mathbf{g}}\frac{1}{K}\sum_{k=1}^{K}(e_{a,k}-\mathbf{g}_{a,k}^{T})^{2}+ \beta\mathbf{g}^{T}\mathbf{\Lambda}\mathbf{g}, \tag{6}\]  
with \(\mathbf{\Lambda}\) denoting the derivative matrix [14] and \(\beta\) denoting a regularization parameter. The solution of (6) is equal to  
\[\mathbf{g}=(\mathbf{Q}+\beta\mathbf{\Lambda})^{-1}\mathbf{q}, \tag{7}\]  
with the correlation matrix \(\mathbf{Q}\) and the cross-correlation vector \(\mathbf{q}\) given by  
\[\mathbf{Q}=\frac{1}{K}\underset{k=1}{\overset{K}{\sum}}\mathbf{r}_{k}\mathbf{ r}_{k}^{T},\,\,\,\,\mathbf{q}=\frac{1}{K}\underset{k=1}{\overset{K}{\sum}} \mathbf{r}_{k}\mathbf{e}_{a,k}. \tag{8}\]
2. _Correlation coefficient generation step (open-loop and closed-loop AAD phase):_ To generate the correlation coefficients of speaker 1 and speaker 2, we compute the Pearson correlation coefficients between the estimated attended envelope \(\hat{e}_{a,k}\) in (1) and the speech envelopes \(e_{1,k}\) and \(e_{2,k}\), i.e., \[\rho_{1,k}=\rho(\mathbf{e}_{1,k},\,\,\hat{\mathbf{e}}_{a,k}),\,\,\,\rho_{2,k} =\rho(\mathbf{e}_{2,k},\,\,\hat{\mathbf{e}}_{a,k}),\] (9) where \(\hat{\mathbf{e}}_{a,k}\) denotes the stacked vector of estimated attended envelopes corresponding to a correlation window of length \(K_{COR}\), i.e., \[\hat{e}_{a,k}=\mathbf{g}^{T}\mathbf{r}_{k}, \tag{1}\]0 (10) and \(\mathbf{e}_{1,k}\) and \(\mathbf{e}_{2,k}\) are defined similarly as in (10). In the training step, the pre-processed EEG responses obtained from the calibration phase were segmented into trials of length 15 s, shifted by 1 sample (corresponding to \(\frac{1}{64}\) s). The parameters \(J\) and \(\beta\) of the envelope estimator in (3) and (7) were determined for each participant using a leave-one-trial-out cross-validation approach, similarly as in Reference [3; 14]. Using these parameters, a trained spatio-temporal envelope estimator \(\mathbf{g}\) in (7) was then computed for each participant using all trials from the calibration phase. In the correlation coefficient generation step, the pre-processed EEG responses were segmented in the same way as in the training step.