Anomaly Detection and Classication of Physiological Signals in IoT- Based Healthcare Framework

Physiological signals retrieve the information from sensors implanted or attached to the human body. These signals are vital data sources that can assist in predicting the disease well before time and thus proper treatment can be made possible. With the addition of Internet of Things in healthcare, real-time data collection and pre-processing for signal analysis has reduced burden of in-person appointments and decision making on healthcare. Recently, Deep learning-based algorithms have been implemented by researchers for recognition, realization and prediction of diseases by extracting and analyzing the important features. In this research real-time 1-D timeseries data of on-body non-invasive bio-medical sensors have been acquired and pre-processed and analyzed for anomaly detection. Feature engineered parameters of large and diverse dataset have been used to train the data to make the anomaly detection system more reliable. For comprehensive real-time monitoring the implemented system uses wavelet time scattering features for classification and deep learning based autoencoder for anomaly detection of time series signals for assisting the clinical diagnosis of cardiovascular and muscular activity. In this research, an implementation of IoT based healthcare system using bio-medical sensors has been presented. This paper also aims to provide the analysis of cloud data acquired through bio-medical sensors using signal analysis techniques for anomaly detection and timeseries classification has been done for the disease prognosis in real-time. Wavelet time scattering based signals classification accuracy of 99.88% is achieved. In real time signals anomaly detection, 98% accuracy is achieved. The average Mean Absolute Error loss of 0.0072 for normal signals and 0.078 is achieved for anomaly signals.


Introduction
Physiological signals carries the information of the electrical activity taking place in parts of a human body [1]. Traditionally, this information is analysed by healthcare workers to realize the physiological condition of the patients and the analysis helps them in decision-making [2]. These decisions have far reaching consequences on diagnosis, treatment monitoring, drug efficacy tests, and quality of life. Physiological signals such as Electrocardiogram (ECG) carries information of human heart's electrical activity and its analysis helps in understanding the cardiovascular health of the patient [3]. The recording has been done by conventionally attaching the leads to the surface of human body over specific areas. The graph is then examined by expert healthcare professionals in order to identify the abnormalities or anomalies. The inclusion of compute vision technology and deep learning algorithm specifically, has made the process of ECG anomaly detection, a matter of few minutes. The significance of automated detection has been validated in this Covid-19 pandemic time when personal visits to a hospital is riskier than the problem itself. This research is an extension of our already published work where we have implemented and analyzed an IoT based healthcare system and important features from the biomedical sensor's data have been extracted by applying the signal processing techniques for anomaly detection [4].
In the recent years, Internet of Things (IoT) has emerged as one of the most essential communication paradigm [5]. IoT can connect number of sensors, people, vehicles, gadgets, and appliances together on internet and make the exchange of information easier and quicker. This exchange results in a large amount of useful data that is accessible and can be analysed for application purpose and making lives easier. IoT can assist healthcare industry due to its access to the information because of its ability to ensure connectivity. IoT applications in healthcare have helped people keep track of their medical requirements such as reminding them of appointments, keeping a check on calorie count, variations in blood pressure, a check on exercises, and many more [6]. IoT-based healthcare system field comprises of sensors, microcontrollers and other electronic devices. These devices are capable of communicating with each other. The data received from these sensors (which are mostly bio-medical sensors) is stored in cloud for analysis and monitoring done by medical professionals or attendants. Integrating the IoT structures into medical devices advances the quality and service of care for aged patients and also for children [7]. The on-body non-invasive sensors monitors the physiological activities of human body and the information is stored and analysed for the realization, detection and potential treatment of diseases. This technology can be the breakthrough in the healthcare industry in terms of quick and safe responses, less physical contact, multiple treatment options, cost reduction and most importantly availability of better healthcare to the masses.
Over the past few years, there has been a lot of advancement in the design of IoT, which is spurring the use and development of smart systems in various bio -medical related processes as well. Ultimately, it has supported the improvement of healthcare system by making it intelligent and manageable. There are a lot of examples describing the effectiveness of smart healthcare including tracking of patients/biomedical equipment, automatic identification, correct prescription of drugs for patients and monitoring of physiological parameters of patients in real-time etc. For implementation, three of the most common smart technologies available are Radio Frequency Identification (RFID), Ultra-High-Frequency (UHF) and Wireless Sensor Network (WSN). [8] In today's digital world, Artificial Intelligence especially Deep Learning algorithms have influenced every data driven field including healthcare. Deep learning algorithms have great potential to analyse the data which would assist the medical staff in perception, recognition and prediction of diseases and would also help in decision-making. According to a survey (Journal of Patient Safety, 2014), about 400,000 people have died in US due to wrong diagnosis and decision-making errors of practitioners. Deep learning algorithms can reduce the diagnosis time and cost and would also help in providing accurate treatment. Convolution Neural Network [9] has emerged as the most frequently used algorithm for extracting important features from the data mainly due to its ability to generate good quality featured trained data automatically, and requires the least data pre -processing. Recently, 1D CNNs have not only managed to achieve high -quality results over 2D CNNs while training temporal data [10], but have also shown better performance with less complexity in both the computations and the training methods. Time-series classification of patient's physiological data helps to recognise and realize the anomaly in the physiological features by learning and identifying the temporal patterns of the acquired real-time data. Temporal data has temporal abstraction and patterns and learning the important features for the classification of time series data is a problem that has been addressed by researchers in the past few years. TSC utilizes the temporal order of the data to analyze, each time the task involves human cognition [11]. All these applications make TSC a desirable algorithm for dealing with real-time data analysis. The process of classification of a time series involves labelling or assigning a cla ss to the data/time series.
In this research, design and implementation of an IoT-based health monitoring framework is presented, where real-time data from on-body sensors have been acquired and stored on cloud for the purpose of real-time monitoring as well as analyzing for the anomaly detection. The featured engineered data is then trained for timeseries classification using 1D CNN. In a case study where we have acquired some signals of bio-medical sensors for monitoring, the vital such as electrocardiogram (ECG), heart-beat and electromyogram (EMG) have been analysed as they are important indicators of physiological health. Also, the system is connected to cloud for transferring, recording and classification of healthcare data, which can assist other healthcare professionals for study purpose as well as patients to self-monitor their vitals. The implemented system is quick in generating the warnings if any anomaly is detected and classifying the type of anomaly which would make decisionmaking easier for the medical professional in treating the patient immediately.
In the remaining part of this article, we present the related study in section II, design and implementation in section III; Signal Processing of acquired data and time series cla ssification is given in section IV, based on analysis of signal data, results are discussed in the section IV. We then conclude the article in section V.

