PULSE2.0: Wearable System for ECG Monitoring

79  Download (0)

Full text


1 FEBRUARY 17 2019

Done by: Adnan Albaba

Supervised by: Alexander Medvedev & Fredrik Olsson


Wearable System

for ECG






he aim of this project was to design a system capable of continuously acquiring and monitoring the ambulatory electrocardiograph (ECG) signal, which covers both rest and active physical status in both normal and abnormal cases so that any irregular heart activity can be detected and reported to the medical administrator in real time. To do so, the hardware had to be engineered according to certain requirements and

standards so that it can be used as a wearable system. On the other hand, the software had to be robust but at the same time, it had to be flexible; robust so that it does not break under heavy conditions, and flexible as it must adapt with the different sorts of noises and artifacts carried with the measurand.

This work was a part of the course “Embedded Control Systems Project” -given by Prof.

Alexander Medvedev (32) and Fredrik Olsson (35)- and the time span for this work was 10 weeks, in which every group had to submit a weekly report, present their work, demonstrate their final prototypes and write a final report.

“Frequent and involuntary myocardium contractions

are least appreciated, only by the ignorant”,

A. Albaba



How to read this report


n this report, the reader can find a general idea about the concept behind this project as well as a brief introduction to electrocardiography (ECG) in Chapter One.

A detailed description of the project from a theoretical point of view as well as technical specs of the electronics used in the project can be found in Chapter Two.

In Chapter Three, the reader can find an elaborated explanation about the

implementation phases of this project including both the hardware and the software design.

Chapter Four is dedicated for presenting the final tests performed and their results.

In Chapter Five, I discuss the final result, mention some of the practical issues that I faced during this work and draw the final conclusion out of this project.



Table of Contents


How to read this report ...3

Table of Contents ...4

List of Figures ...6

Chapter One: Introduction ...8

1.1: Objectives ...9

1.2: Electrocardiography (ECG) ... 10

Chapter Two: Project Description ... 12

2.1: Hardware ... 13

2.1.1: ADS1293 ... 13

2.1.2: ESP8266 ... 14

2.1.3: Power supply management ... 15

2.1.4: TVS Zener diodes ... 18

2.2: Software ... 19

2.2.1: Signal acquisition ... 20

2.2.2: Signal filtration ... 20

2.2.3: Features extraction ... 23

2.2.4: Graphical user interface (GUI) ... 23

2.2.5: Microcontroller & RF module ... 24

Chapter Three: Implementation ... 25

3.1: First prototype ... 26

3.2: ADS1293 configuration ... 27

3.3: RF module ... 28

3.4: Printed circuit board (PCB) ... 29



3.4.1: Schematic design ... 29

3.4.2: PCB layout ... 33

3.5: Ordering the PCBs and the SMD components ... 37

3.6: MATLAB code ... 38

3.7: Graphical user interface (GUI) ... 41

3.8: 3D design ... 43

Chapter Four: Tests and Results ... 44

4.1: Testing the functionality of the ADS1293 ... 45

4.2: Testing the ESP8266 (server/client comm.) ... 46

4.3: Testing the first prototype integration ... 47

4.4: PCB design rule check tool (DRC) ... 48

4.5: Post-soldering inspections ... 49

4.6: Serial port setup in MATLAB ... 50

4.7: Tune the factors of the filters ... 50

4.8: Computation time calculation ... 52

4.9: Code integration test... 53

4.10: Final prototype test ... 54

4.11: Quantitative evaluation of the algorithms ... 55

Chapter Five: Disscusion and Conclusion ... 59

Appendix ... 65

Bibliography ... 78



List of Figures

Figure 1: ECG of a heart in normal sinus rhythm (8) ... 11

Figure 2: ADS1293 functional diagram (9) ... 14

Figure 3: ESP8266 functional diagram (10) ... 15

Figure 4: LiPo battery (11) ... 16

Figure 5: SparkFun LiPo Charger/Booster - 5V/1A (12) ... 17

Figure 6: IC REG LIN 3.3V 250MA SOT23A-3 (13) ... 18

Figure 7: uClamp3311P (14) ... 18

Figure 8: Normal ECG (15) ... 21

Figure 9: ARDUINO IDE ... 24

Figure 10: First prototype ... 26

Figure 11: Schmartboard adapter (17) ... 27

Figure 12: ADS1293 module schematic ... 30

Figure 13: ESP8266 module schematic ... 31

Figure 14: PS and connectors module schematic ... 31

Figure 15: Main module schematic ... 32

Figure 16: Top layer ... 34

Figure 17: Bottom layer ... 35

Figure 18: Internal layer 1 ... 35

Figure 19: Internal layer 2 ... 36

Figure 20: BOM ... 37

Figure 21: Final prototype “50mm x 30mm” ... 38

Figure 22: Setup of serial port ... 39

Figure 23: Two-stage filter ... 40

Figure 24: R-wave localization ... 40

Figure 25: GUI ... 42

Figure 26: 3D design... 43

Figure 27: 3D printer ... 43

Figure 28: Circuit used for testing ADS1293 ... 46

Figure 29: Circuit used for testing ESP8266 ... 47

Figure 30: Result for the first prototype test ... 48

Figure 31: Feedback from the microscope ... 49



Figure 32: Raw ECG signal ... 50

Figure 33: PSD of the raw ECG ... 51

Figure 34: ECG signal after HPF with CF=1Hz ... 51

Figure 35: PSD for the filtered ECG ... 52

Figure 36: ECG signal after a wavelet denoising filter ... 52

Figure 37: Output signal form the filtering block ... 53

Figure 38: ECG signal with its extracted features (P, Q, R, S and T-waves) ... 53

Figure 39: Final prototype "client" ... 54

Figure 40: Output signal from the final prototype ... 54

Figure 41: Evaluation test 1 ... 56

Figure 42: Evaluation test 2 ... 57

Figure 43: Evaluation test 3 ... 57

Figure 44: Evaluation test 4 ... 58

Figure 45: Synthesized ECG with Anoise = 0.2mV ... 58

Figure 46: Synthesized ECG with Anoise = 0.1mV ... 58

Figure 47: Output signal using PULSE2.0b HW ... 61

Figure 48: Knife-cutting machine ... 63



Chapter One




1.1: Objectives


