Processing of EMG Signals with High Impact of Power Line and Cardiac Interferences

: This work deals with electromyography (EMG) signal processing for the diagnosis and therapy of different muscles. Because the correct muscle activity measurement of strongly noised EMG signals is the major hurdle in medical applications, a raw measured EMG signal should be cleaned of different factors like power network interference and ECG heartbeat. Unfortunately, there are no completed studies showing full multistage signal processing of EMG recordings. In this article, the authors propose an original algorithm to perform muscle activity measurements based on raw measurements. The effectiveness of the proposed algorithm for EMG signal measurement was validated by a portable EMG system developed as a part of the EU research project and EMG raw measurement sets. Examples of removing the parasitic interferences are presented for each stage of signal processing. Finally, it is shown that the proposed processing of EMG signals enables cleaning of the EMG signal with minimal loss of the diagnostic content.


Introduction
Biomedical signals as a time function are a complex electrical data measured for any living body. A special case of biomedical signals is the electromyography (EMG) potentials that reflect muscle activity. Such activity is controlled by the nervous system, and we can distinguish two typical states called contraction and relaxation of muscles. The measured EMG signal values are strongly dependent on the anatomical and physiological properties of muscles. Thus, the EMG signal includes the contribution of different tissues.
To acquire EMG potentials, the different types of electrodes used: needle or superficial have a significant impact on the muscle's signal value. When surface electrodes are used, EMG detectors collect signals from different motor units simultaneously and generate interactions between different signals. Therefore, the correctness of EMG signals becomes an essential requirement in biomedical engineering. The proper execution of test preparation, body structure analysis and normalization, minimizes the errors of measurement with surface electrodes [1][2][3]. The main reason for the interest in EMG signals analysis is the clinical diagnosis of muscle innervation deficits. On the other hand, this method mainly finds biomedical application in the rehabilitation of motor disabilities caused by neurogenic damage to the muscular system. The shapes in EMG signals provide important information regarding the diagnosis of neuromuscular disorders. The processing stages for EMG signal registration should be properly developed, and hardware implementations can be made for various EMG signals concerning applications. Nowadays, research and extensive efforts have been made in developing better algorithms, upgrading existing methodologies, improving detection techniques to reduce noise, and improving EMG signal registration accuracy [4,5]. Thus, many researchers have used different types of advanced methodologies, including Least Mean Square (LMS) filtering [6], wavelet transform, Wigner-Ville distribution, independent component analysis, empirical mode decomposition and higher-order statistics, for analyzing the EMG signal appropriately [7][8][9]. Frequency analysis is widely used for processing biomedical signals in various applications. Among them, high-order filtering and the Fourier Transform (FT), including the Short-time FT, are applied both for analysis and modelling [10]. However, it is quite important to investigate the actual problems of EMG signals analysis and justify the accepted measures because the technology of EMG recording is relatively new. There are still limitations in surface electromyography (sEMG), and there is no general approach for different muscle signal registration. Recent advances in signal processing and mathematical models have made it practical to develop advanced EMG detection and analysis techniques. The primary function of the electrodiagnostic system is to record biological signals faithfully. To this end, it is important to have an optimal 'signal to noise ratio', i.e., amplify the neuro-physiological signal voltage while attenuating background noise. This is done using analog hardware and digital signal processing techniques. Many EMG control systems are currently available in the market, for instance, NeuroTrac ® MyoPlus2 [11] or Baseline Load Cell MMT [12]. The full list of modern electromyographs is available at [13]. However, these EMG acquisition systems allow the processed data to be obtained based on implemented algorithms. Generally, the descriptions of the applied algorithms are not available. According to the authors' knowledge, there is no completed analysis of the applied signal processing algorithms in such acquisition systems or estimation of their efficiency.
Electromyography is a diagnostic procedure that evaluates muscle health conditions and the nerve cells that control them. These nerve cells are known as motor neurons. They transmit electrical signals that cause muscles to contract and relax. An EMG translates these signals into graphs or numbers, helping doctors to make a diagnosis [14].
A doctor will usually order an EMG diagnostic test when a patient is showing symptoms of a muscle or nerve disorder. These symptoms may include tingling, numbness, or unexplained weakness in the limbs. EMG results can help the doctor diagnose muscle disorders, nerve disorders, and disorders affecting the connection between nerves and muscles [15].
EMG is not only used in medical diagnostic procedures. It is also utilized as a gesture recognition tool that enables human physical activities to be entered into a computer, so as a human-computer interaction form [16]. Moreover, there are attempts to use EMG as a control signal for electronic mobile devices [17,18], prosthesis [19], and even flight control systems [20,21]. An interface device based on an EMG can be widely used to control moving objects, including an electric wheelchair [22]. This may be particularly useful for people with limited abilities to use the joystick. There are proposals to use surface EMG measurements to control video games [23]. EMG is also a tool used for diagnosing the impact of a technical device on a patient. This application of EMG is used by engineers designing rehabilitation devices [24][25][26]. Another very interesting application of EMG is recognition of unvoiced or silent speech by observing the activity of muscles associated with speech apparatus [27].
This research aims to develop and analyze raw signal processing steps to develop efficient algorithms for EMG measurement. The first section provides an overview of hardware delivering measured EMG signals that are considered in this study. The second section contains the advanced EMG signal processing algorithms.

