## 3 Methodology
### Signal Pre-Processing  
The raw input signal is first decomposed into smaller segments. To optimize the window length, this study explored three different window sizes, based on the 50 Hz sampling rate used for data collection: (1) a 1 s window (50 data points), (2) a 3 s window (150 data points), and (3) a 5 s window (250 data points). An overlap of 80% among consecutive segments by using a stride of 20% is shown in Figure 2.  
With respect to the desired overlap (O) and selected window size (WS), the stride (S) can be derived from the following equation:  
\[S=WS\times(1-O), \tag{1}\]  
whereas the exact window indices (Start, End) for \(N^{th}\) segment (starting from 0) can be determined by the following equation:  
Figure 1: Pipeline for detecting and classifying anomalies in inertial data (segment-by-segment processing) acquired from the most affected upper limb. The data are pre-processed and used to train four models: two (random forest and HARDenseRNN) for movement disorder detection and two (random forest and HARDenseRNN) for movement disorder classification. A comparative analysis of the two modeling approaches is provided in the Results Section.  
Figure 2: Diagram illustrating signal segmentation process with parameters WS (Window size), S (Stride), and O (Overlap). S1 represents the initial segment, and s[N] denotes the \(N^{th}\) segment.  
\[W_{n}=[n\times S,n\times S+(WS-1)]. \tag{2}\]  
The decomposed signal segments are then labeled. For this purpose, this study has explored two different labeling approaches. The first one (S1 methodology--early labeling) treats the segment as an anomalous one if it contains any anomalous data points (in the event of a single anomalous data point). Otherwise, it is treated as a normal segment (zero anomalous data points). In the second labeling approach (S2 methodology--late labeling), the segment label is as per majority voting. If most of the data points are anomalous, the label will be anomalous. On the other hand, if most of the data points are normal, the label will be normal. In case of a tie, the label will be anomalous. Pseudo-code for signal pre-processing can be found in Algorithm 1. Overall, this study has explored three different window sizes, each with two different labeling approaches. Their performance-wise comparative analysis is outlined in the Results Section.  
```
1:Input: Raw signal data, Sampling rate \(f_{s}\), Window size \(WS\), Overlap \(O\)
2:Output: Segmented windows with indices and labels
3:\(S\gets WS\times(1-O)\)\(\triangleright\) Calculate stride based on overlap
4:\(n\gets 0\)\(\triangleright\) Initialize segment counter
5:while not end of signal do
6:\(Start\gets n\times S\)
7:\(End\gets Start+(WS-1)\)
8: Extract segment \(W_{n}=[Start,End]\)
9:\(n\gets n+1\)
10:endwhile
11:for each segment \(W_{n}\)do\(\triangleright\) S1 - Early labeling
12:
13:if any anomalous data point in \(W_{n}\)then
14: Label \(W_{n}\) as anomalous
15:else
16: Label \(W_{n}\) as normal
17:endif
18:\(\triangleright\) S2 - Late labeling
19:\(count_{anomalous}\leftarrow\) Number of anomalous points in \(W_{n}\)
20:\(count_{normal}\leftarrow\) Number of normal points in \(W_{n}\)
21:if\(count_{anomalous}>count_{normal}\)then
22: Label \(W_{n}\) as anomalous
23:else if\(count_{normal}>count_{anomalous}\)then
24: Label \(W_{n}\) as normal
25:else
26: Label \(W_{n}\) as anomalous (tie case)
27:endif
28:endfor
```  
**Algorithm 1** Signal pre-processing.