ardiovascular diseases (CVDs) have become a major healthcare problem that is exhausting the healthcare facilities around the world. On top of being the number one cause of death globally, CVDs patients are accounting for the highest percentage of hospitalized patients. In Sweden, the age-sex standardized hospital admission rate per 100,000 population for congestive heart failure is 305 (1).

One of the well-known techniques used by the cardiologists for collecting information about the structure and functionality of the cardiovascular system is

electrocardiography (ECG) monitoring. Early recognition of cardiac-related issues such as angina, dyspnea, and syncope can be critical, and CVD patients need to visit their doctors for medical tests. Electrocardiography (ECG) is highly used in hospitals and clinics for its usefulness in diagnosing heart diseases. An example of this feature is by detecting ST‐segment elevation is the ECG signal of the patient. This indication

suggests myocardial ischemia in more than 90% instances. In case of ST-depression, this indication suggests myocardial ischemia in more than 60% instances. Moreover, ECG changes also suggest abnormalities in cardiac chambers and certain drug

toxicities. Monitoring of cardiac electrical activity for long time intervals can be useful for detection of arrhythmias. “The diagnostic yield is increased by 15% to 39% by a 24‐

hour recording” (2).

Wearable technology has begun dominating the market of consumable electronic gadgets along with internet of things (IoT) as the number of connected wearable

devices worldwide is expected to jump from an estimate of 325 million in 2016 to over 830 million in 2020 (3). Moreover, wearable ECG monitoring techniques have been a hot area of research for the past decade and still. Aspects such as low power

consumption and limited resources are connected to wearable design and must be taken into consideration when designing such device.



1.2: Electrocardiography (ECG)


n electrocardiogram - abbreviated as EKG or ECG - is a test that measures the electrical activity of the heartbeat. With each beat, an electrical impulse (or “wave”) travels through the heart. This wave causes the muscle to squeeze and pump blood from the heart. A normal heartbeat on ECG will show the timing of the top and lower chambers.

An ECG gives two major kinds of information. First, by measuring time intervals on the ECG, a doctor can determine how long the electrical wave takes to pass through the heart. Finding out how long a wave takes to travel from one part of the heart to the next shows if the electrical activity is normal or slow, fast or irregular. Second, by measuring the amount of electrical activity passing through the heart muscle, a cardiologist may be able to find out if parts of the heart are too large or are overworked (4).

A normal ECG signal consists of three main components: the P wave, which represents the atrial systole contraction pulse; the QRS complex, which represents the

depolarization of the ventricles; and the T wave, which represents the recovery of the ventricles (5). It can also be further broken down into the following -see Figure 1-:

P is the depolarization of the atria

Q is associated with the deflection immediately before ventricular depolarization

R is associated with the peak of the ventricular depolarization

S is associated with the deflection proceeding the ventricular depolarization

T is the repolarization of the ventricles

A healthy heart starts the atrium depolarizing with the help of the pacemaker cells in the sinoatrial node. Then, the atrioventricular node along with the bundle of His and into the Purkinje fibers spread the contraction down and to the ventricles. After that, both ventricles repolarize. It is worth mentioning that the atrial repolarization also takes place after the contraction of the atrium, but the ventricular depolarization waveform masks it (imbedded in the QRS complex).



When it comes to cardiologists, the ECG contains a huge amount of information about the structure of the heart and the functionality of the electrical conduction system (6).

An ECG can be used to measure the heartbeats’ rate and rhythm, diagnose abnormalities of the heart such as the size and position of the heart chambers, diagnose heart attacks, the effects of heart drugs, and the functionality of the pacemakers (7).

Figure 1: ECG of a heart in normal sinus rhythm. Image from Wikipedia (8)



Chapter Two

Project Description



2.1: Hardware


s mentioned before, this project involved both hardware and software work. As a first step across this work, I had to decide which electronic chips will be used in the final prototype. The main chip (the brain of the board) is the microcontroller unit (MCU). Another important chip to be added to the system was the integrated circuit (IC) that will perform the analog processing on the measurand (ECG). The radio frequency (RF) module had to be decided along with the RF technology. Below, detailed information about each electronic part in the system.

2.1.1: ADS1293


he ADS1293 includes most of the features required in portable, low-power electrocardiogram (ECG) devices. With significantly reduced size and power, the ADS1293 produces a great performance.

Some of features of the ADS1293 are:

• Three digital ECG channels

• Digital filters

• Low-power consumption

• Programable gain amplifiers

• Lead-off detection

• Right-leg drive amplifier

The ADS1293 comes in a quad-flat no-lead (QFN) package which makes it one of the best choices for integrated solutions.

For more detailed information about the ADS1293 and its specifications, the reader can refer to the datasheet provided by Texas Instruments (9).



Figure 2: ADS1293 functional diagram. Image from TI.com (9)

2.1.2: ESP8266


he ESP8266 is a low-cost Wi-Fi microchip with full TCP/IP stack and microcontroller capability produced by Shanghai-based Chinese manufacturer Espressif Systems.

With the complete and self-contained Wi-Fi networking capabilities, ESP8266EX can perform either as a standalone application or as the slave to a host MCU. Also, ESP8266EX can be applied to any microcontroller design as a Wi-Fi adaptor through SPI/SDIO or UART interfaces.

Below, some of the features of the ESP8266:

• Tensilica 32-bit microprocessor

• 32 KiB RAM

• External flash is up to 16 MiB



• I2C and I2S interface protocols

• 16 GPIO pins

• 10-bits ADC

For more information about the ESP8266 and for its specifications, the reader can refer to the datasheet provided by Espressif (10).

Figure 3: ESP8266 functional diagram. Image from Espressif.com (10)

2.1.3: Power supply management


ower supply consumption and management is always a critical aspect when dealing with wearable systems. Since the final product will be a wearable device, therefore, it will be powered by a battery (LiPo is very common supply). For that reason, you do not want to add any power-hungry parts because that will result in the need for frequently recharge or even change the battery.

In my design, the ADS1293 analog front end (AFE) is powered by two different supply voltages (5v and 3.3v); for that I am used a 3.7v LiPo battery along with a voltage booster (up to 5v) as well as a voltage regulator (down to 3.3v).



Lithium Ion batteries are slim and light in weight batteries that are based on Lithium Ion chemistry.

Some of the features of the Lithium Ion Battery – 1Ah:

• It outputs a nominal 3.7V at 1000mAh

• Comes with a standard 2-pin JST-PH connector

• Rechargeable

