# EMG-Driven Shared Control Architecture for Human-Robot Co-Manipulation Tasks +
## 2 Materials and Methods
### High-Level Layer
#### 2.3.1 EMG Signal Processing and Classification  
EMG signals are electrical signals produced by the muscles when they contract or relax. To detect these signals, surface or needle-based electrodes are used; in this work, non-invasive surface electrodes attached to the skin with adhesive are considered. The precise placement of these electrodes on the target muscle plays a crucial role, as the amplitude and frequency content of the EMG signals vary with electrode positioning relative to the muscle fibers. Before being processed, these signals need to be amplified, digitized and filtered to remove noise and processed to extract features to evaluate muscle functionality, activation or distinction between different types of contractions. In this work, EMG signals are used to detect muscle activity and patterns related to specific movements or actions. In order to achieve this objective, it is essential to utilize a signal processing classifier. A review of the literature on classifiers and preliminary tests performed on some of them, including those based on Random Forest, revealed that a Support Vector Machine (SVM) classifier was the most suitable for the purposes of this work. The SVM classifier, which is a widely used supervised learning algorithm for classification tasks, receives a set of features extracted from the EMG signals segmented into time windows called epochs. In particular, three time-domain features commonly used for EMG signal classification [41] are extracted:* The Root Mean Square (RMS) can be used to evaluate muscle activity and fatigue; it is defined as: \[RMS=\sqrt{\frac{1}{N}\sum_{i=1}^{N}y_{i}^{2}}\] (13)
* The Mean Absolute Value (MAV) can be used to assess the intensity of muscle contraction. It's definition is: \[MAV=\frac{1}{N}\sum_{i=1}^{N}|y_{i}|\] (14)
* The Average Amplitude Change (AAC) provides information about fluctuations in muscle activity over a period of time and about the level of muscle activation during that period. It is useful for assessing muscle fatigue, tracking changes in muscle activity, and comparing muscle involvement during different activities or conditions. It can be computed as: \[AAC=\frac{1}{N}\sum_{i=1}^{N}|y_{i+1}-y_{i}|\] (15)  
For all the features, \(y_{i}\) is the \(i\)-th element of the vector \(y\) that contains the amplitudes of the EMG signals in a predefined epoch of 1s, and \(N\) is the number of elements contained in \(y\). To train the classifier, the SVM algorithm uses a data set consisting of feature vectors with associated class labels obtained with a predetermined acquisition procedure. The algorithm learns a decision boundary that maximally separates the different classes by finding an optimal hyperplane in the feature space. Let \(\mathbf{x}\in\mathbb{R}^{d}\) be a \(d\)-dimensional feature vector, and let \(z\in\{-1,1\}\) be the class label in the binary case. The hyperplane that separates the classes can be represented as:  
\[\mathbf{w}\;\phi(\mathbf{x})+b=0\;,\]  
where \(\phi(\cdot)\) is a function mapping the input data into the feature space, \(\mathbf{w}\) is a vector of weights and \(b\) is the bias term. The parameters of the hyperplane that separate the classes most effectively can be obtained by solving the following Quadratic Programming (QP) problem:  
\[\min_{\mathbf{w},b,\mathbf{\xi}} \frac{1}{2}\mathbf{w}^{\intercal}\mathbf{w}+C\sum_{i=1}^{M}\xi_{i}\] subject to \[z_{i}(\mathbf{w}^{\intercal}\phi(\mathbf{x}_{i})+b\geq 1-\xi_{i}\qquad i=1,2,\ldots,M\]  
where \(M\) is the number of training samples, \(C>0\) is a regularization parameter and \(\xi_{i}\geq 0\) are slack variables used to relax the constraint in the case of non-separable data. In the dual formulation of the SVM optimization problem, the decision function depends only on dot products between pairs of training samples in the feature space, i.e., \(x_{i}^{T}x_{j}\). These dot products are computed in practice via a kernel function \(K(\mathbf{x}_{i},\mathbf{x}_{j})\).