Design and Implementation ofReal-time Electrical Stimulation Artifact Suppression based on STM32

A biosignal is used as a control signal for electrical stimulation to restore weakened muscle function due to damage to the central nervous system. In patients with central nervous system damage, sufficient muscle contraction does not occur spontaneously. In this case, applying electrical stimulation can cause normal muscle contraction. However, it is necessary to remove the electrical stimulation artifact caused by the electrical stimulation. This paper describes a system design that removes electrical stimulation artifact in real time using a Cortex-M4-based STM32F processor. The STM32F is a very advantageous MCU for such DSPs, especially because it has a built-in floating point operator. Using STM32F's various high-performance peripherals (12-bit parallel ADC and 12-bit DAC, UART, Timer), an optimized embedded system was implemented.In this paper, the simulated and real-time results were compared and evaluated with the designed fir filter. In addition, the performance of the filter was evaluated through frequency analysis. As a result, it was verified that a highperformance 32-bit STM32F with floating point calculator and various peripherals is suitable for real-time signal processing


Introduction
As the modern society gradually enters an aging society, the number of patients with cerebrovascular diseases such as cerebral hemorrhage or cerebral infarction is increasing, and the number of patients with central nervous system damage such as traumatic brain injury or spinal injury due to traffic accidents or other industrial accidents is increasing.Patients with central nervous system injury have paralysis in part of the body, and in this case, peripheral nerves and muscles remain in a normal or capable state of muscle contraction. The electrical stimulation for recovering the paralyzed muscle function is called functional electrical stimulation (FES). Until now, the FES system, which is mainly used in clinical applications, is an open loop method, and the intensity or duration of electrical stimulation is operated by a set value.
This open-loop control method operates independently of the patient's will. In order to perform an effective FES, research on an FES system that uses a biological signal generated from the body as a control signal is actively underway. Representative biological signals used as control signals include electromyogram (EMG), electroneurogram (ENG), and electroencephalogram (EEG) signals that can be obtained from muscles, nerves, and brain [1]. Several studies have shown effective results in normalizing muscle movement by applying this closed loop technique [2] [3].
Currently used in clinical practice is EMG triggered FES. This is when the electromyography is applied as a control signal, the spontaneous EMG signal generated at the patient's will in the paralyzed muscle to which the electric stimulation is applied, but insufficient for muscle contraction is detected. In this case, positive effects in rehabilitation therapy have already been reported by the patient actively generating muscle contraction [4] [8]. However, this method only judges the start of electric stimulation with the detected EMG, and does not perform any treatment on spontaneous EMG while the electric stimulation is applied, so the patient cannot control the strength of muscle contraction or the interval of muscle contraction. The disadvantage is that it is made according to the set value.
An electrical stimulation method that detects spontaneous EMG signals from paralyzed muscles while electric stimulation is applied to the paralyzed muscle and adjusts the intensity of the electric stimulation according to the magnitude of the signal to induce arbitrary and natural movements has been recently studied [5]. This electric stimulator is called EMG controlled functional electrical stimulator, and Figure 1 shows the overall configuration. A problem in EMG-controlled electrical stimulation is a signal called M (Magladery)-wave or M (motor)response, which is caused when many motor units are simultaneously activated by the electrical stimulation. Since this M-wave is generally more than 20dB larger than the spontaneous EMG signal, it occupies most of the signal obtained from the EMG amplification stage. Since the frequency band overlaps the spontaneous EMG signal, it cannot be removed with a band limit filter. The comb filter, which is mainly used to extract only spontaneous EMG signals mixed with M-waves [7], cannot effectively remove M-waves whose size or shape is variable over time. In the case of such M-wave, the use of an adaptive filter that adaptively removes by tracking the amount of change shows better results [5]. Although the size and shape of M-wave varies according to the stimulation cycle, it is highly effective in using the characteristic that the spontaneous EMG signal has a low correlation to the stimulation cycle, whereas it has a fairly high correlation with the previous stimulation cycle. Can be removed. However, since the adaptive prediction error filter operates to unilaterally minimize the power of the output terminal, there is a disadvantage in that the power of the spontaneous EMG signal at the output terminal cannot be kept constant.
In this study, an adaptive filter that minimizes the output while maintaining the spontaneous EMG signal is implemented in real time using the MCU of STM32F4. And we verify the optimality of the proposed method with simulated data.