• Includes built-in protection against over voltage, over current, and minimum voltage.

For more information about the Lithium Ion Battery and its specifications, the reader can refer to the datasheet provided by SparkFun (11).

Figure 4: LiPo battery. Image from SparkFun.com (11)

The SparkFun 5V/1A LiPo Charger/Booster is a very economical choice of circuit for generating one amp from a Lithium Polymer battery at 5V.

Below, some of the features of the LiPo Charger/Booster:

• MicroUSB charger 500mA

• Battery isolation switch



• LED indictors

• Enable pin

For more information about the LiPo charger/Booster and for its specifications, the reader can refer to the datasheet provided by SparkFun (12).

Figure 5: SparkFun LiPo Charger/Booster - 5V/1A. Image from SparkFun.com (12)

The MCP1703 is a voltage regulator which makes sure that the maximum output voltage will be 3.3v with 250 mA maximum output current.

Some of the features of the MCP1703:

• Typical quiescent current equals to 2uA

• Input range 2.7v – 16v

• Integrated and small package

• Short circuit protection

For more information about the MCP1703 and its specifications, the reader refer to the datasheet provided by MicroChip (13).



Figure 6: IC REG LIN 3.3V 250MA SOT23A-3. Image from MicroChip.com (13)

2.1.4: TVS Zener diodes


n this application (wearable ECG monitor), the device is to be directly connected to the patient’s body (heart is surrounded by the electrodes) putting the patient under a possible threat of being electrically shocked -since in demo mode, the prototype will be connected to the computer which is connected to the 220V power line-. For that reason, Zener diodes are added to the circuitry to prevent any current from flowing through the body and also to prevent the electronics from being destroyed by electrical static discharge (ESD).

The μClamp® series of TVS arrays are designed to protect sensitive electronics from damage or latch-up due to ESD, lightning, and other voltage-induced transient events.

Each device will protect up to six lines operating at 3.3 volts (14).

Figure 7: uClamp3311P. Image from semtech.com (14)



The rest of the electronic components are basically passive electronics such as ceramic resistors and capacitors as well as some connectors and headers.

For the sake of ending with a highly integrated device, surface mount technology (SMT) components were soldered in the final prototype.

It is worth mentioning that both the textile electrodes and the medical corset were developed before in a previous project.

Moreover, textile conductive yarns were used instead of using normal copper connectors because conductive yarns are perfect fit for wearable systems.

2.2: Software


n the other hand of this project, I had to design a system dedicated for three main functions:

1. Acquiring the raw signal from the hardware circuitry. This block will be the

connecting joint between the hardware part and the software part of the overall system.

2. Filtering the raw signal. This block will prepare the signal for the third block by filtering out the unwanted part of the raw signal, which are different sorts of noise and artifacts.

3. Extracting the features from the signal. The input for this block will be the

filtered signal. Its job is to detect and identify the main features of the ECG signal - see Figure 1 – and to store them to be used when diagnosing the patient.

Those three main blocks can be referred to as the signal processing entity. The output of this entity will be a continuously updated list of the wanted features, which can be employed in multiple ways and applications.

Another aspect that should be taken into consideration is that this system is meant to be used by the patients; end users always expect a user-friendly graphical user interface (GUI) to deal with. For that reason, a user-friendly GUI was designed.

Next, the reader can find a detailed explanation about the software part of this project.



2.2.1: Signal acquisition


fter capturing the measurand and amplifying it, the data is collected by the

microcontroller using serial peripheral interface (SPI) bus. Next, the collected data will be sent from the client to the server wirelessly using TCP/IP. Now that the data are waiting in the server, the next step would be to acquire this data to the PC and process it. For this purpose, I am using MATLAB as my software interface.

First, I thought that I should end up having the three main blocks (acquisition, filtration and feature extraction) running continuously in parallel. Turned out that MATLAB does not allow two or more loops to be run at the same time. Note that even by using the function PARFOR, the loops must be independent to each other because the iterations will be executed in a nondeterministic order. My solution was to make the acquisition loop runs for a prespecified time and therefore, performing as buffer. This was useful as it worked as a sliding window. More information about the implementation can be found in Chapter Three.

2.2.2: Signal filtration


lectrocardiograph (ECG) signal ranges in several milli Volts in amplitude. Being small in amplitude makes it hard to distinguish the features of the signal when combined with noise signals and artifacts. Fortunately, most of this noise can be filtered out using digital filters. But to use digital filters, the designer should either know the frequency characteristics of the measurand or the unwanted noise component. Bellow, some information about the frequency ranges of a normal ECG signal.



Figure 8: Normal ECG. Image from queensu.ca (15)

The normal heart usually beats in a regular rhythm between 60 - 100 beats per minute (BPM). Below, some specs for the important intervals on the ECG strip as well as their normal ranges (15).

1. P-wave:

Duration in normal condition is less than or equal to 0.11 seconds

Polarity is positive in leads I, II

Generally smooth in shape, not notched or peaked 2. PR-interval:

Duration in normal conditions between 0.12 and 0.20 seconds 3. QRS-complex:

Duration in normal conditions is less than or equal to 0.12 seconds

Amplitude is greater than 0.5 mV in at least one standard lead



Represented by a positive deflection with a large upright R, a negative deflection with a large deep S in and a negative deflection with a large deep Q leads I and II 4. ST-segment:

Isoelectric and slanting upwards to the T wave

In normal conditions, it never get depressed greater than 0.5 mm 5. T-wave:

In normal conditions, it is rounded and asymmetrical in shape

In normal conditions, its amplitude should be at least 0.2 mV 6. QT-interval:

In normal conditions, its duration is less than or equal to 0.44

As I mentioned before, the goal of this project is to monitor the ambulatory ECG - includes both rest and active physical status- in both normal and abnormal cases and for that, the criteria for detecting the features in the ECG signal were modified so that they include the abnormal cases by increasing the bandwidth of the detector window as well as stretching its thresholding region.



2.2.3: Features extraction


very critical part of the system is the block for extracting the targeted features out of the ECG signal. Since the accuracy of the diagnosis will mostly depend on the correctness of the extracted features, the criteria for detecting and identifying those features should be adaptive and reliable.

The list of wanted features in this project consists of:

1. P-wave (time and amplitude) 2. Q-wave (time and amplitude) 3. R-wave (time and amplitude) 4. S-wave (time and amplitude) 5. T-wave (time and amplitude) 6. Heart rate (HR)

