1 Introduction

Information extracted from EMG signals is useful for the field of automatic affect analysis. An exemplary use of this technology for that purpose was presented by C. Rasch et al. in 2015 [1] where facial EMG was used together with eye tracking for product marketing. The realm of electromyographic (EMG) signal processing gained popularity thanks to the surface electromyography (sEMG) which allows for the noninvasive measurements. This technique has been applied to distinct areas like the remote control of electronic devices, exercise physiology, physical therapy [2], neurophysiological experiments or even athlete’s and musician’s workouts. The possibility of measuring the signal on a skin surface facilitated and popularized the measuring procedure but at the same time burdened the signal processing. Many factors including the electrical conductivity of skin tissue [3] and fat layer caused the increased values of signal noise. Information that can be extracted from the signal depends strongly on the signal to noise ratio which varies dependently on many circumstances. Some of them are the type of recording device, electrodes used during the experiment, wires or wireless connectivity, skin preparation and finally, whether the recording was made on a skin surface or directly in the muscle using an electrode with needle.

For many applications it is necessary to obtain high accuracy of the muscle activity onset indication. Some of them, at the same time, demand high level of reliability. Especially those concerning human health or requiring to work in a real time. That imply the need for more advanced EMG signal processing algorithms. The vast majority of such solutions depend on several parameters, at least two of which are left to be adjusted by the end user. In general, that is the window size and some kind of a threshold value. Since it is too time consuming to manually select the optimal tuple, an automatic solution must be provided. Even though the authors usually provide some clues on how to set these parameters and what should be the optimal values, these propositions are set manually and tested only on their data. It creates space for inaccuracy and lack of reliability. This paper’s contribution is describing the application of multi objective optimization genetic algorithm (MOOGA) into the EMG onset detection field. This way scientists can adjust parameters for their algorithms automatically. As an added value of MOOGA algorithm we achieve the multi-objectivity. It provides us with a Pareto front of optimal parameter tuples which can be later picked accordingly to the application area.

Section 2 describes essentials that need to be understood in order to profit from reading this paper. It explains primary concepts of EMG signal processing and MOOGA optimization in the context of muscle onset detection.

2 Background

Muscle activity onset detection basing on EMG signals consists in pointing the precise moment in which the electrical activity starts raising in voltage value. It is related to the moment of a muscle contraction. Basing on that information we can conclude about human movements, even their exact type and moment of the event [4].

In order to detect the onset of EMG automatically various algorithms were proposed in the academia. According to Staude et al. [5] there exists four basic ways of processing the signal: a single observation, a growing test window, a fixed test windows and a sliding test window. Since EMG signals differ in voltage values, shape and other characteristics automatic estimators require setting the internal parameters. The common minimal parameter set of onset detection algorithm is a tuple of w and h. W stands for size of a window frame, that is how many neighboring measurements shall be included in the calculations of statistical factors. H is a threshold, a value that once is exceeded the onset of a muscle is reported. It was originally set by Komi et al. to be 0.03 mV [6] for the single observation.

There exist another approaches to EMG onset detection like sequential analysis, mathematical signal modelling or adaptive linear detectors [7]. MOOGA optimization allows to suit not only two parameters, thus some sequential analysis methods [8] requiring to set more input parameters might be reconsidered to be applied into the field of EMG onset detection. However, in this paper we focus on a simple, slightly modified version of Komi threshold algorithm in order to test the usefulness of automatic parameter fitting and to be able to track the whole process.

Fig. 1.
figure 1

Scheme of MOOGA algorithm adapted to onset detection

2.1 The Problem of Parameter Selection

A vast majority of EMG onset detection methods has at least two parameters left to be adjusted by the user manually. Some, statistically advanced, have even more parameters [9] which strongly depend on the signal characteristics. In order to provide a robust solution, it is inevitable to adapt some kind of automatic parameter optimization. A solution of greedy search space gives the optimal solutions but for a continuous domain of parameters it has an infinite number of possible solutions to revise what makes it impossible. Even after restricting considered parameter values to a reasonable, finite set the execution is too time consuming and is very hard to be applied to this field. A relatively good idea is to deploy a heuristic solution based on the second version of Nondominated Sorting Genetic Algorithm (NSGA-II). It proved a satisfying performance when applied to the related field of Cortical Visual Neuroprosthesis [10]. As an output of this algorithm we achieve the Pareto front - a set of parameter tuples giving the globally best possible solutions [11].

