This repository holds the code for an QRS complex detection algorithms based on finding the rate of change of the acquired signal and add it as a feature column. Once this feature is appende to the dataset, a binary encoding of the rate of change represents a detected QRS complex. Following this, a machine learning algorithm is trained on this mathematical model.
The signal acquired is a time-domain electrocardiagram with the y-axis being the voltage meassured in the ECG. This signal has been retreieve at a laboratory using an MP36/35 unit, performing an electrocardiogram. There are two dataset (one for training, another for testing).
The mathematical model follows two functions:
- Take the first and second derivative of the signal
- Add the absolute values of these two results.
- Transform the signal from time domain to frequency domain.
- Apply a low pass filter
- return the signal to the time domain
- Randomly select 4 windows (500 ms [approximate QRS coomplex length]) in the dataset and calcualtes their maximum values from this
- Finds the mean value from the these and stores it as threshold parameter.
- Iterates through the data and binary encodes and stores the indexes in which a QRS complex was detected.
Before applying the both the Rate of Change function and the QRS one, we clean the training dataset and create a preprocessing pipeline using sklearn. Pass the dataset into the pipeline and train a machine learning model, in this case a support vector classifier model, using the dataset.
Finally, once we have a trained model, we perform a prediction by using our second subject's dataset.
Support Vector Classifier - Training | mse | MAE | RMSE | R2 |
---|---|---|---|---|
Result | 0.000083 | 0.000083 | 0.009129 | 0.998111 |
Support Vector Classifier - Testing | mse | MAE | RMSE | R2 |
---|---|---|---|---|
Result | 0.000313 | 0.000313 | 0.017678 | 0.992211 |