7. RR-interval

This list must be updated in a frequent manner but at the same time, the features must be saved and concatenated. More details about how this block was implemented can be found in section 3.6.

2.2.4: Graphical user interface (GUI)


he graphical user interface (GUI) is usually what the end user will be dealing with when using the device. Since this system will be used for research and not as a final commercial product, the GUI should contain some buttons and numerical indicators as well as graph figure. The buttons will be used as shortcuts to perform functions (such like starting the procedure, stopping the loop, exporting the list of features to an Excel sheet or exiting the program) instead of using the command window. The numeric indicator will show the changes on the value of HR. Finally, the graph will be used to plot the filtered ECG signal along with its extracted features.



2.2.5: Microcontroller & RF module


egarding the firmware used for controlling the microcontroller, I am using the ARDUINO IDE because the ESP8266 is ARDUINO supported. Another feature for the ARDUINO IDE is that it is an open source environment meaning that it is well

resourced. Moreover, it provides the ability of using a serial monitor as well as a serial plotter which make debugging and testing handier.

Two different firmware codes had to be written for the client and server. In the client, the firmware is taking care of configuring the registers of the ADS1293, collecting the serial data output from it and sending the data through the 2.4 GHz channel

established with the server. On the other hand, the firmware in the server should take care of receiving the data from the client and buffering it to the personal computer PC using a UART to USB interface.




Chapter Three





n this chapter, I will go through the main steps of the implementation phase. The implementation phase is usually when the designer transforms his/her theoretical ideas and designs into a working prototype. It is important to know though that in my case, the reason for the implementation phase was not to deliver a final product but to proof my concepts.

3.1: First prototype


he first step was to build a first prototype -see Figure 10- that mimics the final one in behavior (response). To do that, I used a Breadboard along with through-hole

electronic components, making it easier to change and modify the circuit.

Figure 10: First prototype



Next, I performed different sensitivity tests on multiple passive electronic components and noticed the responses. Based on that, the final circuit diagram was determined. It important to mention here that the main reference for me while designing the circuit of the ADS1293 was the recommended circuit design by Texas Instruments (TI) (16).

This prototype was an essential part during the project as every single modification on the final board was tested and validated on the prototype beforehand.

One of the issues that I faced while building the first prototype was that not all the components were available in a through-hole technology form such as the ADS1293 which comes in a quad-flat no-lead (QFN) package only. The solution was basically to order a QFN to DIP adapter -see Figure 11- and then soldering the IC on it using a SMD station.

Figure 11: Schmartboard adapter. Image from Schmartboard.com (17)

3.2: ADS1293 configuration


s I mentioned before in section 2.2.5, the serial plotter and monitor were used to plot the output signal of the prototype. But before I was able to acquire any output signal, I had to configure the registers of the ADS1293. This was done using the

ESP8266 module. Knowing that the ADS1293 can communicate using SPI bus only, and that the ESP8266 supports the SPI protocol, the rest was to choose the suitable values to be sent to their corresponding addresses on the ADS1293. One can find a descriptive information about the map of the registers in the datasheet (16).



Writing the code for configuring the ADS1293 registers was not a straightforward job since TI does not provide support for ARDUINO IDE. After reading the SPI library provided for ARDUINO MCUs (18), I was able to write the code and configure the ADS1293 successfully. To test the code, I simply wrote a specific value to a specific address and then read that address. Another test was to read the preconfigured registers and checking whether their values match the default configurations that are mentioned in the datasheet (16).

The reader can find a snippet of the code in the Appendix.

3.3: RF module


ow that I was able to configure the ADS1293 AFE, the next step was to add the wireless connectivity feature to the system. This is done by programing the ESP8266 module to send and/or receive the data through the 2.4GHz channel. Fortunately, the ESP8266 (as well as all ARDUINO supported MCUs) is well documented and resourced on the internet. I watched a lot of DIY YouTube videos and learnt a lot from their experiences. I must mention that most useful YouTube channel in this regard was the one run by Andreas Spiess (19) which is dedicated for RF related modules and

programming issues.

I used the TCP/IP protocol for the radio frequency transmission and receiving.

The Internet protocol suite is the conceptual model and set of communications protocols used in the Internet and similar computer networks. It is commonly known as TCP/IP because the foundational protocols in the suite are the Transmission Control Protocol (TCP) and the Internet Protocol (IP). It is occasionally known as the

Department of Defense (DoD) model because the development of the networking method was funded by the United States Department of Defense through DARPA.

The Internet protocol suite provides end-to-end data communication specifying how data should be packetized, addressed, transmitted, routed, and received. This

functionality is organized into four abstraction layers, which classify all related protocols according to the scope of networking involved.



From lowest to highest, the layers are the link layer, containing communication methods for data that remains within a single network segment (link); the internet layer, providing internetworking between independent networks; the transport layer, handling host-to-host communication; and the application layer, providing process-to- process data exchange for applications (20) (21).

The code that I used for programming the RF module was a modified version of another code that was wrote by Ghassan Yousif (22).

The codes or both the server and the client can be found in the Appendix.

3.4: Printed circuit board (PCB)


fter testing the integrated overall circuit in the first prototype, the next step was to design the printed circuit board (PCB) to be used as a final prototype. Using the PCB, one can benefit from its small size -compared to the breadboard used for the first prototype- and deploy it on an actual wearable application system.

This part of the project was done under the supervision of Dr. Pawel Marciniewski (33) as part of the course “PC-board construction with ECAD tools”.

3.4.1: Schematic design


he next step after I decided the final circuit scheme was to redesign it using Altium Designer software. This is done as a preparation for transforming it into a PCB layout design.

A very good approach here is to break the overall design into different smaller

modules. This will make the design readable and easier to be reviewed and debugged.

In my case, the overall design consists of three modules:

1. ADS1293 module

The first module is for the ADS1293 IC and its circuitry -see Figure 12-.



Figure 12: ADS1293 module schematic

By looking at Figure 12, the reader can notice the usage of coupling capacitors (I.e. C3, C6, C7 and C8) as well as some pull up resistors (i.e. R7 and R8). The switch (S1) is used for resetting the IC. A common ground is used for the whole circuit as recommended in the ADS1293 datasheet. Also, an external 4 MHz crystal is used for my application.

