## 2 Materials and Methods
### Algorithm
#### 2.1.5 Reconstruction  
In contrast to the reconstruction performed by MARA, where the segments are baseline corrected one by one, AMARA reconstruction is based on \"ok\" segments only (as with ABAMAR) and AMARA reconstructs the signal by including additional information from the acceleration sensor. MARA includes the (artifact removed) MA segments in the reconstruction. AMARA assumes that the length of the MA is small compared to the adjacent \"ok\" segments. The signal changes are expected to be within the magnitude of the standard deviations of the signal in adjacent segments. Based on the value of \(C_{k}\), AMARA assumes that the segments labeled with \"condition free\" (\(C_{k}\) = 1) represent \"trustworthy\" values. Those labeled as \"condition not free\" (\(C_{k}\) = 0) are not trusted and the corresponding signal may deviate from the original baseline. The baseline was defined as the mean of last or first part (of length \(L_{base}\), e.g., 20 s) of a segment. Between trustworthy segments (\"condition free\") a baseline shift may also be present. In such a case, the longest of all connected trustworthy segments will be used and the others will be adjusted to this level. The reconstruction comprises the following steps (see Figure 1d):  
**Step 1:** Find and adjust all the baselines of connected trustworthy segments. \"Connected\" is defined to be a group of segments with \(C_{ok,k}\) = 1, which are not separated by any other \"ok\" segment with \(C_{ok,k}\) = 0. MA segments are disregarded at this point. For each group, starting with the longest segment \(m\), all following segments (\(m\) + 1, \(m\) + 2, _etc._) are adjusted to the former segment's baseline. Similarly the baseline of the previous segments (\(m\) - 1, \(m\) - 2, _etc._) are adjusted. The baseline of the earlier segment (in time) is the last part of length \(L_{base}\) (e.g., 20 s) and has the average \(\bar{x}_{ok,m}\) and the SD \(\sigma_{ok,m}\). The later segment's baseline is defined to be the first part of length \(L_{base}\) with the average \(\bar{x}_{ok,m+1}\) and the SD \(\sigma_{ok,m+1}\). The later segment is only \"adjusted\" if the difference between the baselines is larger than 2.6 times the SD, a criterion adapted from ABAMAR. The factor 2.6 corresponds to the 99\({}^{\text{th}}\) percentile of normally distributed data. \[x_{ad,ok,m+1}=\left\{ \begin{array}{ll}x_{ok,m+1}-\big{(}\bar{x}_{ok,m+1}- \bar{x}_{adj,ok,m}\big{)},&\text{if}\quad\big{|}\bar{x}_{ok,m+1}-\bar{x}_{ok, m}\big{|}\geq 2.6\ \sigma_{ok,m}\\ x_{ok,m+1}-\big{(}\bar{x}_{ok,m}-\bar{x}_{adj,ok,m}\big{)},&\text{if}\quad \big{|}\bar{x}_{ok,m+1}-\bar{x}_{ok,m}\big{|}<2.6\ \sigma_{ok,m}\end{array} \right. \tag{13}\]  
The previous segments' baseline is adjusted similarly to the later segments' baseline:  
\[x_{ad,ok,m-1}=\left\{ \begin{array}{ll}x_{ok,m-1}-\big{(}\bar{x}_{ok,m-1}- \bar{x}_{adj,ok,m}\big{)},&\text{if}\quad\big{|}\bar{x}_{ok,m-1}-\bar{x}_{ok, m}\big{|}\geq 2.6\ \sigma_{ok,m}\\ x_{ok,m-1}-\big{(}\bar{x}_{ok,m}-\bar{x}_{adj,ok,m}\big{)},&\text{if}\quad \big{|}\bar{x}_{ok,m-1}-\bar{x}_{ok,m}\big{|}<2.6\ \sigma_{ok,m}\end{array} \right. \tag{14}\]  
**Step 2:** Adjust the baseline of all not trusted (\"condition not free\") segments in a forward loop. Starting with the first segment with \(C_{k}\) = 0 after the first trustworthy segment, the baseline of the segments with \(C_{k}\) = 0 is adapted to the former segments baseline. The baseline is shifted as in Equation (13). The resulting segments are saved in the vector \(x_{F\!F,ok,m}\). **Step 3:** Adjust the baseline of all not trusted (\"condition not free\") segments in a backward loop. Starting at the first segment with \(C_{k}=0\) before the last trustworthy segment, the baseline of the segments with \(C_{k}=0\) are adapted to the later segments' baseline. The baseline is shifted similarly as in Equation (14). The resulting segments are saved in the vector \(x_{BW,ok,m}\). **Step 4:** Interpolate the forward and backward adjusted baselines of all not trusted (\"condition not free\") segments.