Characteristics of EMG Signals
As mentioned above, a typically measured electromyography signal originates from numerous sources, not only from the muscle's activity. Among them, there are biological, environmental, electronic, and numerical interferences. Some of them are listed below.

•
Low-frequency drift due to the input impedance of the analog system High-frequency noise generated by the digital part of electronics • Numerical noise due to the representation of the number of the recorded data and rounding • Signal distortion due to the specific digital signal processing methods applied (spectrum leakage, group delays, nonlinear phase characteristics, etc.) The interferences listed above were considered in order to develop a new effective algorithm that can be implemented in a portable EMG signal processing device.

Typical EMG Signals of the Right Abdominal Muscle
To develop an efficient algorithm of EMG signal processing, the frequency characteristics of the registered signals were first calculated. Raw signals contain a high level of low-frequency disturbances due to the very high impedance of the front analog circuit. This part of the signal's spectrum has to be removed first using high or band-pass filtering. The typical signals and their spectral characteristics are demonstrated in Figures 1 and 2.
As mentioned above, a typically measured electromyography signal originates from numerous sources, not only from the muscle's activity. Among them, there are biological, environmental, electronic, and numerical interferences. Some of them are listed below.

•
Low-frequency drift due to the input impedance of the analog system • Power line interference containing 50/60 Hz and the higher spectral components • Electro-cardiac heartbeat • Electrical contact between skin and electrodes (changeable with the movement of a patient) • Aliasing in high-frequency spectral range depending on the sampling clock • Noise of the analog electronic circuit • Quantization noise • High-frequency noise generated by the digital part of electronics • Numerical noise due to the representation of the number of the recorded data and rounding • Signal distortion due to the specific digital signal processing methods applied (spectrum leakage, group delays, nonlinear phase characteristics, etc.) The interferences listed above were considered in order to develop a new effective algorithm that can be implemented in a portable EMG signal processing device.

Typical EMG Signals of the Right Abdominal Muscle
To develop an efficient algorithm of EMG signal processing, the frequency characteristics of the registered signals were first calculated. Raw signals contain a high level of low-frequency disturbances due to the very high impedance of the front analog circuit. This part of the signal's spectrum has to be removed first using high or band-pass filtering. The typical signals and their spectral characteristics are demonstrated in Figures 1 and 2. (a) (b) Figure 1. An example of the raw EMG signal of the right abdominal muscle with high impact of 50 Hz power line and ECG disturbances, (a) raw signal, (b) after removing low-frequency spectral range using 3rd order Butterworth HP filter, fc = 2 Hz.

EMG Signal with High Impact of 50 Hz and Higher-Order Components
As expected, there is a high impact of environmental power line parasitic signal sources. It has been experimentally confirmed that the electrical contact between skin and the surface electrodes has the dominant importance in reducing this parasitic impact. The examples showing the contribution of 50 Hz and the higher spectral components are presented in Figure 2.

EMG Signal with High Impact of 50 Hz and Higher-Order Components
As expected, there is a high impact of environmental power line parasitic signal sources. It has been experimentally confirmed that the electrical contact between skin and the surface electrodes has the dominant importance in reducing this parasitic impact. The examples showing the contribution of 50 Hz and the higher spectral components are presented in Figure 2.

Superimposition of EMG and ECG Signals ct of 50 Hz and Higher-Order Components
It has already been mentioned above that the ECG signal significantly interferes with EMG recordings. This strongly depends on the type of muscles being diagnosed and the location of the electrodes attached to the skin. To evaluate the contribution of cardiac activity in the presented experiments, only ECG signals were registered first. Next, the spectrum was calculated and compared with typical EMG and ECG signals superimposed on each other (see Figures 3 and 4).

