## 2 Materials and Methods
### Algorithm
#### 2.1.1 Movement Detection  
Figure 1b depicts the four necessary steps to detect movements in the acceleration signal _acc_(_t_), which is the vector of the _x_-, _y_- and _z_-acceleration components (_i.e._, _acc_(_t_) = [_ax_(_t_), _a_(_t_), _a_(_t_)]). The final output of the movement detection is a vector \(\zeta_{acc}(t)\) which contains \"1\" whenever a movement was found and zero otherwise. This vector is calculated by the following steps:  
**Step 1:** First, the moving standard deviation (MSD) of _acc_(_t_) is calculated:  
\[MSD_{acc,i}(t)=\left[\frac{1}{2q+1}\sum_{j=-q}^{q}\left(a_{i}(t+j)-\frac{1}{2q+ 1}\sum_{j=-q}^{q}a_{i}(t+j)\right)^{2}\right]^{\frac{1}{2}} \tag{1}\]  
where the MSD window length is given by \(2q+1\) samples and \(i\) represents the components \(x\), \(y\), or \(z\). The value of \(q\) used here is twice the number of samples per second of the signal, _i.e._, representing two seconds for the NIRS data used in the present study. Thus, \(q=2\) s \(\times\)_f\({}_{s}\)_ (_i.e._, two seconds times the sampling frequency _f\({}_{s}\)_ in Hz = 2 s of data), whereas_f\({}_{s}\)_ has to be an integer. **Step 2:** The threshold _T\({}_{acc}(t)\)_ for the detection of movements is determined automatically using the moving Zack triangle algorithm [64]. This method finds _T\({}_{acc}(t)\)_ based on the quantile distribution \(D\) (equal to the inverse cumulative distribution) of the data within a certain window of length _w\({}_{size}\)_ (see Figure 2). A line \(L\) is drawn from the smallest to the largest quantile within \(D\) (Figure 2e,f) and the normal (black line marked with a 90\({}^{\circ}\) angle in Figure 2f) to \(L\) is moved to find the maximum length between \(L\) and _D_[64]. The threshold _T\({}_{acc}\)_ corresponds to the _y_-value of the intersection of the normal with \(D\). Now a threshold is defined for the first _w\({}_{size}\)_ seconds of _MSD\({}_{acc,i}(t)\)_. To find the threshold _T\({}_{acc}(t)\)_ for the rest of the signal, a window of the length _w\({}_{size}\)_ is moved forward by the step size _w\({}_{step}\)_ and the algorithm is applied again. The values used for _w\({}_{size}\)_ and _w\({}_{step}\)_ were 15 \(\times\) 60 s \(\times\)_f\({}_{s}\)_ and 5 \(\times\) 60 s \(\times\)_f\({}_{s}\)_, respectively. This represents 15 and 5 min of data. Since the step size _w\({}_{step}\)_ is smaller than the window size _w\({}_{size}\)_, the calculated thresholds overlap. To avoid overlapping of the thresholds, the threshold is only set for the center _w\({}_{step}\)_ data points within the window of size _w\({}_{size}\)_. Hence, _T\({}_{acc}\)_[t - _w\({}_{step}\)_/2,..., t + _w\({}_{step}\)_/2] = MZA([_MSD\({}_{acc,t}\)_[t - _w\({}_{size}\)_/2,..., t + _w\({}_{size}\)_/2]). MZA represents the application of the moving Zack triangle algorithm and t is the time point in the center of the window of size _w\({}_{size}\)_. The Zack triangle algorithm is not able to distinguish a noisy, but valid, biological signal (= \"Noise\" in Figure 2) from an artifact. Hence, two conditions had to be applied to identify noise afterwards: the area between \(L\) and \(D\), and the normalized area between \(L\) and \(D\) (Figure 2e,f). The normalized area was obtained from the normalized quantile distribution, defined as _D_/max(_D_). If one of these values was smaller than the thresholds _T\({}_{area}\)_ (typically 0.005) or _T\({}_{areanorm}\)_ (typically 0.2), respectively, the data in the window were considered to be noise and the threshold _T\({}_{acc}\)_ was set to infinity. For example, if normally distributed noise dominates the signal, the absolute and normalized area between \(L\) and _D_approach zero. If there is a (small) peak within normally distributed noise, the normalized threshold will be large, but the absolute area will be small. In case of non-normally distributed noise or when different noise levels are present in the data, the absolute area might be large, but the normalized area will still be small.