2.2 MOOGA as a Solution for the Problem

The structure of MOOGA reminds of the genetic algorithm since it is built up on it [12] (Fig. 1). The process begins with the initialization stage in which parameters are set and population is created. In the evaluation stage all previously generated candidate solutions are assessed using fitness functions. Then comes the NSGA-II sorting which finds nondominated solutions. In order to do that the sorting algorithm picks globally best solutions according to the first criterion. In case of a draw it selects only those which are not dominated, that is not worse from the others according to the second criterion. The stopping condition checks if the algorithm came to the end. The process ends whenever we reach our goal, that is when a solution we found is better than or equal to the desired one or when it has reached the maximum iteration limit. If at least one of these conditions is satisfied the algorithm ends it task by outputting the final results and correlated parameter tuples which lead to them. If not, the algorithm goes to the stage related to the genetic algorithm. Gene representation of each candidate is determined and the best ones are selected. It creates a kind of a fusion of these solutions by going through the crossover stage. During this stage all genes are divided into parts and new solutions are created by combining them. At the end of this phase a selective mutation takes place; the algorithm takes a randomly picked cromosoma with a given probability and changes its value. Mutation stage provides a factor of randomness, in order to avoid getting stuck in one place of the subspace of possible solutions. After all these steps the candidates go again through the stage of evaluation using fitness function. They are sorted and basing on the stopping condition the decision is made whether to finish the whole process or go back to the cycle.

3 Case Study

In order to revise the capability of proposed parameter optimization method a basic muscle activity onset estimator has been prepared. It consists of two basic ideas. It is built up on a simple threshold algorithm proposed by Komi et al. [6]

$$ {\text{emg}}\left( {\text{i}} \right) \, > {\text{ h }}. $$
(1)

which can be enhanced by using a sliding test window, making the solution more robust for a single voltage peaks.

$$ \begin{array}{*{20}c} {{\text{Var }}\left( {{\text{ emg}}\left( {{\text{i }} - {\text{ w}}/ 2,{\text{ i }} + {\text{ w}}/ 2} \right)} \right) > {\text{ h }}*{\text{ iVar }},{\text{ where}}:} \\ {{\text{i}} - {\text{ index}}\left( {{\text{w}}/ 2,{ 5}000 - {\text{w}}/ 2} \right),{\text{ w}} - {\text{ testing window size}},{\text{ iVar}} - {\text{ initial variance}}} \\ \end{array} $$
(2)

Thus, we decided to enhance it by a sliding test window mechanism and to replace the mean factor with more appropriate variance. We assumed that the first 100 samples of a signal do not contain the muscle activity and used it for adjusting to the specific case of each sequence. The final solution measures the variance of the first 100 samples, multiplies it by a threshold, which beside the size of a sliding test window is one of the input parameters, and compares achieved value with the variance of forthcoming sample windows. If the calculated value exceeds it a muscle activity is reported.

3.1 EMG Dataset

The electrical activity has been recorded by 6 surface electrodes placed on the Rectus Abdominis muscle. The exact description of data collection process has been described in details by Agnieszka Szpala [13] and Mateusz Magda [14]. For the purpose of this experiment 120 signals were selected. The dataset was divided into two equinumerous groups. The first has been used for adjusting the parameters and the second one - for testing. Below you can observe the format of data used in the experiment (Table 1).

Table 1. Testing dataset shape

3.2 Parameter Fitting

The parameters have been selected automatically, according to the MOOGA NSGA-II algorithm described in the Sect. 2.2 above. The EMG estimator had to be adjusted in order to fit to the procedure. We made it by leaving only data, window size and threshold as an input. The output consists of the mean error and the number of the outliers. The upper and lower bounds of window size and threshold have been set respectively to (20–80) and (5–500). In such a form the estimator could be injected into the MOOGA loop. The whole process was limited in time to one hour of a single execution and in maximal number of generations which was set to 400. Remaining parameters relevant to the genetic algorithm were set as follows: population size –80, mutation factor –0.05, probability distribution - uniform. In the last execution of MOOGA algorithm the time constraint has been removed.

4 Results

Calculating the optimal parameter tuple as described in the above section we achieved the following results. Below we present visualized the space of revised parameter tuples, their results, Pareto front of solutions taken from the last population and the histogram of final errors. At the end of this section we include a Table 2 presenting its results. The process of browsing through all possible parameter tuples was supported by MOOGA algorithm using NSGAII as a sorting method and was executed on the learning part of the dataset. The revision of those parameters, i.e. the part related with final results has been conducted using the third point of the Pareto front and was executed on the testing part of the dataset. The middle point of the Pareto front meets the requirements for both criteria. It provides us with a solution which is both accurate and reliable, giving a considerably small number of outliers.