Superimposition of EMG and ECG Signals ct of 50 Hz and Higher-Order Components
It has already been mentioned above that the ECG signal significantly interferes with EMG recordings. This strongly depends on the type of muscles being diagnosed and the location of the electrodes attached to the skin. To evaluate the contribution of cardiac activity in the presented experiments, only ECG signals were registered first. Next, the spectrum was calculated and compared with typical EMG and ECG signals superimposed on each other (see Figures 3 and 4).
(a) (b) Figure 3. ECG signal measured on the right abdominal muscle, (a) raw signal (b) after removing low-frequency part using 3rd order Butterworth HP filter, fc = 2 Hz.

Superimposition of EMG and ECG Signals ct of 50 Hz and Higher-Order Components
It has already been mentioned above that the ECG signal significantly interferes with EMG recordings. This strongly depends on the type of muscles being diagnosed and the location of the electrodes attached to the skin. To evaluate the contribution of cardiac activity in the presented experiments, only ECG signals were registered first. Next, the spectrum was calculated and compared with typical EMG and ECG signals superimposed on each other (see Figures 3 and 4).    As one can notice, the spectrum of ECG and EMG signals are overlapping. The main part of the ECG signal energy lies in the low-frequency band below 20 Hz. Fortunately, the EMG data has dominant spectral components around the 40 Hz range. This allows for the reduction of the impact of ECG disturbance signal on the EMG signal.

Material and Methods
There are two types of muscles in the human body: rapidly contracting muscles responsible for precise movements and contracting ones, whose function is to maintain an upright body position. The EMG signal from fast-twitch muscles is definitely stronger than from those that are constantly tense. Therefore, the EMG measurement method is much more precise in the case of limb muscle injuries. Such diagnostics are most often performed in patients with innervation deficiencies and after injuries or ischemic episodes. Important information for the doctor is the degree of muscle damage and the disorder of its innervation. Since these areas of the body are located distal from the heart, the signal does not interfere with the electrical impulses generated by this organ when measuring muscle tones.
During the measurement, it is imperative to use a reference electrode placed in a different body area where muscle contraction activity is low. This significantly increases the accuracy of the test. EMG examination is instrumental in diagnosing the gastrointestinal and urinary system sphincter, as it enables correct diagnosis and implementation of appropriate therapy. EMG tests should be carried out in a patient-friendly environment so the patient can focus on its individual stages.
Various sets of EMG signal samples were collected from the abdominal muscles during this research. The placement of the surface electrodes is shown in Figure 5. Such a placement was chosen to visualize the significant effect of electro-cardiac activity on the recorded signals. Also, this part of the body allows the quality of the skin-electrode electrical contact to be changed easily. As a result, the different impacts of power line and environmental disturbances superimposed on electromyography signals could be observed. As one can notice, the spectrum of ECG and EMG signals are overlapping. The main part of the ECG signal energy lies in the low-frequency band below 20 Hz. Fortunately, the EMG data has dominant spectral components around the 40 Hz range. This allows for the reduction of the impact of ECG disturbance signal on the EMG signal.