Related Work
Temporal data has temporal abstraction and patterns and learning the important features f or the classification of time series data is a problem that has been addressed by researchers in the past few years. Time series classification groups the temporal data on the basis of extracted features into classes for identification and recognition. In this research a n IoT based healthcare framework is given with real-time feature extraction and 1D CNN has been applied to learn and trained the extracted data for timeseries classification. Preprocessing and feature extraction through applying signal processing techniques would make the feature extraction process much reliable. Researchers have invested a good amount of time in analyzing signal processing techniques for the construction of a Structural Health Monitoring (SHM) for damage detection [12]. A simple Butterworth filter has been used to de-noise the signals Cross-correlation to detect the extent of damage. Detection and classification of physiological signals like ECG for heartbeat diagnosis that has utilized Discrete Wavelet Transform (DWT), and Support Vector Machine (SVM), has resulted in 98.8% classification accuracy [13]. The limitation of such work is usually the vector size. Some other aspects including security of Industrial IoT based healthcare has been explored with the inclusion of encrypted techniques like water-marking for the prevention of theft. Large amount of data collected by body sensors in IoT based healthcare should be managed properly. For this reason, Big Data analytic techniques have been introduced in healthcare organizations [14]. Deep learning algorithms have the capability for analysing big and varied datasets, as compared to machine analysis and classification methods. This is because Deep learning algorithms have the ability to avail all the available input during development process [1]. Biomedical signals including EEG, ECG, EMG etc. have been analyzed for this purpose. In another research [15][16] a healthcare system for critical patients and this system is to be operated by medical attendant/nurse anywhere. System has a smart phone application developed to operate with bio -medical sensors for acquiring the required data, and dedicated health server. Authors have collected different types of bio -signals from patients using the developed system in order to monitor and analyse the data received from bio -sensors. The designed system has its own limitation as the biometric information is being transmitted to the smartphone using Bluetooth, making it low range, and then the acquired data is sent to the dedicated health server for analysis, also an encrypted form of this analysed data is stored in t he database.
The process of classification of a time series involves labelling or assigning a class to the data/time series. As the accessibility of temporal data has been increased [17], a large number of algorithms have been proposed to deal with the classification problem. Generally, TSC can be categorized into feature based, model based and distance-based methods [11]. Most commonly feature based classification methods include discrete wavelet transform (DWT) and principal component analysis (PCA) [18]. While Markov method and hidden markov method (HMM) lies under the category of model-based classification and distance of time series has been measured by dynamic time wrapping (DTW) in some cases. Traditional methods covers assigning the labels to nearest neighbors (NN) or k-Nearest Neighbor for multivariate time series [19], in some cases combination of NN and DTW have produced good results [20]. Over the past few years with the advancement in deep Neural networks, deep learning algorithms have been introduced to solve the time series classifica tion problems. Algorithms such as recurrent neural networks (RNN) and 1-D convolutional neural networks (CNNs), have been shown to provide state-of-the-art results on challenging activity recognition tasks with little or no data feature engineering, instea d using feature learning on raw data [21]. In deep learning algorithms the Auto Encoder (AE) is an unsupervised way of learning the features of the training data [22]. It is a type of a neural network whose prime function is to reconstruct the input data as an output. By unsupervised it is meant tha t AE has the ability to learn the important input features by itself, by utilizing the non -linear mapping without even labelling the data, and then reconstruct the input data. Convolutional Auto Encoder is modified type of AE where 1D-CNN layer is integra ted to extract the important features from raw input data while 2D-CNN layer is added for image processing. As we have mentioned above that this study is specifically for 1D raw ECG data, we will focus on 1-D CNN integration with AE (CAE) in biomedical signal processing applications. AE comprises of an encoder part and a decoder part in its algorithm. The CNN layers help in compressing the input data following the convolutional layers, pooling layers and by using different kernel sizes [23]. Unlike conventional CNNs, CAE are trained to minimize the loss ratio for decreasing reconstruction error during training stages on encoder/decoder.

