## 2 Materials and Methods  
### Algorithm  
AMARA assumes that artifacts are always related to movements. Hence, it only accepts artifacts within movement periods of the subject, detected in the first step \"movement detection\". The subsequent steps, _i.e._, artifact detection, segmentation, and artifact removal, were adapted from MARA [34] and were improved. The reconstruction of the signal was specifically developed for long-term recordings (8-10 h) including a criterion adapted from ABAMAR [63]. The algorithm was developed for application in sleep studies, thus the parameters given (summarized in Table 1) are optimized for such long-term recordings. \begin{table}
\begin{tabular}{c c c} \hline
**Parameter** & **Value** & **Description** \\ \hline \(q\) & 2 s & Defines the MSD window length \(2q+1\) \\ \(w_{\text{size}}\) & 15 min & Moving window length for the Zack triangle algorithm \\ \(w_{\text{step}}\) & 5 min & Step size for the Zack triangle algorithm \\ \(T_{\text{area}}\) & 0.005 & Noise criteria \\ \(T_{\text{streamorm}}\) & 0.2 & Normalized noise criteria \\ \(L_{\text{min}}\) & 2 s & Minimum allowed artifact size or gap between artifacts \\ “condition free” & no default & Defines the fixed segments for the reconstruction (no artifacts) \\ \hline \end{tabular}
\end{table} 
Table 1: List of parameters used in the AMARA algorithm. With the parameter values provided, the algorithm worked optimally in case of our recordings. However, the values depend on the specific characteristics of the input NIRS signals, e.g., number of MAs, frequency of occurrence of the MAs, amplitude of the MAs within the data, or the noise level. These parameters were chosen empirically to give the best result for the data sets comprising long-term NIRS measurements as reported by [PERSON] _et al._[21, 22]. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Parameter** & **Value** & **Description** \\ \hline \(p\) & 1 s & Window length for the FIR filter, Savitzky-Golay filter and MSD within the artifact removal procedure \\ \(f_{\text{c,FIR}}\) & 0.5 Hz & Cut-off frequency of the FIR filter within the artifact removal procedure \\ \hline \hline \end{tabular}
\end{table} 
Table 1: _Cont._  
Figure 1: Flow charts of the whole algorithm (**a**) and detailed flow charts of specific steps (**b–d**). The algorithm detects movements and artifacts separately and only removes artifacts that coincide with a movement. The reconstruction is based on so-called trusted parts of the signal which are determined based on the acceleration signal. (**a**) AMARA flow chart. \(acc(t)\): time dependent acceleration signal with a \(x\)-, \(y\)- and \(z\)-component. \(\overline{acc}(t)\): unfiltered acceleration signal. \(\zeta_{acc}(t)\): output of the movement detection; every movement is marked by “1” at the corresponding sampling points. \(x(t)\): original signal (e.g., \(O_{2}Hb\) or \(HHb\)) containing MAs. \(\bar{x}(t)\): unfiltered input signal. \(\zeta_{x}(t)\): output of the artifact detection; every MA is marked by “1” at the corresponding sampling points. \(x_{ok}\): container for only “ok” epochs (containing no MAs). \(x_{MA}\): container for only artifact epochs (containing MAs). \(x^{*}_{MA}\): container, artifact epochs after MA removal, high frequency information is preserved. \(y(t)\): output signal of AMARA; of the same size as \(x(t)\), but with MAs removed and the reconstructed trend; (**b**) Movement detection flow chart. \(a_{t}(t)\): \(x\)-, \(y\)- or \(z\)-component of \(acc(t)\). \(\zeta_{acc,i(t)}\) as in (a) but for a single component of \(acc(t)\). The final output vector is obtained by combining the three components (Equation (3), see text below). MSD: moving standard deviation. MZ: moving Zack triangle algorithm [64]. \(T_{acc,i}(t)\): vector containing the determined threshold for the acceleration signal; (**c**) Artifact detection flow chart for a signal \(x\). The subscript \(x\) relates the variable to the signal \(x\) instead of the acceleration \(acc\); (**d**) Reconstruction flow chart.