Material and Methods
There are two types of muscles in the human body: rapidly contracting muscles responsible for precise movements and contracting ones, whose function is to maintain an upright body position. The EMG signal from fast-twitch muscles is definitely stronger than from those that are constantly tense. Therefore, the EMG measurement method is much more precise in the case of limb muscle injuries. Such diagnostics are most often performed in patients with innervation deficiencies and after injuries or ischemic episodes. Important information for the doctor is the degree of muscle damage and the disorder of its innervation. Since these areas of the body are located distal from the heart, the signal does not interfere with the electrical impulses generated by this organ when measuring muscle tones.
During the measurement, it is imperative to use a reference electrode placed in a different body area where muscle contraction activity is low. This significantly increases the accuracy of the test. EMG examination is instrumental in diagnosing the gastrointestinal and urinary system sphincter, as it enables correct diagnosis and implementation of appropriate therapy. EMG tests should be carried out in a patient-friendly environment so the patient can focus on its individual stages.
Various sets of EMG signal samples were collected from the abdominal muscles during this research. The placement of the surface electrodes is shown in Figure 5. Such a placement was chosen to visualize the significant effect of electro-cardiac activity on the recorded signals. Also, this part of the body allows the quality of the skin-electrode electrical contact to be changed easily. As a result, the different impacts of power line and environmental disturbances superimposed on electromyography signals could be observed. Appl. Sci. 2021, 11, x FOR PEER REVIEW 6 of 15 Figure 5. Electrodes placement in the measurement of EMG signal for the right abdominal muscle (lat. musculus rectus abdominis).
The measuring system is built of a microcontroller belonging to the dsPIC33 family, equipped with two ADS1292 analog-to-digital converters and the BM78 Bluetooth communication module. The used transducer is a specialized measuring system intended for the measurement of biopotentials- Figure 6. Each of the two ADS1292 chips allows differential measurement in two channels. Thus, the entire device enables the simultaneous measurement of four interesting areas of the patient's body. The transducers are of the delta-sigma (ΔΣ) type. They provide simultaneous sampling with 24-bit resolution. They also have built-in programmable gain amplifiers. Thanks to these parameters, it is possible to connect the measurement probes almost directly to their terminals through RC input filters, avoiding additional sophisticated amplification circuits. An important parameter of the converters is their sampling frequency, which in this particular circuit is chosen at 2kS/s. The measurement resolution of 48 nV/bit was achieved. The actual measurement parameters are greatly influenced by the probes' quality and the accuracy of their adherence to the human body. When the probes show high impedance, the interference caused by the devices located in close proximity, powered from the 50 Hz network, increases greatly. To avoid data acquisition when the probes are disconnected, the device continuously monitors the connection impedance. Thanks to the embedded forced test current mechanism, the system can measure the voltage drop caused by this current. When the measurement circuit impedance is higher than 20 kΩ, the device stops the acquisition and informs the user about the poor quality of the probe connection.  The measuring system is built of a microcontroller belonging to the dsPIC33 family, equipped with two ADS1292 analog-to-digital converters and the BM78 Bluetooth communication module. The used transducer is a specialized measuring system intended for the measurement of biopotentials- Figure 6. Each of the two ADS1292 chips allows differential measurement in two channels. Thus, the entire device enables the simultaneous measurement of four interesting areas of the patient's body. The transducers are of the delta-sigma (∆Σ) type. They provide simultaneous sampling with 24-bit resolution. They also have built-in programmable gain amplifiers. Thanks to these parameters, it is possible to connect the measurement probes almost directly to their terminals through RC input filters, avoiding additional sophisticated amplification circuits. An important parameter of the converters is their sampling frequency, which in this particular circuit is chosen at 2kS/s. The measurement resolution of 48 nV/bit was achieved. The actual measurement parameters are greatly influenced by the probes' quality and the accuracy of their adherence to the human body. When the probes show high impedance, the interference caused by the devices located in close proximity, powered from the 50 Hz network, increases greatly. To avoid data acquisition when the probes are disconnected, the device continuously monitors the connection impedance. Thanks to the embedded forced test current mechanism, the system can measure the voltage drop caused by this current. When the measurement circuit impedance is higher than 20 kΩ, the device stops the acquisition and informs the user about the poor quality of the probe connection.
Appl. Sci. 2021, 11, x FOR PEER REVIEW 6 of 15 Figure 5. Electrodes placement in the measurement of EMG signal for the right abdominal muscle (lat. musculus rectus abdominis).
The measuring system is built of a microcontroller belonging to the dsPIC33 family, equipped with two ADS1292 analog-to-digital converters and the BM78 Bluetooth communication module. The used transducer is a specialized measuring system intended for the measurement of biopotentials- Figure 6. Each of the two ADS1292 chips allows differential measurement in two channels. Thus, the entire device enables the simultaneous measurement of four interesting areas of the patient's body. The transducers are of the delta-sigma (ΔΣ) type. They provide simultaneous sampling with 24-bit resolution. They also have built-in programmable gain amplifiers. Thanks to these parameters, it is possible to connect the measurement probes almost directly to their terminals through RC input filters, avoiding additional sophisticated amplification circuits. An important parameter of the converters is their sampling frequency, which in this particular circuit is chosen at 2kS/s. The measurement resolution of 48 nV/bit was achieved. The actual measurement parameters are greatly influenced by the probes' quality and the accuracy of their adherence to the human body. When the probes show high impedance, the interference caused by the devices located in close proximity, powered from the 50 Hz network, increases greatly. To avoid data acquisition when the probes are disconnected, the device continuously monitors the connection impedance. Thanks to the embedded forced test current mechanism, the system can measure the voltage drop caused by this current. When the measurement circuit impedance is higher than 20 kΩ, the device stops the acquisition and informs the user about the poor quality of the probe connection.  Data from the converters (4 times 2 kS/s) are received by the dsPIC33 microcontroller, where they are subjected to the pipeline signal filtration. Power mains frequency 50 Hz has to be removed as do other electroactive interference, e.g., generated by heart beating excitations. The final step in data processing is calculating the RMS value of the signals as the main diagnostic parameter. The processed data is sent via the Bluetooth module to the master computer, as shown in Figure 7. Data from the converters (4 times 2 kS/s) are received by the dsPIC33 microcontroller, where they are subjected to the pipeline signal filtration. Power mains frequency 50 Hz has to be removed as do other electroactive interference, e.g., generated by heart beating excitations. The final step in data processing is calculating the RMS value of the signals as the main diagnostic parameter. The processed data is sent via the Bluetooth module to the master computer, as shown in Figure 7. The proposed processing algorithm of EMG signal consists of 3 stages, as shown in Figure 8. The first one is used for removing the low-frequency spectral band, including the ECG electro-cardiac disturbance. The comb filter reduces the impact of environmental interferences mainly generated by the 50 Hz power lines. At first, the low-frequency drift signal is removed by the Band-Pass (BP) Infinite Impulse Response (IIR) filter. In order to achieve a trade-off between effectiveness and complexity of filtering, a 3rd order filter was chosen. Next, the comb 40th order filter was implemented to reduce the impact of 50 Hz energy-line interferences. The final stage of the proposed algorithm concerns the RMS signal generation by a parameterized procedure with user-defined offset and window length.