SYSTEM DESIGN & IMPLEMENTATION
This aim of this work is to design and implement an IoT-based healthcare system having, uniqueness as its capability to combine and enable different, yet complementary, technologies. Basically, the system we have pictured should have the ability to collect and analyze real-time signals/data a bout the physiological parameters of a patient and deliver them to a signal processing unit. It then on finding anomaly in patient's data sends alerts to a medical professional, helping patients taking active role in managing their health. Figure 1 shows the design of IoT-Based healthcare system and signal analysis in the same framework. In this system, signals from sensors connected to a patient are transferred to Arduino (NodeMCU ESP8266). NodeMCU ESP8266 is connected to PC via mini USB port. NodeMCU ESP8266 is equipped with Atmega 328 microcontroller and compatible with the Arduino IDE with wifi SoC . It belongs to the Boards Manager selection of ESP-12 family, has six extra GPIOs as compared to ESP-12E module [24].
Adafruit IO is an open source platform available for data logging with MQTT library. Sensors data is displayed and logged on to the relevant feeds which can be private and public. In public mode data can be viewed by anyone in the world connected to internet while in private mode data is viewed by the owner of the feed only, giving him required privacy. Online data is retrieved and processed in LabVIEW for anomaly detection. The Arduino is acquired in LabVIEW through NI NISA (Virtual Instrument Software Architecture VISA) and LabVIEW Interfacing For Arduino (LIFA) which is a standard for configuring, programming, and troubleshooting instrumentation systems comprising GPIB, VXI, PXI, Serial, Ethernet, and/or USB interfaces. Data is fed through serial port interface to LabVIEW for online signal processing.