Port-type of connection is used to connect between two different modules in Altium Designer (i.e. MISO and MOSI). The five input ports (IN1-5) are the five ECG leads which will be connected to the patient. The ports (SCLK, MISO, MOSI, CSB and DRDYB) are used for serial peripheral interface (SPI) communication bus. The Zener diodes (D1- 5) are used for the protection of the patient.

2. ESP8266 module

To find the best connection scheme for the ESP8266 -see Figure 13-, I checked the online forums where developers keep contributing to the developers’ society by sharing their experiences with hardware designing or programming the ESP8266. This is a good way for starting your design as it will save you a lot of time and failing

attempts (23).



Figure 13: ESP8266 module schematic

By looking at Figure 13, the reader can notice the usage of coupling capacitor (C9) as well as some pull down resistor (R12). The LED is used as an indicator for debugging.

The headers (P3, and P4) are used for in circuit debugging and programming mood.

3. Power supply and connectors module

The last schematic module consists of the main connectors and the voltage regulation circuit -see Figure 14-.

Figure 14: PS and connectors module schematic



By looking at Figure 14, the reader can notice the usage of coupling capacitor (C13 and C10). The voltage of the LiPo battery (3.7v) will be regulated to 3.3v. The header (P1) is used to connect the power supply to the board. It is also used to connect the

debugger/programmer to the ESP8266 module. The header (P2) is used to connect the ECG electrodes to the ADS1293 IC in the board.

Finally, all three modules are linked together by instantiating each module and connect its ports to the corresponding ones -see Figure 15-.

Figure 15: Main module schematic

This hierarchical approach makes it handy to use one module schematic in different modules.



Usually, the next step would be to annotate the components used in the schematic, but I assigned each component to unique value and number, so I used this step for checking if there were any mistakes in the annotation.

After that, one must check the error reporting list and the connection matrix before compiling the project.

After a successful compilation, one can generate the Bill of Materials. I prefer to do this step after finishing the PCB layout design and making sure that all metrics are chosen correctly for each component.

3.4.2: PCB layout


his is a very critical step where the designer must figure out the optimum placement of the components and the best routing for the connections. Pawel described this process as a puzzle and the designer is trying to solve it. I would like to add here that this puzzle has different solutions.

The first step when designing the PCB layout is to configure the layer stack, that is, to define the number of layers in the PCB and the width of the layers. The designer can also choose the material that will be used for manufacturing the PCB.

In my case, I used four layers; the top layer is used for most of the components, the bottom layer is used for the power supply circuitry. The first internal layer is used for the ground plan while the second internal layer is used for the power plans


The widths and the material of the layers were taken from the recommendations document provided by the supervisor.

After configuring the layer stack, one must set the layout rules. Based on those rules, and when the designer runs the design rule check (DRC) tool, the tool will generate its faults report. For this step, I did not follow the recommendations provided by the supervisor, instead, I used the rules provided by the manufacturing company because at the end of the day, the only limits here are the limitations of the machines used in the manufacturing company “JLCPCB” (24).

Below, the reader can find the layout for each layer -see Figures 16, 17, 18 and 19-.



Figure 16: Top layer

Looking at the top layer layout, the reader can notice the ADS1293 IC to the left-side of the figure, next to it (to the far left of the figure), the reader can find the header

connector for the electrodes. On the other hand of the layer, the reader can find the ESP8266 module and the power supply connector.

SMD electronic components are used to minimize the size of the board. 0603 and 0402 sizes where used for the same reason (minimizing the area used for mounting the components).



Figure 17: Bottom layer

Figure 18: Internal layer 1



Figure 19: Internal layer 2

In Figure 18, the reader can find the layout of the internal layer 1 where all ground VIAs are connected. While in Figure 19, the reader can find the layout of the internal layer 2. This layer is divided into two plans, VDD5 and VDD3.3 and in each plan, the corresponding VIAs are connected.

Another thing to notice in both top and bottom layers are the ground polygons which were poured over the corresponding pins and VIAs.

During the designing process, the designer might need to modify the shape of the board; thanks to Altium Designer, this can be done at any time before generating the fabrication files.

After finishing the placement of the components, connecting them and pouring the polygons, the designer can run the design rule check (DRC) tool.

One more thing I would like to mention here is that I have modified the PCB layout design. The modified version’s size was reduced to nearly the half. The new design will be tested in my next project.



3.5: Ordering the PCBs and the SMD components


he final step after checking up the overall design is to generate the fabrication files of the design -see Figure 20-. These files are used for aiding the machines in the

production process of the printed circuit boards. These files are usually two packages of files, the first package is the Gerber files. The second package is the NC Drill files.

Altium Designer provides the CAMtastic tool to preview the fabrication files. The last thing to do before sending the fabrication files to the manufacturing company is to check the CAMtastic viewer for any overlap between pads in the Solder Mask.

Regarding the electronic components, one can upload the bill of materials (BOM) to one of the electronics providers (such as DigiKey (25)) for ordering the whole list of components.

Figure 20: BOM



The next step was basically to assemble the final board -see Figure 21- by soldering every SMD component to its corresponding footprint on the PCB.

Figure 21: Final prototype “50mm x 30mm”

3.6: MATLAB code


he other half of this project was to design an interface for acquiring and processing the output signal form the board. This interface must plot the filtered signal for demonstration purposes.

The first step here is to serially read the data received by the server, which is hooked to the PC via a UART to USB connection. To do that, I had to configure a serial port in MATLAB and then open that port and scan its buffer. I used the functions provided by the MATLAB instrument control toolbox -see Figure 22-. The reader can refer to the MATLAB script in the Appendix.



Figure 22: Setup of serial port

After I start reading the serial port, I setup the figure in which the filtered signal will be plotted. Then, I declared the variables along with the flags used in the code. The

interface consists of three main blocks or loops; data acquisition, signal filtering and feature extraction (signal processing) and plotting the results. As I mentioned in section 2.2.1, it is not possible to run two or more dependent loops in parallel using MATLAB. The solution was to run the acquisition loop for one second first. After that, it will handle the acquired data to the second loop which is the signal processing.

The signal processing block can be broken down into two sub-blocks; signal filtration and features extraction. But before entering to this loop though, an (If statement) is to determine the sample frequency which is the number of samples obtained in one second duration (one advantage for using a one second window). The first step when entering the signal processing loop is to update the counters (“tmin” and “tmax” in the code) which keep track of the number of samples.