Filtering of Low-Frequency Spectrum Components
Band-filtering is the EMG signal's main operation during recording and processing [28]. The basic problem in such processing is the reduction of the impact of superimposed parasitic disturbances. The first antialiasing filtering has to be implemented in the front analog circuit. Among numerous sources of disturbances having a significant impact on the EMG signal, the ECG (Electrocardiography) heartbeat activity is one of the most important.
The maximally flat magnitude filter was proposed in the presented research. The Infinite Impulse Response (IIR) Butterworth filters of different orders for high and bandpass processing were implemented.

Third Order High-Pass IIR Filters
To reduce the low-frequency spectral range from the recorded signals, high-pass filters were chosen and implemented using the MATLAB environment [29]. To achieve the The proposed processing algorithm of EMG signal consists of 3 stages, as shown in Figure 8. The first one is used for removing the low-frequency spectral band, including the ECG electro-cardiac disturbance. The comb filter reduces the impact of environmental interferences mainly generated by the 50 Hz power lines. Data from the converters (4 times 2 kS/s) are received by the dsPIC33 microcontroller, where they are subjected to the pipeline signal filtration. Power mains frequency 50 Hz has to be removed as do other electroactive interference, e.g., generated by heart beating excitations. The final step in data processing is calculating the RMS value of the signals as the main diagnostic parameter. The processed data is sent via the Bluetooth module to the master computer, as shown in Figure 7. The proposed processing algorithm of EMG signal consists of 3 stages, as shown in Figure 8. The first one is used for removing the low-frequency spectral band, including the ECG electro-cardiac disturbance. The comb filter reduces the impact of environmental interferences mainly generated by the 50 Hz power lines. At first, the low-frequency drift signal is removed by the Band-Pass (BP) Infinite Impulse Response (IIR) filter. In order to achieve a trade-off between effectiveness and complexity of filtering, a 3rd order filter was chosen. Next, the comb 40th order filter was implemented to reduce the impact of 50 Hz energy-line interferences. The final stage of the proposed algorithm concerns the RMS signal generation by a parameterized procedure with user-defined offset and window length.

Filtering of Low-Frequency Spectrum Components
Band-filtering is the EMG signal's main operation during recording and processing [28]. The basic problem in such processing is the reduction of the impact of superimposed parasitic disturbances. The first antialiasing filtering has to be implemented in the front analog circuit. Among numerous sources of disturbances having a significant impact on the EMG signal, the ECG (Electrocardiography) heartbeat activity is one of the most important.
The maximally flat magnitude filter was proposed in the presented research. The Infinite Impulse Response (IIR) Butterworth filters of different orders for high and bandpass processing were implemented.

