According to the WHO, Heart disease is major part of deaths among the adults, and the treatment is very expensive which is not affordable by the poor people, So what if we try to build one using cheap products yet satisfying results.
The aim of this project is to develop a functional and cost-effective device that can detect heart patologies. This device will allow people to diagnosis their heart themselves which is both cost-effective and easy.
Solution:-
We are proposing to build a small yet effective and low-cost portable device, which can do ECG in real time. It consist of a main board with high processing power (like the STM32F429ZI) to read the ECG signal and a Raspberry Pi Display to show the Real-time results of the analysis.
Nowadays ECG equipments are both expensive and bulky. They are designed to output highly reliable clean pulses of the heart. Our device is designed for as we say a FIRST-AID KIT that is helpful in emergency situations, furthermore the output signal will be analyzed by a software, the data do not need to be clean & in detail in emergency. By Simply downgrading some level of detail & filtering, the device becomes portable. Voila.......
This will allow ECG to be easily & remotely done simply by powered using batteries or even if available renewable energy sources (ex:- solar, wind etc) due to its low power consumption.
Working:-
The AD8232 ECG Module has leads which can be connected to the patient body. This leads measure the spikes in voltage levels in the body as the heart beats which is related to heart behaviour. The signal we will receive will be amplified and measured with the help of ADS1115 Analogue to digital converter.
After that the digital data will be processed by the STM32F429ZI microcontroller. The microcontroller will be running a simple neural network, previously trained on Google Colab with an extensive dataset, that will analyse and try to classify the heart signal, and will detect possible problems based on the signal.
In Future we will also have visual representation of received data in addition of the output of the neural network, for the patient/doctor to view the results of analysis.
Design:-
The design of the Project is shown below in the image.
Firstly we have to obtain and amplify the pulse signal of the ECG so that the microcontroller will be able to read it. Before sending it to the microcontroller the signal is converted in digital data with the help of ADS1115 Analogue to Digital Convertor. Once the data is converted in digital data the microcontroller will send it to the Raspberry Pi, where the neural network running on it will extract the parameters and generate a result based on the input.
ECGTheory:-
Electrocardiography is the process of producing an electrocardiogram (ECG or EKG. It is a graph of voltage versus time of the electrical activity of the heartusing electrodes placed on the skin. These electrodes detect the small electrical changes that are a consequence of cardiac muscle depolarization followed by repolarization during each cardiac cycle (heartbeat). Changes in the normal ECG pattern occur in numerous cardiac abnormalities, including cardiac rhythm disturbances (such as atrial fibrillation and ventricular tachycardia), inadequate coronary artery blood flow (such as myocardial ischemia and myocardial infarction), and electrolyte disturbances (such as hypokalemia and hyperkalemia).
In a conventional 12-lead ECG, ten electrodes are placed on the patient's limbs and on the surface of the chest. The overall magnitude of the heart's electrical potential is then measured from twelve different angles ("leads") and is recorded over a period of time (usually ten seconds). In this way, the overall magnitude and direction of the heart's electrical depolarization is captured at each moment throughout the cardiac cycle.
There are three main components to an ECG: the P wave, which represents the depolarization of the atria; the QRS complex, which represents the depolarization of the ventricles; and the T wave, which represents the repolarization of the ventricles.
During each heartbeat, a healthy heart has an orderly progression of depolarization that starts with pacemaker cells in the sinoatrial node, spreads throughout the atrium, and passes through the atrioventricular node down into the bundle of His and into the Purkinje fibers, spreading down and to the left throughout the ventricles. This orderly pattern of depolarization gives rise to the characteristic ECG tracing. To the trained clinician, an ECG conveys a large amount of information about the structure of the heart and the function of its electrical conduction system. Among other things, an ECG can be used to measure the rate and rhythm of heartbeats, the size and position of the heart chambers, the presence of any damage to the heart's muscle cells or conduction system, the effects of heart drugs, and the function of implanted pacemakers.
Theory&ImplementationOfNeuralNetworks:-
First we have to create a neural network in ADA. For training of the Neural network, we should have an "input.dat" file with the appropriate configuration, inputs to the neural network, as well as the expected outputs. The necessary parameters in the code should be configured in the "config.adb" file, for example number of layers of the network, the number of inputs and outputs, size of each layer etc. As a output, it will generate a "weights.dat" file with the weights for each neuron, which is necessary for the execution of neural network in the EDGE case. Right Now, it is processing over the cloud.
We have to provide basic functions for the neuron body and the neuron actuator, the summation and the sigmoid functions. The system was designed such that more functions can be included and easily configured for the network.
The library is located inside the "neural-network-lib" folder. The training of the network in the project inside the folder "neural-learning". The example of the production mode of the neural network can be found in the folder "example-run-net", which also includes an implementation of the Fast Fourier Transform, obtained from https://rosettacode.org/wiki/Fast_Fourier_transform#Ada, which we found very useful for the treatment of input signals to the neural network.
Microcontroller:-For the STM32 board, modifications had to be made to the Fast Fourier Transform code, due to returning unconstrained elements and the intensive use of recursiveness.
We developed a console module, using the USART, to view the results on screen and send them to the Raspberry Pi module, using the PA2 and PA3 pins. USART reading is developed through interruptions. It can be found in the file "console.adb".
the use of the ADC is to obtain the information of the heartbeats, to analyze them and to send them to the neural network. The ADC device of the board has been configured on the pin PA4, with a resolution of 12 bits, converting the input to a value between 0V and 3.3V. It is in the file "ecgreader.adb".
Once the input is between 0v and 3.3V, Fast Fourier Transform is applies to the signal, and then the module. From this result, it extracts some parameters from the signal, which will be used later as input to the neural network.
Minimum, Maximum, Variance, Mean, HaPo (frequency which divides the spectrum into two parts)
Program execution Sequence is:
- Initialization of the console, the ADC and the neural network.
- Reading ECG data
- Processing The recieved Data
- Execution of the neural network
- Sending the neural network output and ECG data to the Raspberry Pi
time delay of 20ms is there while calculating the next input.
Implementation:-For Displaying the data on the screen a python script is written. The script will get the data from the serial port, filter it using scipy and then plot using matplotlib.
A lowpass filter in applied because of the noise comming from the main AC supply. This affect the Output Signal of the ECG.
The results are good but not the best, Well it's just a prototype and doing great.
Comments