After that, the portion of the input signal is handled to the signal filtering function where the signal undergoes two stages of filtering; the first one is a High-Pass filter (HPF) with a cutoff frequency equals to 1 Hz. The second stage is a Wavelet denoising filter which uses “Symlet” wavelet with the “Bayes-Empirical Bayes” denoising method -see Figure 23-.



Figure 23: Two-stage filter

More about the designing and testing of the filters can be found in Chapter Four. The output signal of the filtering function is then Detrended to remove any linear trend component from the signal.

The filtered signal is now ready to be exploited and that is by handling it to the feature extraction function. Inside the feature extraction function, the signal is filtered by a differentiation filter. This is done to increase the value of the peaks in the signal (Q, R and S waves) -see Figure 24-.

Figure 24: R-wave localization



I must mention here that I have got the idea of using this filter from Antonio Ribeiro’s GitHub profile (26). Antonio (34) is a guest PhD student who sat with me for a couple of hours and discussed with me some relative aspects (related to this project) that happened that he was working on as part of his research work.

Another idea that I borrowed from Antonio’s is to use a Band-Pass filter (BPF) for extracting T waves.

To detect the P waves, I used the “max” function along with a time sliding window which is in relation with the nearest detected Q wave. Now that I have the features extracted, the next step is to save them by concatenating them on the corresponding arrays.

For estimating the Heart Rate (HR), I use another feature which is the “RR interval”.

The HR is therefore updated after every one second. Then, the HR and RR interval values are also concatenated on their corresponding arrays. Now, I am ready to plot the ECG signal along with its features. This is done by entering the third and final block.

I used a combination of the two functions “drawnow” and “cla” to make it look like a continuous plotting. Please note that this block is only for demonstration purposes.

3.7: Graphical user interface (GUI)


dding a graphical user interface (GUI) to your software is similar to adding buttons to your hardware, both used to facilitate the accessibility to some or even all of the

functions featured by the system. In my case, I wanted to have a nice interface where I can perform some of the main functions such as “start”, “stop” and “export” without the need of reaching the MATLAB command line when demonstrating the system -see Figure 25-.



Figure 25: GUI

To design and build the GUI, MATLAB offers an easy-to-use application “App Designer”

which makes it pretty handy. All I had to do was to drag and place some buttons and numerical indicators. After that, I had to add a “callback” code to each of the buttons and indicators. The code of the GUI can be found in the Appendix.

One drawback for using the app designer though, is that the variables are not going to be saved to the MATLAB workspace. In other words, the designer will have to declare

“global” variables in order to use them in different functions.

The ability of saving the list of the extracted features and exporting it into an Excel sheet can be very fruitful for further uses, especially that MATLAB provides the ability of reading such spread sheets. At this moment, I have not used the extracted features for any specific application other than plotting the features on the ECG signal, but I am planning to exploit them in my next project.



3.8: 3D design


side from electronics and coding, I wanted to have a hard case enclosure for the final prototype. To do that, I designed a 3D model of the hard case using the free and open source software environment “TinkerCAD” (31) -see Figure 26-. After that, I printed the 3D model using one of the 3D printers -see Figure 27- which are available for Uppsala University students.

Figure 26: 3D design

Figure 27: 3D printer



Chapter Four

Tests and Results




n this chapter, I am going to view the methods that I used for testing verifying each element, entity and the integrity of the system. I will also show the results that I have got after conducting the tests. Please note that the discussion of the final results can be found in Chapter Five.

4.1: Testing the functionality of the ADS1293


his test was one of the trickiest as I was not actually just testing the functionality of the ADS1293, but also testing the correctness of my code and even the soldering of the ADS1293. The problem is that the designer cannot make sure if the all the QFN

packaged IC’s pads are soldered correctly to their footprints. Therefore, if I soldered the IC and performed the test for configuration and it failed, I cannot tell for sure if the issue is with code or with soldering or even with the ADS1293 chip itself (highly

sensitive to ESD).

The test was simply to hook the ADS1293 to the MCU using SPI bus -see Figure 28-, writing a value to a specific register and then reading this register. As expected, the first test failed, but I was confident that the problem is not with my code, so I re- soldered the chip again and retested it and finally, it worked.



Figure 28: Circuit used for testing ADS1293

4.2: Testing the ESP8266 (server/client comm.)


his test was not as hard or tricky. The strategy was to connect a potentiometer to the client, read the voltage across the potentiometer using the analog to digital channel (ADC) -see Figure 29-, send the value to the server and display the received value using the serial plotter.



Figure 29: Circuit used for testing ESP8266

Eventually, the test succeeded, and I was able to plot the change in the voltage continuously and wirelessly as I was changing the value of the resistance on the potentiometer.

4.3: Testing the first prototype integration


n this test, the target was to verify that the integration of both the software and the hardware produces the expected results; a clean ECG signal. To conduct this test, I used the circuit shown in Figure 10. I connected my body to the circuit using ECG

Ag/AgCl electrodes (27). Of course, it did not work from the first trial due to bugs in the code, but after debugging and testing, it worked and produced the output signal

shown in Figure 30.



Figure 30: Result for the first prototype test

The ECG lead that I tested in this test was ECG Lead II (right leg is the reference, right hand is the negative and left leg is the positive (28)). Later, I used this output signal to verify my MATLAB code.

4.4: PCB design rule check tool (DRC)


his is an automated checking tool provided by Altium Designer (29). Usually, the designer will start by setting his rules for the DRC tool before starting with the PCB layout.

The reader can refer to section 3.4.2 where I talked about this topic.



4.5: Post-soldering inspections


hen it comes to surface-mount dimensions (SMD) soldering, one needs to be very careful as he/she is dealing with small dimensions. But even with caution taken, there will always be room for small yet critical mistakes.

Personally, I prefer to perform a check routine after soldering every single component as well as an integration test. Two kinds of inspections were used; electrical inspection using a digital multimeter (DMM) to look for short circuits, and visual inspection using an electronic microscope -see Figure 31-.

Figure 31: Feedback from the microscope



4.6: Serial port setup in MATLAB


o verify the code responsible for setting up the serial port and scanning the incoming data, I used the same circuitry in Figure 29. The expected result was just like the one for the test of the ESP8266 in section 4.2, only here the ARDUINO serial plotter is replaced with MATLAB graph. Eventually, the test succeeded.

4.7: Tune the factors of the filters