Third Order High-Pass IIR Filters
To reduce the low-frequency spectral range from the recorded signals, high-pass filters were chosen and implemented using the MATLAB environment [29]. To achieve the At first, the low-frequency drift signal is removed by the Band-Pass (BP) Infinite Impulse Response (IIR) filter. In order to achieve a trade-off between effectiveness and complexity of filtering, a 3rd order filter was chosen. Next, the comb 40th order filter was implemented to reduce the impact of 50 Hz energy-line interferences. The final stage of the proposed algorithm concerns the RMS signal generation by a parameterized procedure with user-defined offset and window length.

Filtering of Low-Frequency Spectrum Components
Band-filtering is the EMG signal's main operation during recording and processing [28]. The basic problem in such processing is the reduction of the impact of superimposed parasitic disturbances. The first antialiasing filtering has to be implemented in the front analog circuit. Among numerous sources of disturbances having a significant impact on the EMG signal, the ECG (Electrocardiography) heartbeat activity is one of the most important.
The maximally flat magnitude filter was proposed in the presented research. The Infinite Impulse Response (IIR) Butterworth filters of different orders for high and bandpass processing were implemented.

Third Order High-Pass IIR Filters
To reduce the low-frequency spectral range from the recorded signals, high-pass filters were chosen and implemented using the MATLAB environment [29]. To achieve the compromise between quality of filtering and numerical complexity, the 3rd order IIR Butterworth filtering was used. The transfer function of such filters is presented by Equation (1) where: a i , b i are the filter coefficients, and z is the Z-transform variable, corresponding to the unit delay of the signal samples. The time-domain formula implemented in a DSP processor can be expressed as follows where x and y denote the samples of input and output signals of the filter, respectively. The examples of raw and filtered signals are presented in Figures 9 and 10. Table 1 contains the filters' coefficients for different cutoff frequencies. In order to ensure a low level of rounding errors, 24-bit input data should be processed using at least 32-bit fixed-point arithmetic. (1) where: ai, b i are the filter coefficients, and z is the Z-transform variable, corresponding to the unit delay of the signal samples. The time-domain formula implemented in a DSP processor can be expressed as follows where x and y denote the samples of input and output signals of the filter, respectively. The examples of raw and filtered signals are presented in Figures 9 and 10. Table 1 contains the filters' coefficients for different cutoff frequencies. In order to ensure a low level of rounding errors, 24-bit input data should be processed using at least 32-bit fixedpoint arithmetic. (1) where: ai, b i are the filter coefficients, and z is the Z-transform variable, corresponding to the unit delay of the signal samples. The time-domain formula implemented in a DSP processor can be expressed as follows where x and y denote the samples of input and output signals of the filter, respectively. The examples of raw and filtered signals are presented in Figures 9 and 10. Table 1 contains the filters' coefficients for different cutoff frequencies. In order to ensure a low level of rounding errors, 24-bit input data should be processed using at least 32-bit fixedpoint arithmetic.

Filtering of 50 Hz Signal and Higher-Order Harmonic Components
The very high impact of power line interferences with EMG signals was observed during the research. In some cases, the higher-order harmonics of the 50 Hz component had relatively large amplitudes. In order to reduce these harmonics in the EMG recordings, either comb or notch filters can be applied [30,31].

Comb Filters
The transfer function of the comb filter is expressed by Equation 3 where M depends on sampling frequency. In the developed system, f s = 2 kHz was calculated as: Parameters a and b can be chosen according to the width of the 3-dB stopband (∆f ) of the filter. The magnitude of the comb filter, raw and filtered signals, and the poles distribution on the z-plane are presented in Figures 11 and 12. Table 2 contains the values of comb filter coefficients for different widths of stopbands. To achieve the proper filtering accuracy, one can consider using high-resolution calculus with filter coefficients represented by the appropriate number of digits as presented in Table 2.  RMS signal is calculated using the moving window of the length N and the chos offset as presented in Figure 13. The window length N depends on the sampling frequen fs and should be selected as the multiple of fs/50, i.e., n = 40, 80, … for fs = 2 kS/s. Th results from the necessity of acquiring the integer number of periods of 50 Hz and t higher harmonics. It reduces the leakage problem of frequency analysis and, in con  RMS signal is calculated using the moving window of the length N and the chosen offset as presented in Figure 13. The window length N depends on the sampling frequency fs and should be selected as the multiple of fs/50, i.e., n = 40, 80, … for fs = 2 kS/s. This results from the necessity of acquiring the integer number of periods of 50 Hz and the higher harmonics. It reduces the leakage problem of frequency analysis and, in consequence, allows for a better estimation of power line disturbances interfering with the EMG signals.  RMS signal is calculated using the moving window of the length N and the chosen offset as presented in Figure 13. The window length N depends on the sampling frequency fs and should be selected as the multiple of f s /50, i.e., n = 40, 80, . . . for f s = 2 kS/s. This results from the necessity of acquiring the integer number of periods of 50 Hz and the higher harmonics. It reduces the leakage problem of frequency analysis and, in consequence, allows for a better estimation of power line disturbances interfering with the EMG signals.

