Algorithm for Onset/Offset Detection of EMG Signals for Real-time
Control of a Low-cost Open-source Bionic-hand
Sandra Rodrigues
1
and Milton P. Macedo
1,2 a
1
Instituto Politécnico de Coimbra, ISEC, DFM, Rua Pedro Nunes, Quinta da Nora, 3030-199 Coimbra, Portugal
2
LIBPhys, Department of Physics, University of Coimbra, Rua Larga, 3004-516 Coimbra, Portugal
Keywords: Electromyography (EMG), Onset/Offset Detection, Algorithm, Real-time Control.
Abstract: This work was carried out as part of a project to develop a low-cost open source bionic hand using
electromyographic (EMG) signals. Probably the most important task for the success of this bionic hand is to
achieve a correct determination of muscle activation intervals. In this paper it is presented an algorithm for
the detection of Onset/Offset to be executed in an Arduino UNO. The aim of this algorithm is to be executed
in this ATmega328 microprocessor with a 16 MHz clock speed and 32 kBytes of memory in order to
accomplish with effectiveness the real-time control of the bionic hand. The tests performed up to its
application in real-time detection of muscle activation will also be described. The preliminary results
presented show a 100% success rate in most gestures performed by the bionic hand but with the occurrence
of a few false activations.
1 INTRODUCTION
With the purpose of using EMG signals for the
control of a bionic hand there is an absolute need of
an algorithm that is able to make a correct
identification of time windows in which the muscle
activation occurs. The hardware platform is
continuously acquiring a EMG signal and it is
demanded that in real-time, i.e., as soon as possible,
following the muscle deactivation, it is detected.
Additionally it has to save the data regarding the
whole time interval of muscle activation in some way
in order to afterwards complete the execution of the
correct action. This work is focused on the
implementation of one algorithm for onset/offset
detection but facing these constraints, with the aim of
using a low-cost microcontroller, Arduino Uno, as a
standalone controller of a bionic hand. Regarding this
real-time application, in a certain sense, the requisites
for the algorithm are more demanding, as well as
limitations in memory space and processing speed of
the hardware platform, has to be considered.
Several methods are available in literature for
onset/offset detection, i.e., for the determination of
time intervals in which the muscle is active, using
different definitions of thresholds to find the
a
https://orcid.org/0000-0003-0595-5298
beginning and end of a muscle activation, considering
a single threshold of signal amplitude, based on a
deviation from the baseline of three times the
standard deviation (Di Fabio, 1987), or using a double
threshold (Bonato, 1998). It is also described in
literature a method that detects muscle activity onset
using the energy of the signal which increases with
the start of the contraction (Rasool, 2012).
However these methods are general purpose in the
sense that the acquisition of EMG data is performed
previously. The need to carry out real-time control of
the bionic hand imposes a number of additional
requirements also on algorithms for data acquisition,
particularly in respect to onset/offset detection. In the
literature there are examples of algorithms developed
for similar applications, but in some cases it is
required that the processed signal is known a priori.
To implement an algorithm independent of the a
priori knowledge one option was to focus onto the
Teager-Kaiser Energy Operator (TKEO), which puts
in evidence the instantaneous increase of the action
potential and reduces the baseline noise (Li, 2007)
(Gentile, 2017). A threshold algorithm was then
implemented in TKEO’s domain for detecting muscle
activity, taking into consideration the minimum
period of muscular activity, the minimum period of
muscle inactivity and the margin of accuracy in the
872
Rodrigues, S. and Macedo, M.
Algorithm for Onset/Offset Detection of EMG Signals for Real-time Control of a Low-cost Open-source Bionic-hand.
DOI: 10.5220/0010976500003123
In Proceedings of the 15th International Joint Conference on Biomedical Engineering Systems and Technologies (BIOSTEC 2022) - Volume 5: HEALTHINF, pages 872-878
ISBN: 978-989-758-552-4; ISSN: 2184-4305
Copyright
c
2022 by SCITEPRESS Science and Technology Publications, Lda. All rights reserved
estimation of such measures (Konrad, 2006) (De
Luca, 1997).
Another paper concerns with the acquisition and
analysis of EMG signals for multiple active hand
movements based on wrist-hand mobility for control
of prosthesis robotic hand (
Raurale, 2014). An EMG
hardware module had been developed but the
classifier based on Linear Discriminant Analysis
(LDA) with threshold detection approach, resulted in
a very low processing time for the pattern recognition.
In spite of the documented success of some of
these methods, the algorithm presented in this paper
is based on a previous work in which a smoothing
filter is applied to EMG signal (Russo, 2019). These
filtering is achieved through a derivative component
that evidences the largest variations discarding the
signal noise. These enables the more efficient
application of a single threshold as higher frequencies
of the signal were suppressed.
2 METHODS
The algorithm was initially tested in Matlab using
previously acquired data from EMG signals. Later,
the code had to be adapted in order to be executed in
an ongoing data acquisition. To face the difficulty in
carrying out its debug, there was an intermediate step
of executing the algorithm in Arduino Uno through
the Arduino IDE platform with visualization of the
acquired signals in Opensignals. At this stage, for the
sake of ease in debugging, signals were acquired from
the accelerometer module of BITalino, whose shape
it was possible to adjust in a simple way. Through
Arduino's serial monitor, it was possible to follow the
values of some flags used for debugging, which were
complemented by the visualization of signals in
Opensignals. At this stage, the accelerometer signals
were acquired in parallel by Arduino UNO and a
BITalino. Through these, it was possible to improve
the code, identifying and correcting errors in the
algorithm and debugging the code until the conditions
for the independent execution of the code in Arduino
UNOo were created.
3 ALGORITHM
The initial code of the algorithm was developed in
Matlab, based on data smoothing previously
described in the literature (Russo, 2019). Three
parameters were defined that must be previously
adjusted in order to optimize the efficiency of
onset/offset detection. These parameters together
with auxiliary flags allow to control the flow of
execution of the different routines.
Figure 1 shows the data of an EMG signal
acquisition in which three muscle activations are
identified. Green and red markers corresponding to
onset and offset detection, respectively, are also
represented. These markers are obtained from each
raw-data from EMG sensor, which is computed in
order to calculate the difference from the previous
value. The average of an amount of these values
defined by the parameter arraySize is the key value
for the application of a threshold, defined by a second
parameter, activation, from which it is compared in
order to detect firstly the onset in upward direction
and offset in downward direction.
These markers do not delimit muscle activation,
and it is necessary to establish the time when
activation starts, with the help of First_onset_flag, as
well as the time when muscle activation ends. In this
case, Last_offset_flag is used, defining a period of
time that must elapse since the previous offset, using
the third parameter, DesactDelay. The description of
the various flags used for this flow control is
presented in table 1.
Figure 1: EMG signal acquisition with onset and offset
markers, green and red, respectively.
The parameter arraySize imposes the degree of
smoothness as it raises when the average is calculated
over a larger amount of values of EMG signals.
Consequently it also influences the sensitivity of the
algorithm in onset/offset detection as a greater
smoothing of the signal reduces its fluctuations and
the number of times it crosses the threshold value.
The activation parameter, on the other hand, has a
direct action in the detection of the onset/offset, as a
lower threshold value implies a more frequent
recognition of a variation as an onset, that is, it
increases the sensitivity of the algorithm. It is
important to be clear that this threshold is applied to
the smoothed signal instead of raw EMG signal. In
EMG signal amplitude (a.u.)
Algorithm for Onset/Offset Detection of EMG Signals for Real-time Control of a Low-cost Open-source Bionic-hand
873
Table 1: Description of the flags used for flow control.
F
la
g
Description
Init_flag
To avoid onset detection for the first data acquisition owing to a large
difference to previous value
State_sign Identification that an onset is already active
First_onset_flag Signals the occurrence of a first onset and starts time counting
Last_offset_flag
Activated when the defined time interval has elapsed from the last offset with
no onset between
Figure 2: Overall schematic of the algorithm.
short, these two parameters act to detect the
onset/offset that occurs multiple times during a
muscle activation. On the other hand, the
DesactDelay parameter will only act to identify the
end of muscle activation, as it sets the time that will
have to elapse after an offset, without the following
onset, so that it is considered as the end of muscle
activation. Therefore, it also influences the
determined instant for muscle relaxation.
Figure 2 illustrates the overall schematics of the
algorithm from the initializations of the flags listed in
Table 1 through the specific code in the first time slot
in order to avoid false activation and the function to
calculate the smoothed values to the function for
onset/offset detection that is described in detail in
Figure 3.
Figure 4 shows the muscle activation intervals
obtained with this algorithm for the acquisition of
EMG signals shown in Figure 1.
As can be seen, the values of the three parameters
are shown in the figures. To illustrate the effect of the
DesactDelay parameter, through the observation of
figure 5, it can be seen that decreasing its value by
100 milliseconds (250 instead of 350), the instant of
time obtained for muscle relaxation then shifts to the
left. In this case, it has no other effect, namely in
determining the moment of muscle activation and
sensitivity in detecting onset/offset.
But with smaller values of this parameter, several
false activations can be identified within a single
muscle activation. It is important to adjust this value,
taking into account the type of signal that is acquired,
namely the frequencies present in that signal.
So, for example, when an application is made for
the acquisition of accelerometer signals, this
parameter must be the used with a different value than
from EMG signals.
Figure 6 is intended to illustrate the effect of the
other two parameters. In (a) and (b) the arraySize
parameter has been reduced by 100 units, that is, the
signal smoothing is weaker, since the average value
of the differences between consecutive values of the
EMG signal is calculated for a smaller amount of
values.
As a consequence, fluctuations in this mean value
increase, making the algorithm more sensitive to
fluctuations in the EMG signal. This fact is
responsible for the identification of a false muscle
activation.
WHC 2022 - Special Session on Wearable HealthCare
874
Figure 3: Schematic of the function OnsetOffsetDetection of the algorithm.
Figure 4: EMG signal acquisition with lines showing the
start and end of muscle activation, green and red,
respectively.
In (c) and (d) it is possible to observe the effect of
reducing the activation parameter value, which is the
threshold value, i.e., the minimum value of the
smoothed EMG signal to be considered as an onset.
The time interval of muscle activation has no
variation, but there are several false activations, as
this threshold value was not adjusted in accordance
with the amplitude of the oscillations that occur in the
baseline of the signal. It is important that this
adjustment is made taking into account the noise
present in the acquired signals.
Figure 5: Same EMG signal acquisition using a lower value
of DesactDelay parameter (250 instead of 350).
Finally, looking at (a) and (c), and comparing with
figure 1, it can be seen that, as expected, the amount
of onset/offset detections during the three muscle
activations has suffered an significant increase as the
two parameters, arraySize and activation, were
reduced.
EMG signal amplitude (a.u.)
EMG signal amplitude (a.u.)
Algorithm for Onset/Offset Detection of EMG Signals for Real-time Control of a Low-cost Open-source Bionic-hand
875
Figure 6: Same EMG signal acquisition using a lower value of: (a) and (b) arraySize parameter (150 instead of 250); (c) and
(d) also of activation parameter (0.1 instead of 0.2).
4 REAL-TIME APPLICATION
After testing the algorithm offline in Matlab, it was
necessary to find a platform capable of providing a
correct environment for its transition to the
application of the algorithm in real-time control of a
bionic hand, executed by a standalone Arduino Uno.
As shown in figure 7, previous tests were performed
with the accelerometer module of BITalino, due to its
greater ease in data analysis. These data were
acquired in parallel by Arduino and BITalino,
enabling the simultaneous visualization of the
acquired data, using the Serial Monitor and Serial
Plotter, in the first case, and Opensignals, in the
second case.
Through the correct use of the flags, already
presented in table 1, for the control of the algorithm's
flow, it was possible to obtain a satisfactory success
in the detection of the onset/offset of activations with
the accelerometer sensor.
Subsequently, the necessary adaptations were
made to the code for the acquisition of data from the
EMG sensor, namely in determining the values of the
three parameters described above. Furthermore,
although the sampling rate is adjustable, in these tests
a cycle time of one millisecond had been used. Both
in the selection of this value and in the arraySize
depth, there are constraints imposed by Arduino
Uno's limitations, which were met, but did not
prevent the successful application of this algorithm,
as shown in table 2, for the detection of muscle
activation when random gestures are performed for
the control of a bionic hand.
Figure 7: Schematic of previous tests setup. First with
accelerometer (A) and afterwards with EMG module (B).
0 2000 4000 6000 8000 10000 12000 14000
Time (ms)
350
400
450
500
550
600
650
700
750
[arraySize; DesactDelay; activation]=[150; 250; 0.2]
0 2000 4000 6000 8000 10000 12000 1400
0
350
400
450
500
550
600
650
700
750
[arraySize; DesactDelay; activation]=[150; 250; 0.2]
0 2000 4000 6000 8000 10000 12000 14000
Time (ms)
350
400
450
500
550
600
650
700
750
[arraySize; DesactDelay; activation]=[150; 250; 0.1]
0 2000 4000 6000 8000 10000 12000 14000
350
400
450
500
550
600
650
700
750
[arraySize; DesactDelay; activation]=[150; 250; 0.1]
Time
(
ms
)
WHC 2022 - Special Session on Wearable HealthCare
876
Table 2: Results of success on detection of muscle
activation from random gestures.
Muscle activation rando
m
# performe
d
18
# detected 18
# not detected 0
# false activations 0
Success rate 100%
Error rate 0%
This evaluation of the success of this algorithm in
real-time muscle activation detection was carried out
using a servo-driven bionic one-hand controller
prototype, as shown in Figure 8.
Figure 8: Photo of the prototype of the bionic-hand
controller.
Additional factors were identified that may reduce
detection success such as the noise in the EMG
signals coming from electromagnetic interference,
namely that the different rotation of the servomotors
to carry out each person generates different noise.
Noise was also noted as a result of forearm movement
artifacts. Due care was taken with regard to noise
reduction by reducing the length of cables and
winding them up. Even with the conditions presented,
the results obtained for different gestures were
satisfactory, as shown in table 3.
5 DISCUSSION AND
CONCLUSIONS
Preliminary results from the application of this
algorithm in real-time detection of muscle activations
are promising. The method based on smoothing the
acquired signal from the EMG sensor, using flags in
order to identify for each acquisition the global state
of muscle activation, proved to be adequate for the
proposed objective. It is now necessary to broaden
and deepen this assessment in order to validate these
results. This will allow an optimization of the three
parameters defined in the algorithm, through a better
characterization of the factors with an impact on that
decision. In fact, the analysis performed did not
address the precision in determining the time interval
for muscle activation, which will be an important
factor in the evaluation of the proposed algorithm.
This will be a next objective, as this initial work
focused on demonstrating the applicability of this
algorithm, regarding the detection of muscle
activation in a real environment.
This work also aimed to evaluate the real-time
application of the algorithm, using a hardware
platform based on Arduino UNO, a cheap
microcontroller, as it is part of a project to develop a
very low-cost bionic hand. Thus, the level of
requirement raises, as the limitations in terms of
microcontroller performance, both in terms of
processing and memory, significantly reduce the
options in terms of algorithm. Even so, it was possible
to implement this algorithm with a sampling rate of 1
kHz, without an evaluation of the response time for
the control of the bionic hand, as this is not the
objective of this work.
The option for Micro Servo SG90 servomotors
also contributed to the low cost of the platform used.
However, it was possible to identify that they
constituted an additional source of noise, which
affected the amplitude of the fluctuations in the base
level of the signal, with the muscle relaxed,
depending on the gesture associated with the anterior
muscle activation. It is also worth remembering that,
contrary to what happens in the algorithms described
in the literature, for this real-time application of the
algorithm, the pre-processing with the use of filters
was not carried out, using the raw EMG signal
instead.
Table 3: Results of success on detection of muscle activation for the execution of different gestures.
Muscle activation Close Open Poin
t
Pinch
# performe
d
20202010
# detecteds 20 14 20 10
# not detected 0200
# false activations 1420
Success rate 100% 70% 100% 100%
Error rate 5% 30% 10% 0%
Algorithm for Onset/Offset Detection of EMG Signals for Real-time Control of a Low-cost Open-source Bionic-hand
877
Thus, given all these constraints, it will be
difficult for any algorithm to be able to determine
with high precision the time interval of each muscle
activation. Despite this, future work will be focused
on optimizing the algorithm presented in this paper,
and subsequent integration into the bionic hand
control software, in order to characterize it in terms
of the success rate in performing the different
gestures and in its response time.
REFERENCES
Bonato P., D’Alessio T., Knaflitz M. (1998). A statistical
method for the measurement of muscle activation
intervals from surface myoelectric signal during gait.
IEEE Transactions on Biomedical Engineering, 45,
287–299.
De Luca, C.J. (1997). The Use of Surface
Electromyography in Biomechanics. J. Appl. Biomech.
1997, 13, 135–163.
Di Fabio, R.P. (1987). Reliability of computerized surface
electromyography for determining the onset of muscle
activity, Physical Therapy, 67, 43–48.
Gentile, P., Pessione, M., Suppa, A., Zampogna, A., &
Irrera, F. (2017). Embedded wearable integrating real-
time processing of electromyography signals. In
Multidisciplinary Digital Publishing Institute
Proceedings (Vol. 1, No. 4, p. 600).
Konrad, P (2006). The ABC of EMG, A Practical
Introduction to Kinesiology Electromyography,
Version 1.4; Noraxon Inc.: Scottsdale, AZ, USA.
Li, X.; Zhou, P.; Aruin, A.S. (2007). Teager–Kaiser Energy
Operation of Surface EMG Improves Muscle Activity
Onset Detection. Ann. Biomed. Eng., 35, 1532–1538.
Rasool, G., Iqbal, K. (2012). Muscle activity onset
detection using energy detectors. In: Proc. of the IEEE
Engineering in Medicine and Biology Society Annual
Int’l Conf. (EMBC) (pp. 3094- 3097). IEEE Publisher,
San Diego.
Raurale, S. A. (2014). Acquisition and processing real-time
EMG signals for prosthesis active hand movements,
2014 International Conference on Green Computing
Communication and Electrical Engineering
(ICGCCEE), 2014, pp. 1-6-
Russo, P (2019). Desenvolvimento e Teste de Algoritmos
para a Extração de Características em Tempo Real a
partir de Biosinais. [Unpublished Biomed. Tech BSc,
thesis]. Polytechnic Institute of Setubal.
WHC 2022 - Special Session on Wearable HealthCare
878