||Signal Classifier - Distinguish between EMG and ECG|
Machine learning is a branch of artificial intelligence that emerged with the increase of computational power that has accompanied the evolution of technology. It allows for the computer to learn the outcome of numerous problems by exploiting the internal structure of the datasets given as input.
There are three main settings of machine learning :
1 - Import the required packagesIn order to facilitate our work, we will use the biosignalsnotebooks package, which includes multiple sample signals among other features, scikit-learn , that has an high-level implementation of a high number of methods and models used in machine learning applications, and numpy , that implements mathematical functions in an easy way.
import biosignalsnotebooks as bsnb from numpy import mean, std, zeros, diff, sign, vstack, concatenate, ravel from scipy.stats import kurtosis, skew from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import ShuffleSplit from sklearn.metrics import classification_report, accuracy_score
2 - Load sample signalsbiosignalsnotebooks Python package provides a set of sample signals that we will be using in order to train and test our model. As we want to distinguish between ECG, EMG and other types of signals, we will use multiple files.
First, we will load the ECG signal, that consists of a 20 seconds acquisition at 1000 Hz sampling rate and a resolution of 16 bits.
# Relative path to the signal samples folder path = "//biosignalsplux.com/signal_samples" # Load the ECG signal ECG = bsnb.load(path + "/ecg_20_sec_1000_Hz.h5")['CH1'] # Normalise ECG signal ECG = ECG - mean(ECG); ECG /= std(ECG)
ECG_time = bsnb.generate_time(ECG) bsnb.plot(ECG_time, ECG)