RMS(j)
where: s(i) denotes the samples of input signal preprocessed by filtering, length n = 40, 80, 120, . . . , j = 0, offset, 2 offset, . . . , offset = N/k, k = 1, . . . , N. It has to be emphasized that the RMS signal recovery operates as a type of low-pas filtering depending on the length and the offset of the moving window. The longer length the stronger the low-pass filtering. Choosing the appropriate values of length and offse is a compromise between the attenuation of EMG signal, the complexity of calculus, an the overall processing algorithm's execution time. This is crucial for real-time applica tions.

Results and Discussion
In order to demonstrate the effectiveness of the proposed signal processing, severa measurements of the abdominal EMG signal were performed. Particular attention wa paid to signal processing with a relatively high influence of the 50 Hz power line an cardiac disturbances. The filtering proposed in this article has been applied to reduce th high impact of interference- Figure 14.
It should be emphasized that all the signals presented in the article were acquired b the new system developed during this research. This system is used not only to measur biopotentials, but also to stimulate muscle contraction. The proposed signal processin allows the doctor to choose the appropriate filtering depending on the type of muscle diagnosed. The system offers BP or HP preprocessing to eliminate low-frequency drif All processing is carried out in the form of the pipeline architecture. Just after pre-pro cessing, power line disturbance filtering can be implemented as the next stage in the pipe line structure. The combined characteristics of these first two steps are shown in Figur 14. It has to be emphasized that the RMS signal recovery operates as a type of low-pass filtering depending on the length and the offset of the moving window. The longer length, the stronger the low-pass filtering. Choosing the appropriate values of length and offset is a compromise between the attenuation of EMG signal, the complexity of calculus, and the overall processing algorithm's execution time. This is crucial for real-time applications.

