## 3 Real-Time Classification  
The previous section proposed an offline machine learning model to recognize hand gestures from small fixed windows of IMU signals. To embed the Figure 7, the classification pipeline in a real-time application, it first needs to be combined with an algorithm that will trigger the classification process. There are (at least) two options to do that. The first option is to have a fixed-size sliding window and repeated classification routines at short, fixed intervals in this window. When tested, this method performed weakly (for multiple reasons). First, different gestures take different lengths of time to complete. Even if the gestures are supposed to be the same, they can be executed at different rates. Additionally, to prevent the classifier from predicting the same given gesture multiple times over the fixed sliding window (or to make an early (and incorrect) prediction), there has to be an algorithm that determines the moment at which the gesture begins and ends (the solution  
Figure 6: Normalized confusion matrices, resulting from the validation of the optimized SVM classifier for (**a**) five different gestures and (**b**) four different gestures. Figure 7: Final diagram of the classification process (pipeline). could also be to increase the time lapse between the intervals of classifications, but this would greatly increase the risk of missing significant windows of signals). The other option is to use a sliding window over the signal (but this time to determine only the moments at which the gesture starts and ends); only then is the classification process triggered and a gesture predicted. As a result, this does not produce a fixed-size snapshot of the signal. Instead, the snapshot begins when the sliding window recognizes the beginning of a gesture and ends when the signal comes back to an idle state. The beginning and end of a gesture are determined for the signals' variance and instantaneous slope (from the derivative). Indeed, none of the components in Figure 7 actually requires the input to always be of the same length. This procedure settles the previously stated issues (duplication of the prediction and variable length of the gestures) and allows for the execution of sequences of gestures in a fluid and efficient manner. Algorithm 1 presents the definition of DetectAction. ```
1:functionDetectAction(SensorReading\(r\))
2:\(\triangleright\)length\((r)\) should be 1
3:\(\triangleright\)\(start=end=\texttt{NULL}\) for the first function call
4:\(window\leftarrow\texttt{concatenate}(window[1...],r)\)\(\triangleright\)slide\(window\)
5:if\(\left|\frac{d}{dt}[window[-\delta\dots]]\right|>\textit{threshold}_{d}\)AND\(\texttt{Var}[window[-\delta\dots]]>\textit{threshold}_{\textit{var}}\)then
6:if\(start==\texttt{NULL}\)then
7:\(start\leftarrow\texttt{length}(window)-\delta\)
8:\(end\leftarrow\texttt{NULL}\)
9:else
10:\(start\gets start-1\)\(\triangleright\)slides with \(window\)
11:endif
12:else
13:\(end\leftarrow\texttt{length}(window)-1\)
14:if\(start\)NOTNULLthen
15:\(action=\texttt{Predict}(window[start\dots end])\)
16:\(start\leftarrow\texttt{NULL}\)
17:endif
18:endif
19:return\(action\)
20:endfunction
```  
**Algorithm 1** Definition of the real-time gesture recognition sub-routine. The function takes \(r\) (a sensor reading) as an input. In the context of the experiments, \(r\) has two components, the accelerometer's magnitude signal and the gyroscope's magnitude signal. Using the magnitude does not constrain the IMU to be positioned in any specific orientation on the body of the user. The length of \(r\) should be 1, meaning it is only a single new point. This assumption simplifies Algorithm 1, but a validation could be added. The window sliding operation is then represented by Line 4, where \(r\) is appended to \(window\) and the first \(\texttt{length}(r)\) elements of \(window\) are removed. To generalize, the \(window\) would be a \(2\times l_{w}\) matrix, where \(l_{w}\) is the length of the window and each row represents one component.