esigning a filter can involve some trial and error procedures. The approach I used for deciding the designing factors of the filter -mainly the cutoff frequency- was to

perform a power spectral density (PSD) analysis for the pre and post-filter signal.

For example, the ECG signal shown in Figure 32 contains a linear trend component.

Figure 32: Raw ECG signal

When performing a PSD analysis on this signal, the designer can notice a high-power component at the frequency 1 Hz as illustrated in Figure 33 below.



Figure 33: PSD of the raw ECG

Using this information, the designer can set the cutoff frequency for the HPF to be equal to 1Hz. The resultant ECG signal is illustrated in Figure 34 below.

Figure 34: ECG signal after HPF with CF=1Hz

And when performing the PSD analysis on the filtered ECG signal, we can see that the peak at the frequency 1Hz has disappeared as illustrated in Figure 35. The signal is still noisy and can be filtered using a low-pass filter (LPF), but this is for demonstration reasons only. Note that this is not the output signal from the system that I designed and thus, it does not represent the noise of a wearable ambulatory ECG signal.



Figure 35: PSD for the filtered ECG

Figure 36: ECG signal after a wavelet denoising filter

4.8: Computation time calculation


o calculate the computation time needed to perform a specific function, I used the combination of the MATLAB functions “tic” and “toc”. When performed, the elapsed time starting from executing the “tic” until executing the “toc” will be printed on the command window of MATLAB. This can be useful when optimizing the code.



4.9: Code integration test


ere, I verify the functionality of the code as one entity. To do that, I used the signal that I have acquired using the first prototype -which emulates the final prototype- which illustrated in Figure 30. A portion of the resultant signal from the filtering block as well as a sample of the final ECG signal along with its features are illustrated in the two figures 37 and 38 below respectively.

Figure 37: Output signal form the filtering block

Figure 38: ECG signal with its extracted features (P, Q, R, S and T-waves)



4.10: Final prototype test


n this test, I want to verify the functionality of the final prototype -the PCB-, and that is done by simply redoing the same test done in section 4.3 but using the final

prototype instead of the first one.

The results are illustrated in Figure 40 below.

Figure 39: Final prototype "client"

Figure 40: Output signal from the final prototype



Based on the previous results, I can say that the test of the final prototype has failed to meet the desired output behavior.

The final test that was supposed to be done after this one is to test the integration of the final prototype with the MATLAB software. Since the final prototype has failed to produce the wanted signal, the final test was postponed.

In the next chapter, I am going to discuss the final results and try to predict the reason for such failure.

4.11: Quantitative evaluation of the algorithms


n this test, I perform a statistical evaluation test that evaluates the performance of the algorithms in MATLAB. Those algorithms are supposed to detect and identify the targeted features in the ECG signal (P, Q, R, S and T-waves).

To do that, I must have an ECG signal with prespecified statistics that can be used as a ground truth for the evaluation test. I used the WFDB toolbox for MATLAB and Octave (37) (38) -provided by Physionet (30)- to generate a synthesized ECG signal. Using this tool, one has full control over the main parameters of the ECG signal such like the heart rate mean and standard deviation as well as the additive noise and the sampling frequency.

I tested the algorithms by inputting:

• A clean ECG signal with normal rhythm

• A noisy ECG signal with normal rhythm -see Figure 45 and 46-

• A noisy ECG signal with arrhythmia (tachycardia)

• A noisy ECG signal with arrhythmia (bradycardia) The statistical measures of the performance are:

• Estimated heart rate mean (HRmean_est)

• Estimated heart rate standard deviation (HRstd_est)

• Positive predictivity or precision (PP) = (true positives / condition positives) * 100

• Sensitivity (Se) = (true positives / (true positives + false negatives)) * 100

• Accuracy (Acc) = ((true positives + true negatives) / (true positives + true negatives + false positives + false negatives)) * 100


56 Terms used for the evaluation:

• P, Q, R, S and T: condition positives

• P_det, Q_det, R_det, S_det and T_det: detected positives

• neg_P, neg_Q, neg_R, neg_S and neg_T: detected negatives

• P_trueP, Q_trueP, R_trueP, S_trueP and T_trueP: true positives

• P_falseP, Q_falseP, R_falseP, S_falseP and T_falseP: false positives

• P_trueN, Q_trueN, R_trueN, S_trueN and T_trueN: true negatives

• P_falseN, Q_falseN, R_falseN, S_falseN and T_falseN: false negatives

• Fs: sampling frequency [Hz]

• Anoise: additive uniformly distributed measurement noise [mV]

• HRmean: heart rate mean [beats per minute]

• HRstd: heart rate standard deviation [one beat per minute]

• T: total elapsed time [minutes]

• N: total number of heart beats

The results for each test are illustrated in the figures 41-44 below:

Figure 41: Evaluation test 1



Figure 42: Evaluation test 2

Figure 43: Evaluation test 3



Figure 44: Evaluation test 4

Figure 46: Synthesized ECG with Anoise = 0.1mV Figure 45: Synthesized ECG with Anoise = 0.2mV



Chapter Five

Discussion and Conclusion




his chapter is dedicated to discussing the final results which I viewed in the previous chapter, mentioning some of the challenges that I have faced while working on this project and lastly, concluding this report.

Let us start by discussing the final results. The fact the same code worked perfectly when tested on the first prototype -which mimics the final one- but failed when tested with the final prototype, left me with a list of suspicious reasons for this failure. First possibility is that there is a problem with the RF module embedded on the client’s board. To eliminate this possibility, I simply redone the same test but this time I connected the client directly to the PC using a UART to USB connection. The results were similar to the previous ones, therefore, no problem with the wireless connection.

The code cannot be the reason for the failure because the same code worked fine with the first prototype.

Adding the TVS Zener diodes might be the problem -I thought that drop voltage or even the impedance of the diodes might affect the input signal-. To eliminate this possibility, I de-soldered them as shown in Figure 21, then tested the prototype but it gave me similar results.

Currently, I am suspecting the soldering of the ADS1293 or maybe it was destroyed due to an electrostatic discharge. I did not have enough time to validate these theories, but I will do that soon.

An important thing to add here is the adaptability of the MATLAB algorithms. I tried my best to make them as adaptive as possible. Eventually and using some tricks, the

algorithms became adaptive to some factors such as the change in sampling frequency which can happen when changing the hardware system that is used for acquiring the measurand.

