# A Bimodal EMG/FMG System Using Machine Learning Techniques for Gesture Recognition Optimization
## 2 Materials and Methods
### Data Processing  
As illustrated in Figure 4, the EMG and FMG signals are then initially acquired by BITalino, where they undergo basic preprocessing, which includes amplification and initial filtering.  
Figure 4: Steps of EMG and FMG signal processing.  
Figure 3: Acquisition of EMG and FMG signals: (**a**) On the clasp of the hand; (**b**) Opening the hand.  
After pre-processing, the data enters the phase of extracting the characteristics of the most relevant signals for the discrimination of gestures. Previously, it was necessary to detect signal onsets and offsets in order to identify the periods of muscle activation.  
The signals are then forwarded for offline processing in MATLAB. Here, additional denoising and bandpass filtering operations are performed to maintain only the relevant frequencies. The signal offset is also removed.  
Using the MATLAB software, the signals are processed, and their features are extracted through a set of previously developed routines [1; 14]. This set comprises a main routine with the pipeline, along with auxiliary functions for onset/offset detection and feature extraction from EMG and FMG signals.  
The main routine, implemented in MATLAB, performs a series of critical steps in signal processing:  
1. EMG signal filtering: For each text file (with EMG and FMG data), the code applies a bandpass filter from 20 to 500 Hz to the EMG signals;
2. Wavelet Denoising: EMG signals go through a second stage of noise reduction, this time using the wdenoise function of MATLAB's Wavelet Toolbox. This technique, which acts in the time-frequency domain, eliminates random noises that could be mistaken for true muscle activity;
3. Onset and offset detection of muscle activity: This is a crucial step. The code uses the onsetting function to determine when the muscle started to contract (onset) and when it stopped (offset). The result is a time series (vectors) of onsets and offsets of muscle contraction. The onset/offset function is responsible for identifying the moments when the EMG signal demonstrates significant activity. The function does this by full-wave rectification of the signal, applying a moving average to calculate the test function, and setting a threshold for onset detection. If the signal falls below this threshold, an offset is detected. In addition, the function also ensures that the detected activity moments have a minimum duration to avoid false detections (650 ms);
4. Corresponding activations: The code looks for muscle activations that coincide between the EMG signals of the two muscle windows (extensor and flexor). The onset and offset times of the FMG signals are given by the values saved for the corresponding EMG signals. The tolerance for coincidence is given by the value of the constant tolerance_window and has been maintained at 500 ms. Figure 5 shows an example of the signals acquired with the detection of the onsets and offsets of each muscle activation;
5. Feature extraction: For each muscle activation that matches, the code extracts a set of features from both the EMG and FMG signals. Features are measures that provide a deeper understanding of the signals, which would otherwise be very difficult to interpret.  
The extract_emg_features and extract_fmg_features functions were used to extract characteristics from the EMG and FMG signals, respectively. These functions compute a set of characteristics, both in the time and frequency domains (in the case of EMG), for each instance of a gesture. In total, thirty-six characteristics were extracted, twelve EMG and six FMG for each muscle group.