A. ECG Signals:
Electrocardiogram (ECG) is the measurement of body's electrical potentials. For the measurement, contact electrodes are placed on the surface of body. There are different factors causing distortions in the measured signals including patient's movement, contact area between skin and electrodes and breathing, generally known as baseline wanderings. Baseline wanderings is a noise signals which can mask important features of ECG signal. Certain methods can be used to remove the artifacts in ECG signals, generally categorized into major two types of filtering, non -adaptive and adaptive filtering. In this paper, wavelet adaptive filtering is used for the elimination of ECG's baseline wanderings to minimize the distortion. Coefficients of the transform and filtered output have been used in order to reconstruct the signal, and then baseline-removed signal has been produced using inverse wavelet transform.

B. Heart Rate Variability (HRV):
Heart rate variability (HRV) is the measure of the variation between successive heartbeats over period of time. It relies on heart rate regulation. HRV is an important feature reflecting physiological factors and the normal heart rhythm. It also provides a n understanding of the interaction between the sympathetic and parasympathetic nervous systems. Therefore, Heart Rate Variation analysis has become a popular noninvasive tool for evaluating the nervous system and its automatic activities. [25].

C. Electromyogram (EMG) Signals:
Electromyography (EMG) is the study of neurophysiologic mechanisms of fatigue in human body muscles. It's a non-invasive tool that's helps in the measurement of the muscle's activation level in myofibrils membrane [26]. Fatigue can be seen as reduction in muscle force. Signal processing of EMG signal using frequency domain, helps in extracting important features such as its dispersion values (standard deviation (SD) and variance measures), the median power frequency (MPF), and the slope, or the rate of decrease, of the MPF. In this research all of these variables have been extracted and analysed to measure the state of human muscle fibers.

II. Wavelet Scattering Transform
The wavelet transform computes the inner products of a time series signal [27]. Transient in electrocardiogram (ECG) signal is present due to presence of Heart Beat. These transients generally are not smooth and are of short duration. Transients are precisely captured by wavelets due to its flexibility in shape and short duration. ECG time-series signals usually require higher frequency resolution as compared to time resolution because they have low-frequency component. Whereas high time resolution is required for High-frequency components in ECG because they vary quickly with time. Therefore, a multiresolution analysis method would analyze an ECG signal precisely if the ECG signal comprises of both High and Low-frequency components. In wavelet scattering, the propagation of data is done by a series of wavelet transforms, nonlinearities, and averaging. Therefore, it produces a low-variance representations of time series. Wavelet time scattering yields signal representations insensitive to shifts in the input signal without sacrificing class discriminability.

Simulation Results & Discussion
In the designed IoT based hea lthcare framework discussed in previous section, data acquisition has been done. The acquired data is filtered in the first step of analysis, which includes de -trending and de-noising of the acquired bio-signals to accurately compare the minimum threshold values already computed into the designed framework. Figure 7 shows the unfiltered ECG signal, to make it free from baseline wanderings and other motion artifacts, Wavelet transform has been used. Wavelet transform has its own significance due to its better localization properties in both time and frequency domain. Decomposition of a normal ECG signal waveform comprises of P wave, QRS complex and T wave. These are the important parameters we have located during the analysis of detected ECG signal. In order to understand the cycle for better analysis, P wave relates to the heart's atrial depolarization and the T wave corresponds to heart's ventricular repolarization.   Table 1 shows the information of located intervals and peak values which are compared to threshold normal values (stored manually) for generating medical alerts. The ECG data is received via biosignal acquisition device and stored on the cloud in 512 values per second. If the variation of LabVIEW detected particular interval is large, irregular ECG is detected. The R-R interval and QRS interval serve as important indicators of various heart diseases, such as arrhythmia.

Figure 9: Peak and Interval detection in ECG Signal
Next variable that is part of our analysis is HRV. This is variation in time between succesive heart beats and is in control of a basic part of our nervous system called the autonomic nervous system (ANS). An abnormal HRV pattern leads life-threatening cardiac diseases like arrhythmias.    HRV can be effected by other factors as well including aging and gender. Figure 12 reflects heart rate number under normal conditions. Another variable which is part of our analysis is ploting of EMG signal for detection of abnormalities. A 0.5 Hz EMG signal shown in figure 13 is acquired from bio-signal sensor and is stored on cloud for further analysis and anomaly detection. Studies have shown the significance of EMG signals analysis in the frequency domain in order to get useful intuition about muscle fiber. We have used the frequency spectrum to generate other measures associated with EMG frequency analysis. The aim is to identify and validate the frequency domain behavior of EMG signal and so to determine median, average and mod frequency parameters from the power density spectrum to get useful information about the muscle state.  The zeroth and first order coefficients are plotted in figure 19, 20. The all-scattering sequence data is passed into multiclass SVM to classify the signals. The overall 99.88% accuracy is achieved on scattering sequences over complete dataset. For second analysis on train and test data, we fit a multiclass SVM to the 80% training data and tested the model for predictions on the 20% of the test data.
There are 32 data records in the test set. The achieved accuracy is 98%. The corresponding confusion matrix is shown in figure 21.