System 1. Microcontroller -STM32F407
In this paper, we designed the STM32 platform that collects data with the most recent ARM technology and high real-time, multi-parameter, high-precision, data storage direction in embedded systems. Large capacity, miniaturization and portability, multiple communication modes and long-distance development for data transmission. To meet the real acquisition system multitasking requirements, this article has described the STM32 microcontroller system of the signal acquisition system. Therefore, we designed a micro signal acquisition system based on STM32 to meet the real acquisition system multi-task requirements.
The 32-bit RISC STM32F407VGT6, used as the processor of our system, operates at 168MHZ compared to similar products, and has the characteristics of strong performance and low power consumption, real-time and low cost. The processor contains 1M FLASH, 1M SRAM, communicates using 5 serial ports including CAN bus, USB2.0 SLAVE mode and Ethernet interface, and includes 2 more RS232 ports. The system in this document uses STM32F407VGT6 serial memory.
It has an SPI bus interface that is considered temporary storage when collecting large amounts of data, and also an A/D converter that provides 12-bit resolution and the fastest conversion up to 1us at the system's 3.6V full scale. In addition to the design of the system power supply circuit, reset circuit, RTC circuit and GPIO port, it ensures system requirements and normal operation.The bock diagram is shown in figure 2. Figure 2. STM32F4 Architecture 2. EMG signal Electromyography (EMG) signals provide a very useful means of biomedical area. Research in the field of biomedical engineeringhas created a state-of-the-art, accurate active prosthesis. The biggest problem that arises while processing physiological signals is separating the desired signal from similar ones, for example M-wave [6]. The goal of this paper is to implement an easily controllable FES system that provides user feedback as well as focusing on obtaining an accurate signal from the muscles using EMG signals obtained from the extensor muscle.The EMG signal is an electrical sign of neuromuscular activation, which is an electrical manifestation of neuromuscular activation, which represents the current generated by the flow of ions across the membrane of muscle fibers that propagate through the surrounding tissues and reach the sensing surfaces of electrodes located in the environment. EMG measures the amount of discharge in muscle fibers, thus quantifying muscle contraction and relaxation. EMG signals are recorded using electrodes placed on the muscle. The quality of the EMG signal measurement is highly dependent on proper skin preparation and electrode placement, and is necessary to improve the adhesion of the electrodes, especially in humid conditions or sweaty skin types and/or conditions of dynamic movement. Special abrasives and conductive cleaning pastes/gels are available that exfoliate and clean the skin from dirt and sweat. The electrode we used is a pre-gelled surface electrode.Since EMG signals have a lower amplitude compared to other peripheral signals on the skin surface, it is necessary and convenient to detect them in a differential configuration. In this differential configuration, the shape and area of the sensing surfaces and the distance between the sensing surfaces are important factors as they affect the amplitude and frequency components of the signal. The differential arrangement acts as a comb band pass filter for the electrical signal visible on the sensing surface. In fact, if you set the detection surface spacing so as not to alias the EMG signal, the spectrum of the EMG signal should fit the bottom of the bandpass filter. For practical purposes, the differential electrode works. The frequency distribution and bandwidth of the spectrum are affected by the distance between the sensing surfaces. At least one neutral reference electrode must be placed per subject. Normally they are not electrically affected, but close areas such as joints, bone areas, bangs, etc. are selected. We also prepared the skin for the reference electrode and used an electrode diameter of at least 1 cm. EMG signals are recorded using electrodes placed on the muscle. Electrical activity measured by each muscle electrode and ground electrode is transmitted to the amplifier.

Experiments and Results
The EMG signal was obtained from a SEMG electrode attached to the subject's arm and the recorded EMG signal is fed directly to a filtering circuit where all unwanted artifacts are removed and the signal is amplified according to the readable range of the controller. When the signal is filtered, the recorded continuous EMG signal is supplied to the digitized analog-to-digital conversion circuit, and then the digitized EMG signal is supplied to the controller of the STMF407VGT6 for analysis, removing the M-wave through digital signal processing, and detecting only the EMG signal. It's possible. And it generates a pulse train corresponding to the electric stimulation intensity according to the magnitude of this EMG signal.

Conclusions
Since EMG signals contain valuable information about the nervous system, the main purpose of this study was to measure the EMG signal to control the onset, intensity, and termination of electrical stimulation. Through this study, EMG signals and M-waves were clearly distinguished, and signal processing was successfully implemented using the STM32F407 microcontroller. In this study, STM32F4 MCU was used to remove Mwave. M-wave and voluntary EMG signals were tested using simulated data and actual patient data. In both cases, the results of removing the M-wave while maintaining the voluntary EMG signal were confirmed. In addition, the false-positive rate was used to quantitatively confirm the degree of M-wave removal and the maintenance of voluntary EMG.If FES, which is controlled by voluntary EMG signal in real time, is applied to patients with central nervous system damage, it may be helpful in functional aspects or rehabilitation.While implementing the hardware interface, it has been observed that the use of other reconfigurable devices such as FPGAs and PLDs improves the results more efficiently.This paper designed a system that collects and filters real-time EMG signals.For signal, ADC built in STM32F407 was used, and for EMG signal, a self-made analog system was used.The proposed system gave almost the same results as the simulated data in MATLAB.As a result, we implemented a system that enables low cost and high sensitivity data collection.