But they are not immune to sudden changes in the amplitude of the input signal and this fact makes the system unsuitable for real-life applications at its current state, as those sudden changes in the shape of the signal have to be taken into account.

Moreover, the filters were designed and tuned to deal with noises and artifacts similar



to those encountered in the signal which was used for testing the algorithms, meaning that I cannot claim that my algorithms -in their current state- can be used as an

inclusive solution.

The traces in the PCB layout are somehow long. This issue was solved in my modified design.

Back to the final results; during the last 10 days, I was trying to work the final

prototype out. Having little room of time -two days before the demo day- left me in a reckless and hasty state. This resulted in me losing my critical way of thinking and engineering approach for troubleshooting. Overall, this was not the perfect condition for dealing with such failure.

After the demo day, I started to change my mind regarding the situation of the project;

instead of solving the problem with the hardware -which shall waste a lot of time-, I will focus on the MATLAB algorithms. And to do so, I will activate plan B (modified version of the hardware that was developed before in my BSc thesis (39)) which I call

“PULSE2.0b”. As a matter of fact, I have already done that by testing the hardware of

“PULSE2.0b” and it worked perfectly -see Figure 47-. Unfortunately, the results have not been well documented yet and thus, I could not showcase them in this report.

Figure 47: Output signal using PULSE2.0b HW



Now, I will leave you -dear reader- with some of the challenges that I encountered during this project;

1) Hardware orders: In this kind of projects, the prototyping phase is expected to start earlier in along the schedule. This was case in my

project, and to waste no time, I needed to start as early as possible. To do so, I had to order all the electronics needed for prototyping. It was

possible to place the order through the IT department, but this meant that I will wait for a very long time until I receive the components. This is due the tedious formalities needed to be considered when placing such order through the department. The only solution was to find a sponsor for my project. Following the “3F” rule -family, friends and fools-, my father approved on sponsoring me.

2) PCB footprints and libraries: One of the most annoying issues was to find the right footprint for each component. Of course, the designer can design the footprint from scratch, but this will be a tedious process and can be exposed for human errors. To solve this problem, I had to fetch for each library of every component, some of which were supported by Altium, so I was able to find them in their website. Other manufacturers were not supported by Altium, but I found their libraries (Schematic, PCB or Integrated libraries) which were designed using different software such like Eagle. Thanks again to Altium Designer (AD), one can use their Import Wizard tool to convert libraries from different software and import it to the project in AD.

3) In-circuit programming/debugging: Since the ESP8266 will be soldered to the PCB, and since this board is still used as a prototype, that means that I will need to reprogram it or debug it. There are two ways to do that; one is to de-solder the module, program it and then re-solder it again. The other solution is to do an in-circuit programming. This can be done by connecting the module to another programmer using UART bus. To do that, I made use of headers and shunt connectors to change the working moods of the system.



4) Ground plan under the antenna: This was the most expensive mistake for me. I sent the fabrication files to the manufacturer company and later received the PCBs. When I showed them to the supervisor, he

immediately noticed a fatal mistake in my design. I naively poured a ground plan beneath the antenna of the ESP8266 module resulting in blocking any transmission to occur. Later, I modified the design by cutting the area under the antenna as shown in Figure 16.

5) Soldering SMD components: Before soldering the SMD components using the hot air gun, one must apply the solder paste over every single pad.

These pads are very tiny that it was impossible to apply the solder paste even with a micro needle. The solution was to use the so called “stencil”.

Stencils are basically a solder mask and can be printed using a knife-cutting machine -see Figure 48- and so I did. Thanks to my friend Abdul (36) -a PhD student in the Microsystems department- the stencil was fabricated and used for applying the solder paste successfully.

Figure 48: Knife-cutting machine



In the end and as a conclusion to this work, if I were asked what is one thing that I have learnt during this project course, I would answer by quoting “Hardware work does not finish, it can only be ended” by Alexander Medvedev.




6) Code for ADS1293 configuration:



Note: For more details regarding the code, please contact the author using the following Email address:


7) Code for WIFI connectivity:

• The Server:





• The Client:


69 8) MATLAB code:







Note: For more details regarding the code, please contact the author using the following Email address:



73 9) GUI code (Demo use version)












(1). https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5891427/#joa312035-bib-0005 (2). https://www.healthsystemtracker.org/chart-collection/know-cardiovascular-

disease-spending-outcomes-united-states/#item-hospital-admissions- congestive-heart-failure-frequent-u-s-comparable-countries

(3). https://www.statista.com/statistics/487291/global-connected-wearable- devices/

(4). https://www.heart.org/en/health-topics/heart-attack/diagnosing-a-heart- attack/electrocardiogram-ecg-or-ekg

(5). Lilly, Leonard S, ed. (2016). Pathophysiology of Heart Disease: A Collaborative Project of Medical Students and Faculty (sixth ed.). Lippincott Williams &

Wilkins. p. 74. ISBN 978-1451192759.

(6). Walraven, G. (2011). Basic arrhythmias (7th ed.), pp. 1–11

(7). ^ Braunwald E. (ed) (1997), Heart Disease: A Textbook of Cardiovascular

Medicine, Fifth Edition, p. 108, Philadelphia, W.B. Saunders Co.. ISBN 0-7216- 5666-8.

(8). https://en.wikipedia.org/wiki/Electrocardiography (9). http://www.ti.com/product/ADS1293

(10). https://www.espressif.com/en/products/hardware/esp8266ex/overview (11). https://www.sparkfun.com/products/13813

(12). https://www.sparkfun.com/products/14411

(13). https://www.microchip.com/wwwproducts/en/en530838

(14). https://www.semtech.com/products/circuit-protection/low-voltage-esd- protection/uclamp3306p

(15). https://meds.queensu.ca/central/assets/modules/ts-ecg/normal_ecg.html (16). http://www.ti.com/product/ADS1293/technicaldocuments

(17). https://schmartboard.com/smt-to-dip-adapters/qfp-qfn-to-dip/

(18). https://www.arduino.cc/en/reference/SPI

(19). https://www.youtube.com/channel/UCu7_D0o48KbfhpEohoP7YSQ (20). R RFC 1122, Requirements for Internet Hosts – Communication Layers, R.

Braden (ed.), October 1989.

(21). ^ RFC 1123, Requirements for Internet Hosts – Application and Support, R.

Braden (ed.), October 1989




Related subjects :