II. Autoencoders
Another important contribution of this resea rch work is a real-time implementation of a framework, designed on the basis of LabView and Python as an add-on which produces a real time powerful signal anomaly detection system. LabView 2020 Community edition is used for implementation of Python code with Python 3.6 version. In real time scenario, an Auto encoder based deep neural network is implemented to detect the anomaly of acquired ECG signals. The model is implemented in keras and the model summary is shown in figure 22.

Figure 22: Model Summary
The model used in the classifier has simple structure of one LSTM layer with 256 followed by dropout layer with rate of 0.2. Then repeat vector followed by decoder level of LSTM layer with 256 and Timedistrubuted layer is applied. Adam optimizer is used with "mae" loss. The av erage mae loss of 0.0072 for normal signals is achieved and 0.078 is achieved for anomaly signals.

Conclusion
An IoT based healthcare framework has been designed and implemented for in time awareness of decline in physiological parameters, ultimately preventing probable loss. This system helps in improving medical services by providing a smart system capable of tracking and displaying the analysed state of patient's health using graphical representation. This information helps the doctor understand and prescribe some suitable medical treatment for immediate action.
One of the contributions in this research is extensive signal processing of acquired data from bio signal acquisition framework, in order to understand the patient's condition. Analysis has been done by detecting PR, QRS, ST intervals, R-peaks in ECG signa l, Heart Rate Variance, and standard deviation (SD) and variance measures, the median power frequency, and the slope of the Median Power Frequency in EMG signal. In the extended part of the research work of the proposed designed framework online signal anomaly detection is implemented using autoencoder. By setting reconstructed error thresholds of 0.02 in term of MAE loss, 98 % accuracy is achieved for anomaly detection. If anomaly is detected then an intensive wavelet time scattering based featured are extracted and classified by multiclass SVM with accuracy of 98.78% of 3 class ECG signals.

DECLARATION:
We declare that we will make readily reproducible materials described in the manuscript, including new software, databases and all relevant raw data, freely available to any scientist wishing to use them, without breaching participant confidentiality. *Funding: NA *Conflicts of interest/Competing interests: We have no conflicts of interest to disclose. *Availability of data and material: Three datasets are used in this research including MIT-BIH Arrhythmia Database, MIT-BIH Normal Sinus Rhythm Database and The BIDMC Congest ive Heart Failure Database. *Code availability: NA *Authors' contributions: One of the contributions in this research is extensive signal processing of acquired data from bio signal acquisition framework, in order to understand the patient's condition.
Analysis has been done by detecting PR, QRS, ST intervals, R-peaks in ECG signa l, Heart Rate Variance, and standard deviation (SD) and variance measures, the median power frequency, and the slope of the Median Power Frequency in EMG signal. In the extended part of the research work of the proposed designed framework online signal an omaly detection is implemented using autoencoder. By setting reconstructed error thresholds of 0.02 in term of MAE loss, 98 % accuracy is achieved for anomaly detection. If anomaly is detected then an intensive wavelet time scattering based featured are extracted and classified by multiclass SVM with accuracy of 98.78% of 3 class ECG signals.
Physionet.org. (n.d.). Retrieved from https://www.physionet.org/ Figure 1 Block Diagram of IoT-Based Healthcare System with Signal Processing and anomaly detection Figure 2 System Integration for Signal Analysis Figure 3 Signal processing steps in ECG analysis Un ltered ECG Signal Peak and Interval detection in ECG Signal Figure 10 Detection of QRS interval Figure 11 Peak/Interval detection in ECG Signal   Zeroth-order Scattering Coe cients Reconstruction error of Normal & Anomaly Signals