Results and Discussion
In order to demonstrate the effectiveness of the proposed signal processing, several measurements of the abdominal EMG signal were performed. Particular attention was paid to signal processing with a relatively high influence of the 50 Hz power line and cardiac disturbances. The filtering proposed in this article has been applied to reduce the high impact of interference- Figure 14. Time-varying RMS recovery is the last step in the processing of EMG signals. The RMS curve is computed as a function of time using a moving window for an EMG signal contaminated with 50 Hz power line noise as shown in Figure 15. The moving windows may overlap and may have a user-defined length. The experience gained in these studies It should be emphasized that all the signals presented in the article were acquired by the new system developed during this research. This system is used not only to measure biopotentials, but also to stimulate muscle contraction. The proposed signal processing allows the doctor to choose the appropriate filtering depending on the type of muscles diagnosed. The system offers BP or HP preprocessing to eliminate low-frequency drift. All processing is carried out in the form of the pipeline architecture. Just after pre-processing, power line disturbance filtering can be implemented as the next stage in the pipeline structure. The combined characteristics of these first two steps are shown in Figure 14.
Time-varying RMS recovery is the last step in the processing of EMG signals. The RMS curve is computed as a function of time using a moving window for an EMG signal contaminated with 50 Hz power line noise as shown in Figure 15. The moving windows may overlap and may have a user-defined length. The experience gained in these studies confirms that the disturbance of the 50/60 Hz power line strongly depends on the quality of the electrical contact between the probes (electrodes) and the skin. Time-varying RMS recovery is the last step in the processing of EMG signals. The RMS curve is computed as a function of time using a moving window for an EMG signal contaminated with 50 Hz power line noise as shown in Figure 15. The moving windows may overlap and may have a user-defined length. The experience gained in these studies confirms that the disturbance of the 50/60 Hz power line strongly depends on the quality of the electrical contact between the probes (electrodes) and the skin. As already emphasized, depending on the position of the surface electrodes and the type of muscle diagnosed, the biopotentials resulting from the heartbeat may overlap the EMG signal. An obvious and general remark may be that the closer the electrode is to the heart, the stronger the influence of the ECG signal, which should be reduced as much as possible. The spectral bands of the ECG and EMG signals are only partially separated, as described in the introduction. Therefore, it should be taken into account that strong filtering of the low-frequency band corresponding to the heart rate may affect the EMG spectrum and consequently, alter the time-dependent RMS plot. Figure 16 shows an example Magnitu Figure 15. Example of analysis, (a) a raw EMG signal of the right abdominal muscle with high content of power line parasitic disturbances, (b) RMS-80/40 EMG signal of the right abdominal muscle with high content of power line parasitic disturbances, HP filter (f c = 10 Hz), comb 40th order filter (∆f = ±0.5 Hz).
As already emphasized, depending on the position of the surface electrodes and the type of muscle diagnosed, the biopotentials resulting from the heartbeat may overlap the EMG signal. An obvious and general remark may be that the closer the electrode is to the heart, the stronger the influence of the ECG signal, which should be reduced as much as possible. The spectral bands of the ECG and EMG signals are only partially separated, as described in the introduction. Therefore, it should be taken into account that strong filtering of the low-frequency band corresponding to the heart rate may affect the EMG spectrum and consequently, alter the time-dependent RMS plot. Figure 16 shows an example of an RMS signal received for EMG recording with a high-level ECG signal superimposed and the RMS signal after removing the low-frequency spectral band.
l. Sci. 2021, 11, x FOR PEER REVIEW 13 of 1 of an RMS signal received for EMG recording with a high-level ECG signal superimposed and the RMS signal after removing the low-frequency spectral band.  Figure 17. The RMS calculation is a type of low-pass filtering. Th window width defined for the RMS calculation affects the cutoff frequency of such a filter As a result, for a wider window, the RMS peak amplitudes and the details of the highe frequency signal decrease.

Conclusions
In this research, the advanced three-stage signal processing of EMG recordings wa presented. The IIR filtering was implemented to remove low-frequency drift, 50/60 H power line, and ECG heart beating interferences to achieve satisfactory diagnostic data The RMS signal varying in time was calculated for the user-defined window moving along the recorded samplings. The proposed algorithm consisting of the different bank Time-dependent RMS diagrams are computed in the last processing step. Selected examples of RMS curves and for the same EMG input signal for different lengths and shift values are shown in Figure 17. The RMS calculation is a type of low-pass filtering. The window width defined for the RMS calculation affects the cutoff frequency of such a filter. As a result, for a wider window, the RMS peak amplitudes and the details of the higher frequency signal decrease.
of an RMS signal received for EMG recording with a high-level ECG signal superimposed and the RMS signal after removing the low-frequency spectral band.  Figure 17. The RMS calculation is a type of low-pass filtering. The window width defined for the RMS calculation affects the cutoff frequency of such a filter. As a result, for a wider window, the RMS peak amplitudes and the details of the higher frequency signal decrease.

Conclusions
In this research, the advanced three-stage signal processing of EMG recordings was presented. The IIR filtering was implemented to remove low-frequency drift, 50/60 Hz power line, and ECG heart beating interferences to achieve satisfactory diagnostic data. The RMS signal varying in time was calculated for the user-defined window moving along the recorded samplings. The proposed algorithm consisting of the different banks of filters was successfully implemented in the portable DSP system.

Conclusions
In this research, the advanced three-stage signal processing of EMG recordings was presented. The IIR filtering was implemented to remove low-frequency drift, 50/60 Hz power line, and ECG heart beating interferences to achieve satisfactory diagnostic data. The RMS signal varying in time was calculated for the user-defined window moving along the recorded samplings. The proposed algorithm consisting of the different banks of filters was successfully implemented in the portable DSP system.
The proposed algorithm is a compromise between the quality of processing and the complexity of calculus. Removing the superimposed parasitic signals by IIR filtering leads not only to registered data improvement but to EMG signals deteriorating as well. The proposed processing of EMG signals enables cleaning up of the EMG signal with minimal loss of the diagnostic content. The algorithm is fully implemented in software using pipeline processing. One must bear in mind that the overall processing has to run in realtime on a low-power and cost-effective DSP microprocessor system. In the authors' opinion, the EMG systems have to be parameterized to choose the signal processing appropriate for a patient and his diagnosis.