Table 2. Results

Figures 2 and 3 are enclosed for the illustration purpose and show the work of MOOGA algorithm. They both show data taken from randomly chosen, same population. Figure 2 shows the distribution of tested parameter tuples taken from the selected population. It represents one stage of browsing the space of possible solutions. We can observe that the space of solutions was browsed uniformly in a randomized way, without leaving unrevised territories. It is crucial to ensure the proper search space exploration, especially if it is considerably large. Leaving unrevised space exposes the risk of not finding the global optimum. Below we present the results for all individuals found in the previous stage. All candidates were evaluated and their values of fitness function are presented in Fig. 3. Each individual is represented with a mean error and the number of outliers. We can observe an initial stage of Pareto front created by the four bottom points of the figure. As it is the middle stage of MOOGA algorithm the population of solutions is spread all over the figure. In the final stages all solutions converge to the Pareto front.

Fig. 2.
figure 2

Browsed set of parameters (one population)

Fig. 3.
figure 3

Space of results for solutions found during MOOGA calculation

The above Fig. 4 shows the final output of MOOGA algorithm, a Pareto front, i.e. the set of results for optimal parameter tuples. This figure shows the relation between the absolute value of mean error measured in milliseconds and the number of outliers. We can observe the necessity of a tradeoff between the accuracy and reliability that has to be made. The lower the mean error the higher the number of outliers. Some applications have a demand on a robust solution because false indications can cause hazardous situation like in case of artificial limbs or almost every real-time system. On the other side some may accept outliers in return for the highest possible accuracy as it is in case of physiological experiments in which every suspicious assessment can be revised by a specialist.

Fig. 4.
figure 4

Pareto front for threshold algorithm

Histogram shown in the above Fig. 5 shows the final results, i.e. the error values achieved using parameters selected by MOOGA. This is the illustration of how the algorithm with automatically selected parameters performs on the testing part of the dataset. Looking at the histogram we can see that a vast majority of errors are constrained within the range of (–200 ms, 200 ms) what classifies them as non-outliers. The results are grouped around the value of 0 ms. There appear only 2 outliers which is less than 3,6% of the whole population.

Fig. 5.
figure 5

Histogram of errors for testing sequence (automatic selection)

Table 2 shows the final results in a form of a summary. Results presented in it are the outcome of testing the prepared estimator, described more in details at the beginning of Sect. 3 Case Study, using the third point (parameter tuple) of the Pareto front. The algorithm was executed on the testing part of the dataset. The first column show the mean value of error. The mean error made by the estimator using automatically adjusted parameters was 15.94 ms, which is almost 4 times (370,26%) lower than 74.96 ms achieved by the same algorithm with parameters being set manually (W = 100, h = 10). In the second column we can observe an absolute value of the same error. In the third column appear the percentage of the outliers in the population of final results.

5 Conclusion

In this paper we presented an automatic solution of parameter fitting for the area of muscle onset detection based on EMG signals. We can clearly state that the automatic selection of parameters is essential for this field. EMG signals are burdened with relatively large signal noise what impedes the task of onset detection and advanced solutions must be provided in order to automatically detect the real onset of a muscle. MOOGA is a perfect solution for adjusting parameters of the onset detection algorithms. In order to test the proposed solution we chose the middle point of the Pareto front. However, we would like to point out, that accordingly to the needs, one may want to select different point from the Pareto front to meet the needs of particular application area. In this study case it revealed 4 times higher accuracy than the manual selection. Slow SNR (signal to noise) ratio is not the only obstacle in the process of extracting information from the signal. Depending on the place of the electrode placement crosstalks from surrounding muscles can also be the issue [15, 16]. It is extremely important to take it into account while measuring signal in the aggregation of various muscles, e.g. the forearm. Additionally, in case of trunk muscles cardiac crosstalks may appear in the recorded signal [17]. One must be aware of the above hindrances while processing the EMG signals.

For future improvement one can consider optimization by the recursive calculation of variance or appropriate statistical factor. Since MOOGA needs to evaluate the fitness thousands of times, it is inevitable to optimize the calculations within tested algorithm. Even though this solution proves good performance encountering global optima it is worth considering to allude the local optima like in two stage estimator [18].