• No results found

Prototyping a wireless ECG system with an automatically tunable notch filter.

N/A
N/A
Protected

Academic year: 2022

Share "Prototyping a wireless ECG system with an automatically tunable notch filter."

Copied!
70
0
0

Loading.... (view fulltext now)

Full text

(1)

ISRN UTH-INGUTB-EX-E-2019/016-SE

Examensarbete 15 hp September 2019

Prototyping a wireless ECG system with an automatically tunable

notch filter.

Mattias Flodén

(2)

Teknisk- naturvetenskaplig fakultet UTH-enheten

Besöksadress:

Ångströmlaboratoriet Lägerhyddsvägen 1 Hus 4, Plan 0

Postadress:

Box 536 751 21 Uppsala

Telefon:

018 – 471 30 03

Telefax:

018 – 471 30 00

Hemsida:

http://www.teknat.uu.se/student

Abstract

Prototyping a wireless ECG system with anautomatically tunable notch filter

Mattias Flodén

In this thesis an electrocardiography (ECG) prototype is developed that wireless transfer the ECG measurements to an Android smartphone.

The prototype consist of two printed circuit boards (PCBs), an Android smartphone and an automatically tunable notch filter.

The first PCB is intended for performing ECG measurements using three electrodes placed on a body and transferring the ECG data to the second PCB wireless via ultra-wideband (UWB). The second PCB is used to receive the ECG data via UWB communications and then transfer it to the Android smartphone through a USB cable. An automatically tunable notch filter is implemented to remove the 50 Hz power line interference in the ECG measurement data. And finally, an Android application is developed to display the ECG data to the user in real- time.

The finished prototype is tested and shown to be successful. The ECG measurements can be transmitted from the transmitting to the

receiving PCB over UWB and then displayed graphically in real-time on an Android smartphone. The automatically tunable notch filter is simulated and shown to able to remove power line interference.

(3)

Populärvetenskaplig sammanfattning

Elektrokardiografi (EKG) är ett instrument där elektroder fästes på krop- pen för att mäta och registrera hjärtats elektriska aktivitet. Det används för att upptäcka avvikelser i hjärtats aktivitet som exempelvis rubbningar i hjärtrytmen. Detta är något som vanligtvis brukar utföras på sjukhus.

Genom att tillverka en liten lättanvänd sensor så kan detta göras utan att behöva åka till sjukhus. Detta är något som hade kunnat minska arbets- belastningen hos sjukhusen och tidigare kunna identifiera hjärtproblem hos patienter som ligger i riskzonen. Sensorn skickar informationen till en smart- phone där algoritmer kan skrivas för att detektera avvikelser i hjärtrythmen.

Datan kan också användas för att skickas vidare till en läkare för en utförlig diagnostisering.

Projektet visar också hur Ultra-wideband (UWB) tekniken kan användas för känslig medicinsk utrustning. UWB har fördelen över bluetooth och WiFi att den är väldigt energisnål och att den har en låg amplitud som gör att den inte orsakar störningar på annan känslig utrustning.

Prototypen består utav två noder och en Android telefon. Första noden är ett designat kretskort där elektroder kan kopplas till för att göra EKG mät- ningen. Kretskortet ska sedan skicka vidare mätdatan med hjälp av UWB.

Andra noden består av ett annat designat kretskort som kan ta emot UWB- datan och skicka den vidare till Android telefonen. Båda kretskorten ska vara baserade på mikrokontrollern ATSAM3X8E, som också är den mikrokon- troller som används till Arduino DUE. Mätdatan ska sedan tas emot och presenteras i en utvecklad Android applikation på telefonen. För att bli av med störningar som orsakas av elnätet så konstrueras även ett automatiskt adaptivt digitalt notch-filter.

Hela projektet nådde kravställningen som ställdes innan projektet påbör- jades förutom det digitala filtret. På grund av tidsbrist så simulerades endast filtret men implementerades ej in i prototypen.

(4)

Contents

1 Introduction 1

1.1 Background . . . 1

1.2 Purpose of the project . . . 1

1.3 Project description . . . 2

1.4 Tasks . . . 2

1.5 Outline . . . 2

2 Theoretical and technical background 3 2.1 Electrocardiography . . . 3

2.1.1 Components of the Electrocardiogram . . . 4

2.1.2 Electrode placement (Bipolar) . . . 5

2.2 Ultra-Wideband . . . 5

2.3 Digital signal processing . . . 6

2.3.1 Sampling and quantization . . . 6

2.3.2 Sampling frequency and aliasing . . . 8

2.3.3 Infinite impulse response notch filter . . . 10

2.4 Printed circuit board design . . . 12

2.4.1 Electromagnetic compatibility . . . 12

2.4.2 Decoupling capacitor . . . 13

2.4.3 Transmission line . . . 13

2.4.4 Differential signaling . . . 14

2.4.5 Trace spacing . . . 15

3 Hardware implementation 16 3.1 Overview of prototype . . . 16

3.2 Microcontroller, ATSAM3X8E . . . 16

3.2.1 Power supply and rails . . . 18

3.2.2 Crystal oscillator . . . 18

3.2.3 USB . . . 20

3.2.4 Programming and debugging . . . 21

3.3 Ultra-Wideband transceiver, DWM1000 . . . 22

3.4 Heart rate measurement, AD8232 . . . 24

3.5 USB On-The-Go . . . 25

3.6 Printed circuit board . . . 26

3.6.1 Overview . . . 26

3.6.2 PCB layout . . . 27

3.6.3 Component placement . . . 28

3.6.4 Trace routing . . . 29

(5)

4 Software implementation 32

4.1 Android application . . . 32

4.1.1 Architecture . . . 32

4.1.2 Main activity . . . 33

4.1.3 USB service . . . 33

4.1.4 Help fragment . . . 34

4.1.5 Heart monitor fragment . . . 34

4.1.6 Settings fragment . . . 34

4.1.7 Debugging fragment . . . 34

4.2 Microcontroller code . . . 35

4.2.1 Transmitter node . . . 35

4.2.2 Receiver node . . . 36

4.3 Adaptive notch filter . . . 38

5 Results and discussion 40 5.1 Prototype system . . . 40

5.2 Printed circuit board prototype . . . 40

5.2.1 Design a printed circuit board . . . 42

5.2.2 Assembly process . . . 42

5.2.3 Sensitivity and disturbances . . . 44

5.3 Android application . . . 44

5.3.1 Develop an Android application . . . 48

5.3.2 Software bugs . . . 48

5.4 Simulated adaptive IIR notch filter . . . 48

6 Conclusions and future work 50 6.0.1 Future work of the PCB prototype . . . 50

6.0.2 Future work of the Android application . . . 50 6.0.3 Future work of the adaptive IIR notch filter algorithm 51

References 52

A Appendix: Recommended pin connection (Single power sup-

ply) 54

B Appendix: Schematics of PCB prototype 55

C Appendix: 3D-model of PCB prototype 60

D Appendix: SMD stencil 61

E Appendix: Simulated IIR notch filter MATLAB code 62

(6)

Nomenclature

Abbreviations

ADC Analog-to-Digital Converter

CAD Computer-Aided Design

CMOS Complementary Metal Oxide Semiconductor CPU Central Processing Unit

DAC Digital-to-Analog Converter EMI Electromagnetic Interference FFT Fast Fourier Transform FIR Finite Impulse Response

GPIO General-Purpose Input/Output

I/O Input/Output

IC Integrated Circuit

IDE Integrated Development Environment IIR Infinite Impulse Response

ISP In-System Programmer

JTAG Joint Test Action Group

MEMS Microelectromechanical systems

OTG On-The-Go

PCB Printed Circuit Board

RC Resistance Capacitance

RF Radio Frequency

(7)

RTC Real-Time Clock

SMD Surface Mount Device

SPI Serial Peripheral Interface SRAM Static Random Access Memory

UI User Interface

USB Universal Serial Bus

UWB Ultra Wideband

Physics Units

Ω Electrical resistance

ω Natural frequency (ω = 2πf )

A Electrical current

F Electrical capacitance

Hz Cycles per seconds

V Electrical potential difference

W Unit of power

Terminology

Baud rate Speed of data communication (bits per second) Double Data type that represents decimal values String Data type that represents characters

(8)

1 Introduction

1.1 Background

An electrocardiogram (ECG) device is used to measure and record the elec- trical activity of the heart by placing electrodes on a human body. ECG data is used to detect anomalies in a patient’s heart activity, e.g. atrial fibrillation.

This is usually done at the hospital.

By developing a small easy to wear sensor this can be performed outside the hospital, reducing work load of the health care system and enabling to early identify heart disease of high-risk patients. With fast development of microelectromechanical systems (MEMS), ECG devices become portable and suitable for home use, and because of pervasive use of smartphones nowadays, apps are developed for smartphones to collect (receive) ECG data from ECG devices, and then display and analyze the data, or send remotely via mobile networks to a doctor for further diagnostics.

With such an interest, a portable ECG system was built in an earlier Master thesis project. It contains two units:

1. an ECG measurement unit that consists of electrodes, an Arduino Due microcontroller board and a UWB (ultra-wideband) communication module and

2. a data collecting and displaying unit that consists of an Arduino Due microcontroller board, a UWB communication module and a smart- phone with an app collecting and displaying ECG data. The UWB modules are used for transferring the ECG data via UWB communica- tions from the first unit to the second unit.

This project is intended to build prototype PCBs (printed circuit boards) based on this portable ECG system with an automatically tunable notch filter added and the smartphone app further developed.

This is the bachelor thesis project in the final semester at Uppsala uni- versity. The project is done at the Division of Signals and Systems in the Department of Engineering Sciences, at Uppsala university.

1.2 Purpose of the project

The purpose of this project is to develop prototype PCBs for the portable ECG systems on single boards. It includes designing of printed circuit boards (PCBs), processing data using digital signal processing and programming an

(9)

1.3 Project description

This project consists of three different parts. The first part is to make two prototype printed circuit boards (PCBs) based on the Arduino due. The first PCB will be able to measure ECG on a patient using three electrodes, and send the measurements out using UWB communications. The second PCB will be able to receive the measurements through UWB and then send it to an Android device.

The second part of the project is to develop an Android application to receive the ECG measurements from the first PCB. The application displays the ECG waveforms.

And the third part is to construct an automatically tunable notch fil- ter. The filter will be designed so that it can remove unwanted interference without altering the measurement data.

1.4 Tasks

The objectives of this project is to:

• Design one PCB that measures the ECG from a patient and sends the measurements wireless using UWB.

• Design a second PCB that is able to receive and send data using UWB and USB.

• Further develop the Android application to display ECG waveforms in real time.

• Construct an automatically tunable notch filter.

1.5 Outline

After this introduction section there will be a section describing the theoret- ical and technical background behind the project. The third section states the choice of components and how they are connected with each other. The fourth section describes how the Android application is developed and how to construct a digital adaptive notch filter. The fifth section presents and discuss the results of the final developed prototype. And finally, the sixth section gives the conclusions and examples of future work to the project.

(10)

2 Theoretical and technical background

2.1 Electrocardiography

The heart is a muscle that is pumping blood through blood vessels in the body. Each contraction of the heart is controlled by electrical signals in the body. The electrical signals happens a fraction of a second before the

"mechanical event" occurs. The hearts electrical activity can be measured and plotted using electrocardiogram (ECG). ECG is used to detect abnormal rhythm and function of the heart [13].

The ECG is measured by placing electrodes on the surface of a patient’s body. It’s performed by using 3 up to 12 leads, each record the electrical activity from different orientation or perspective.

(11)

2.1.1 Components of the Electrocardiogram

The ECG waveform shows three different cardiac events: atrial depolariza- tion, ventricular depolarization and ventricular repolarization. Each of these events are separated into three different waves called: P-wave, QRS-complex and T-wave [18, p. 1].

The P-wave shows the electrical activity when the atrial depolarization.

This is when the atrial fills with blood and contracts to fill the ventricular.

The QRS-complex shows the ventricular depolarization. The ventricular de- polarization is when the ventricular have been filled with blood and then contracts. And the T-wave shows the ventricular repolarization, which is when the ventricular fills with blood. The different waves is seen in figure 2.1.

In the frequency domain, these waves have a bandwidth of 0.5 to 100 Hz and sometimes reaches up to 1 kHz [20].

Figure 2.1: ECG waveform components [24].

(12)

2.1.2 Electrode placement (Bipolar)

Bipolar leads are a standard limb lead configuration for ECG measurements with 3 leads. The positive electrode is placed on the left arm, and the negative electrode on the right arm. The electrodes are placed on each arm so the potential difference between them is measured. The third electrode is placed on the right leg and only serves as a reference for the measurement. The electrodes can be placed either close to the shoulders and hip or at the wrists and ankle.

The placement of electrodes on either the origin or end of the limbs does not affect the measurement as the limb act as conductors. The three elec- trodes form a triangular shape called Einthoven’s triangle. This triangle is named after Willem Einthoven, the inventor of ECG. A figure of Einthoven’s triangle is seen in figure 2.2.

Figure 2.2: Einthoven’s triangle [24].

2.2 Ultra-Wideband

Ultra-wideband (UWB) is a high bandwidth radio technology used for short- range applications. UWB was first developed to be used as a military tool as it could see through trees and beneath ground surfaces. But later, it became target to the consumers market to be used in low power, low cost, high data rate, precise locating and low interference applications.

UWB works by spreading the signals across a wide range of frequencies, compared to broadcasting on separate frequencies. Instead of sinusoidal ra- dio waves, it uses pulse trains pulsing at hundreds of millions pulses per

(13)

low interference.

UWB uses narrow pulses which gives it the wide bandwidth. If the pulses are separated it gives the receiver a fine resolution of reflected pulses. This is important in all wireless communication, since interfering pulses is the largest problem to an error free communication. The large bandwidth also enables high-speed data in the range of 100 Mbps to 500 Mbps.

Another benefit of using UWB is that it has the ability to determine the signals time of travel at various frequencies. This makes UWB systems multipath immune. It can be used to calculate distances with high resolution and accuracy, ideal for indoor positioning. Multipath is when the receiver receives the same signals at different times due to the signal traveling different paths, caused by reflections and absorption etc. [15]

The UWB technology is regulated by each country’s responsible author- ity. The US federal communications commission was the first authority to regulate UWB in February 2002. According to their regulations UWB is allowed for indoor applications using the frequency range between 3.1 and 10.6 GHz.

European regulations were established in March 2006 and separated the usable frequency range for indoor application into two bands, 4.2 – 4.8 GHz and 6 – 8.5 GHz [25, p. 2].

2.3 Digital signal processing

Digital signal processing is used for numerical manipulations and calculations of a digital signal. It’s used to transform an analog signal into a digital so it can be processed by a digital system.

By converting an analog signal into a digital allows a processor to process the signal using programming algorithms instead of analog circuits. Digital circuits also are less sensitive to noise and does not age over time.

Computer algorithms can be written so that unwanted interference can be filtered out. A digital filter is easier to realize than an analog filter which requires application dependant hardware. The filter coefficient can easily be modified and adaptive by just changing the code. Digital filters cut-off frequency is determined by the clock frequency and filter coefficients. This makes it possible to design filters with a very low cut-off frequency.

2.3.1 Sampling and quantization

To be able to process an analog continuous-time signal digitally it must first be converted into binary numbers. The conversion is made through a process called sampling. The sampling can be done in different ways. It

(14)

can either record the analog signals momentary amplitude in periodic time intervals or the analog signal can be multiplied by a periodic impulse train or a rectangle. Sampling by impulse train is called impulse train sampling and has been proven to be more useful for analysis and design [17, p. 89].

The definition of an impulse train δT(t) is described by equation 1.

δT(t) =

X

−∞

δ(t − n∆t) (1)

The input continuous-time signal to be sampled x(t) is multiplied with the impulse train resulting in xc(t), as described in equation 2. This results in sequence of impulses. xc(t) corresponds to the amplitude of the continuous- time signal at t = n∆t where n is the n sample and ∆t is the sample period.

xc(t) =X

n

x(n∆t)δ(t − ∆t) (2)

To illustrate this process, a continuous-time signal (figure 2.3) is mul- tiplied with the impulse train (figure 2.4). Each impulse get the amplitude corresponding to the sampled signals amplitude, the resulting graph is shown in figure 2.5.

Figure 2.3: Continuous-time signal x(t) [17, p. 90].

Figure 2.4: Impulse train [17, p. 90].

(15)

Figure 2.5: Result of the sampling xc(t) [17, p. 90].

When the continuous-time signal has been sampled into a discrete-time signal it can be reconstructed back into a continuous-time signal through a process called quantization. Each sample of the discrete-time signal contains information about the amplitude of the output voltage, a quantiser then tries to find the closest binary number. The digital-to-analog converter (DAC) holds the analog value for ∆t seconds and then changes to the next sample.

2.3.2 Sampling frequency and aliasing

When converting a continuous-time signal into a discrete-time signal it’s important to choose an appropriate sampling frequency. If the sampling frequency is too low or too high it can cause misleading results.

If we look at the sampling process in the frequency domain by Fourier transforming equation 2, we get equation 3. In the frequency domain, the input signal is now convoluted instead of multiplied with the impulses.

Xc(ω) = 1

∆tX(ω) ∗X

n

δ



ω −2πn

∆t



(3)

Looking at the equation in frequency domain we can also see that if the sampling period (∆t) is reduced, the sampling pulses moves closer but in frequency domain it increases the separation.

If the Fourier transform of an analog signal is assumed to be a triangular shape with the maximum frequency component at ωm rad/s. Assume we are using a sampling frequency of ω = 2π/2. The sampled signal X(ω) is then convolved with each of the impulses, forming the primary component at ωm = 0 and complementary component at ω = 2π/2. The process repeats for every impulse at positive and negative frequencies. The process is illustrated in figures 2.6, 2.7 and 2.8.

(16)

Figure 2.6: Fourier transform of analog input [17, p. 93].

Figure 2.7: Fourier transform of impulse train [17, p. 93].

Figure 2.8: Fourier transform of sampled signal [17, p. 93].

If we look at the Fourier transform of the sampled signal in figure 2.8 we can see that if the sampling frequency had been increased the components would eventually overlap each other. If the components overlap, they add to each other, making the quantized signal a distorted version of the sampled.

This is called aliasing and is caused by a too high sampling frequency.

If the sampling frequency is too low, it causes undersampling. Undersam- pling causes the sampling process to miss important data point which also results in a distorted version of the original [17, pp. 91-95].

To avoid aliasing distortion, the sampling frequency must be at least twice the highest frequency to be sampled. This theorem is called the Nyquist

(17)

2.3.3 Infinite impulse response notch filter

A notch filter is a band-stop filter with a very narrow stop-band. A notch filter is ideal for filtering out a specific frequency such as the 50/60 Hz sinu- soidal signal caused by power-line interference.

The notch filter can be implemented either as an infinite impulse response (IIR) or finite impulse response (FIR) filter. The benefits of an IIR filter is that it’s recursive, meaning that the filter has a feedback from previous, present and future values. Since the filter has a “memory” it enables it to use a lower order to achieve filter specifications compared to a FIR filter. The IIR filter also has poles on the unit circle instead of the origin as a FIR filter has. The position of the poles of the IIR filter allows a band-pass filter with a very narrow bandwidth.

The IIR filter can be designed using different methods. It can either be designed by transforming an analog filter using bilinear transform or it can be designed by pole-zero placement on the z-plane. To design the IIR notch filter using pole-zero placement we need to place the poles and zeros into the transfer function [17, pp. 125-149]. A commonly used notch filter is the second order IIR filter. The equation of a second order IIR notch filters transfer function is seen in equation 4 [27].

H(z) = b0 z2− 2z cos ΩN + 1

z2− 2rz cos ΩN + r2 (4) where b0 is the filter gain, ΩN is the pole angle or normalized notch frequency and r is the poles radius.

First the normalized frequency ΩN is calculated to place a pair of zeroes on exactly the notch frequency using equation 5.

N = 2πfN

Fs (5)

where fN is the notch frequency and FS is the sampling frequency.

Then a pair of poles needs to be placed close to the unit circle and at the notch frequency. For an IIR filter to be stable, all poles have to be within the unit circle. So, for the filter to be stable the absolute value of r has to be less than 1. r is calculated using equation 6. A picture of a pole-zero plot of an IIR notch filter is seen in figure 2.9.

r = 1 −BW

Fs π (6)

where BW is the notch bandwidth.

(18)

Figure 2.9: Pole-zero plot of IIR notch filter.

The distance between pole and origin r controls the notch bandwidth of the filter. When r is close to 1, the bandwidth will become narrow. A picture illustrating how r affects the notch bandwidth is seen in figure 2.10.

Figure 2.10: Notch bandwidth using different r.

(19)

2.4 Printed circuit board design

When designing a printed circuit board (PCB) or any other electrical product some issues and design technique must be known. One of the biggest issues when designing a PCB is electromagnetic compatibility (EMC). EMC cannot be removed but it can be reduced. Some design techniques and how to reduce EMC will described in further detail in following sections.

2.4.1 Electromagnetic compatibility

EMC is the electrical equipment ability to function in an electromagnetic environment. If the EMC is not considered in the design, unwanted effects such as electromagnetic interference (EMI) can occur. If large amount of EMI is present in a PCB design, it can cause unexpected behavior and mal- functioning circuits.

There are many variables that causes EMI, such as passive components and switching digital components. One of the most common is the exception of the normal behavior of passive components. As example, a resistor with a high frequency current going through it behaves as an inductor in the leads of it in parallel with a capacitor across its terminals [16, pp. 13-18].

The EMC field can be described using a series of partial differential equa- tions known as Maxwell’s equations. These equations describe the relation- ship of both electric and magnetic fields and are derived from Ampere’s law, Faraday’s law and two from Gauss’s law. The equations says among other things:

• Static-charge produce static electric fields.

• Constant current produces magnetic fields.

• Time-varying current produce electric and magnetic fields.

When designing a PCB it is not necessary to solve these equations, and therefore will not be described in further detail in this thesis.

A simplified way to relate to Maxwell’s equations in a PCB trace is by looking at Ohm’s law equations in time (equation 7) and frequency domain (equation 8). By looking at the equations one can see that if radio frequency (RF) current exists in a PCB trace which has an impedance, there will be a proportional RF voltage created.

(20)

V = I · R (7)

Vrf = Irf · Z (8)

where V is voltage, I is current and Z is the impedance (Z = R + jX).

2.4.2 Decoupling capacitor

Between circuits in a coupling, noise can propagate in the power supply net- work. When currents flow in the supply voltage network to components it causes voltage drops due to resistance in the traces. Also, switching com- ponents causes voltage drops during clock or data transitions when multiple components switch simultaneously [16, p. 65].

To compensate for these noise and voltage drops, decoupling capacitors is used. A decoupling capacitor ensures that the component have a low- impedance power source present. The decoupling capacitor is required to provide enough voltage and current levels during simultaneous component switching that causes maximum capacitive load. Since the decoupling ca- pacitor have a low impedance at high frequency, it can divert high frequency noise from the power network.

The decoupling capacitor are connected directly between the components power supply pin and ground. When designing a PCB the placement of the decoupling capacitor is important. To be able to act as a low-impedance power supply it’s important that the capacitor is placed close to the compo- nents power supply pin and ground. The traces need to be kept short, and so that they do not form a loop to reduce the inductance [16, pp. 85-86].

2.4.3 Transmission line

When traces on a PCB is routed adjacent to a ground plane, or RF return path, it forms a transmission line. A trace routed on an outer layer is called microstrip, and if the trace is routed on an internal layer, it’s called stripline.

Some applications, especially high-speed traces require that the transmis- sion line have a controlled impedance. The characteristics of a trace can be calculated either manually or by computer programs.

The impedance Z0 of a surface microstrip trace can be calculated using different equations depending on the traces width. The equation for calcu- lating the impedance Z0 is seen in equations 9 and 10. The microstrip trace

(21)

capacitance per inch C0 can also be calculated using equation 11.

Z0 = 79

√εr+ 1.41· ln

 5.98H 0.8W + T



(9) (Valid for 0.127 mm < W < 0.381 mm)

Z0 = 87

√εr+ 1.41· ln

 5.98H 0.8W + T



(10) (Valid for 0.381 mm < W < 0.635 mm)

C0 = 0.67(εr+ 1.41)

ln 0.8W +T5.98H  (11)

where W is the width of the trace, T is the thickness of the trace, H is the distance spacing to nearest reference plane and εr is the dielectric constant of the planar material [16, p. 107].

2.4.4 Differential signaling

Differential signaling is a method to transmit logic signals between two sys- tems. The differential signaling works by sending the signal as differential pairs in separate conductors, where the signals are equal and opposite. The receiver reads the signal by reading the difference between the signals rather than ground as a single-ended signaling does. By doing so, the driver and receiver floats with respect to ground.

There are several advantages of differential signaling, one is reduced EMI.

The EMI is reduced since the magnetic field produced by one conductor is eliminated by the second conductor, because they are opposite of each other. Another advantage of differential signaling is that both conductors are exposed to the same noise, resulting in that noise is canceled out [16, p. 124].

Theoretically the two signals only need to arrive in good condition with the same timing to work. This means that the conductor pair can be routed spread out, on different layers or side-by-side. Thus, some logical components require a specific differential impedance between the pair, which requires routing of the traces side-by-side.

When routing differential signals, they need to be length matched and, in some cases, have a controlled differential impedance. Even though it’s not required to run the traces parallel to each other it’s highly recommended

(22)

to do so, since it otherwise causes EMI issues [16, p. 125]. The differential impedance Zdif f is calculated using equation 12.

Zdif f ≈ 2 · Z0

1 − 0.48e−0.96DH



(12) where Z0 is the characteristic impedance of one trace, D is the trace edge- to-edge spacing and H is the distance spacing to nearest reference plane [16, p. 107].

2.4.5 Trace spacing

Another important aspect to consider during the design of PCB is crosstalk.

Crosstalk is when unintended electromagnetic coupling occurs between traces, components and wires etc. Crosstalk is something that can cause unwanted effects on data and control nets. The majority of crosstalk is caused by clock and periodic signals [16, p. 131].

The most effective way to reduce crosstalk between two parallel traces is to increase the distance between them or to bring the traces closer to a reference plane. One rule of thumb is to use the 3-Width rule. The rule states that:

"The distance separation between traces must be three times the width of a single trace measured from centerline to centerline."

[16, p. 136]

By using the 3-Width rule, it minimizes the coupling between transmis- sion lines or traces. It’s mandatory to use it on high-threat signals such as clock, differential pairs, reset lines and other critical nets.

(23)

3 Hardware implementation

3.1 Overview of prototype

The final prototype consists of three nodes, node one (receiver), node two (transmitter) and an Android smartphone. The transmitter is powered by a battery pack and connects to the electrodes that measures the heart activity of the patient. It sends the measurements to the receiving node using UWB communication.

The receiving node receives the measurements from the transmitter node and sends the information to the Android smartphone via USB communica- tion. The receiving node is powered by the Android smartphone which uses a USB OTG adapter that makes the smartphone act as a host as described in section 3.5. A block schematic of the system is seen in figure 3.1.

Figure 3.1: An overview of the system.

3.2 Microcontroller, ATSAM3X8E

In the previous thesis that this project is based on, the prototype was made up of Arduino Due. The Arduino Due uses the ATSAM3X8E microcontroller and therefore the same microcontroller is used in this project. Using the same microcontroller makes it compatible with Arduino IDE for programming and help documentation can easily be found on the Arduino community. A pic- ture of the ATSAM3X8E is shown in figure 3.2

Figure 3.2: Picture of ATSAM3X8EA-AU-ND microcontroller [11].

(24)

The ATSAM3X8E is a microcontroller based on the 32-bit ARM R Cortex R- M3 processor. It has 512 kB of flash memory for storing of programming code and 96 kB of Static Random Access Memory (SRAM). The microcontroller comes with a factory burned bootloader in a dedicated read only memory (ROM). This means that the microcontroller is ready to be programmed out of the box and doesn’t require access to in-system programmer (ISP) before the code can be uploaded. A table of specifications of the ATSAM3X8E is shown in table 1.

Table 1: Specifications of ATSAM3X8E [11]

Name Value

Part Family ATSAM3X8E

Max CPU Speed 84 MHz

Program Memory Size 512 kB

SRAM 96 kB

Temperature Range -40 to 85 C

Operating Voltage Range 1.62 to 3.6 V

Direct Memory Access Channels 23

SPI 4

I2C 2

Peripheral Pin Select/Pin Muxing Yes

Number of USB Modules 1

ADC Input 16

Max ADC Resolution 12 bits

Max ADC Sampling Rate 1000 ksps

Number of DACs 1

Internal Oscillator 4,8,12MHz,32kHz

Max I/O Pins 103

Pinout 144

To be able to function properly, the microcontroller requires some pe- ripheral circuitry. The manufacturer provides a checklist for the minimum required peripherals and recommended pin configurations [2]. These periph- erals will be described in the following subsections.

(25)

3.2.1 Power supply and rails

The microcontroller can have different power rail setups depending on its application. In this project the Single Power Supply is used and can be found the manufacturers checklist [2, pp. 4-5]. When USB will be used, one can read that the microcontroller requires a main supply voltage between 3.0V to 3.6V. Since the PCB is powered by the USB port which supply a voltage of 5V, a voltage regulator is required.

The Texas instruments LM1117 was chosen as the voltage regulator. It is a fixed linear regulator from 5V to 3.3V and can provide an output current of 800mA [14]. The advantage of using a linear regulator over a switching regulator is that it’s cheap, produces minimal noise and have a simple circuit.

It has a disadvantage of lower efficiency, since the voltage difference between the input and output needs to be absorbed at the same time as the load current passes through [22].

The ATSAM3X8E also have an embedded voltage regulator that provides an output of 1.8V. This output is intended to supply the ATSAM3X8E in- ternal core but can also be used to supply other parts in the design, in this project it’s only used for supplying its core [19, p. 21].

In the table in appendix A the different power rails and recommended pin connection is described. Full schematics of the power supply circuit is seen in appendix B.

3.2.2 Crystal oscillator

The ATSAM3X8E features two embedded RC (resistance, capacitance) os- cillators, called slow clock and main clock [19, p. 27]. It also has pins for connecting external crystals to use as clock signals, which is needed in some applications. In this project two external crystals are connected to the AT- SAM3X8E.

The slow clock is used in low power modes and for real-time clock (RTC), which will be used in the programming of this project. An external crystal is used to get a higher accuracy clock signal and connects to the XTAL32 pins of the ATSAM3X8E. The crystal must be 32.768 kHz and meet certain spec- ifications to match the embedded oscillator as specified in the ATSAM3X8E datasheet [19, pp. 1395-1396]. The required 32.738 kHz crystal specifications is stated in table 2.

(26)

Table 2: External crystal requirements for slow clock at 32.768 kHz [19, p. 1396]

.

Symbol Description Min Typ Max Unit

PON Drive Level 0.1 µ W

Clext Maximum external capacitor 20 pF

CCrystal Allowed Crystal Capacitance Load 6 12.5 pF

ESR Equivalent Series Resistor 50 100 kΩ

CSHU N T Shunt capacitance 0.6 2 pF

When USB communication will be used one can read in the datasheet that an external 12MHz crystal is required to be connected to the XTAL pins of the ATSAM3X8E and will be used as the main clock. This crystal also needs to meet certain specifications to match the embedded oscillator as specified by the datasheet [19, pp. 1397-1398]. The required 12MHz crystal specifications is stated in table 3.

Table 3: External crystal requirements for main clock at 12MHz [19, p. 1398].

Symbol Description Min Typ Max Unit

PON Drive Level 50 µW

Clext Maximum external capacitor 10 pF

CCrystal Allowed Crystal Capacitance Load 12.5 17.5 pF

ESR Equivalent Series Resistor 80 Ω

CSHU N T Shunt capacitance 7 pF

(27)

3.2.3 USB

The USB connector in this project is used for power supply, programming and serial communication. The connector can be connected to the ATSAM3X8E in different ways depending on the application which are described in the manufacturer checklist [2]. In this project the Bus-Powered Device mode is used. [2, p. 15]. The connections between the USB connector and the ATSAM3X8E is seen in table 4 and full schematics is seen in appendix B.

The power bus of the USB connector (VBUS) is connected to a 5V to 3.3V voltage regulator via a resettable polyfuse. Most USB ports have their own internal protection thus, the fuse provides extra protection. If the current from the USB port exceeds 500mA, the fuse breaks the circuit until the short or overload is removed.

A low-capacitance 3-channel transient voltage suppressor is used on D+, D- and ID lines as electric static discharge protection.

Table 4: Connections between USB connector and ATSAM3X8E [2, p. 14]

Pin Description Notes Pin

ATSAM3X8E USB Connector

VBUS Bus power measurement Connected to external VBUS voltage regulator

DFSDM Full-speed differential Connected in series with a D- data line - 39Ω ± 1% resistor

DFSDP Full-speed differential Connected in series with a D+

data line + 39Ω ± 1% resistor

DHSDM High-speed differential D-

data line -

DHSDP High-speed differential D+

data line +

UOTGID USB identification ID

VBG Bias voltage reference Pin connected to RC filter R = 6.8kΩ ± 1%, C = 10pF

(28)

3.2.4 Programming and debugging

There are different ways to upload programming code to the ATSAM3X8E.

It can be programmed by USB port, serial on pins RX0 and TX0 or joint test action group (JTAG). Since it comes with a pre-burned bootloader it’s able to upload code directly using the USB port, therefore no JTAG connector is used in this project. Even though JTAG is not used, pull-up resistors is connected to the JTAG pins of the ATSAM3X8E to prevent unexpected signals. To be able to upload code using RX0 and TX0 pins a USB-to-serial converter would be needed.

Since this is the first prototype some extra debugging features are added.

Buttons for resetting and erasing of the code is installed, by pressing both buttons simultaneously for a few seconds, the uploaded code is erased. Also, an extra connector is added to the PCB that connects to RX0 and TX0 serial pins, so the PCB could be tested in case of issues with the USB communica- tion. The connector also connects to a transistor for erasing and resetting the ATSAM3X8E. Full schematics of the debugging features are seen in appendix B. Debugging pin configurations is seen in table 5.

Table 5: Debugging pin connections [2, pp. 11-12]

Pin Pin Connection Description

ATSAM3X8E

TCK/SWCLK Pull-up 100kΩ Test clock/Serial wire clock to +3.3V input pin TCK after reset TMS/SWDIO Pull-up 100kΩ Test mode select/Serial wire

to +3.3V input/output TMS after reset TDI Pull-up 100kΩ Test data in TDI after reset

to +3.3V

TDO/ Floating Test data out/Trace asynchronous

TRACESWO data out

JTAGSEL Ground Tie to +3.3V to enter JTAG

boundry scan

NRST Floating Microcontroller reset input pin NRSTB 10nF to +3.3V via Asynchronous microcontroller

push button reset input pin

TST Ground Test mode select input pin

FWUP Pull-up 100kΩ Force wake up pin to +3.3V

SHDN Floating Shut-down control pin

(29)

3.3 Ultra-Wideband transceiver, DWM1000

For UWB communication between each node, the Decawave DWM1000 mod- ule was chosen. The DWM1000 module is fully integrated of DW1000 radio integrated circuit (IC), antenna, power management and clock control. The DW1000 radio IC is a single chip complementary metal oxide semiconduc- tor (CMOS) radio frequency (RF) transceiver IC compliant with the IEEE 802.15.4-2011 UWB standard [4]. A picture of the DWM1000 module is shown in figure 3.3.

Figure 3.3: DWM1000 UWB transceiver [9].

One significant benefit of using the fully integrated module is that it simplifies the integration to the design of PCB. The module already includes all necessary peripherals and no RF design is required.

The DWM1000 uses the SPI protocol for communication with the micro- controller. The host communication is a slave-only SPI, meaning that the module can only act as a slave and the microcontroller will therefore act as the host. It supports different data transfer protocols, clock polarities and phases. The different modes of the module is selected using the general- purpose input/output (GPIO) pin 5 sets SPI polarity and GPIO 6 sets SPI phase. A block diagram of the DWM1000 module is shown in figure 3.4, and connections between the DWM1000 and microcontroller is shown in table 6.

(30)

Figure 3.4: Block schematic of the DWM1000 module [4, p. 1]

Table 6: Connections between DWM1000 and ATSAM3X8E

Signal name Pin I/O Description Pin

DWM1000 ATSAM3X8E

RSTn 3 DIO Reset pin 132

IRQ 22 DO Interupt request output 144

SPICSn 17 DI SPI chip select 102

SPICLK 20 DI SPI clock 110

SPIMOSI 18 DI SPI data input 109

SPIMISO 19 DO SPI data output 108

VDD3V3 6, 7 P 3.3V supply pins

VDDAON 5 P External supply of

Always-On portion of chip

GND 8, 16, 21, 23 24 G Common ground

(31)

3.4 Heart rate measurement, AD8232

The ECG measurements in this project are made using the AD8232. The AD8232 module is an integrated signal conditioning block. The module is designed to extract, amplify and filter small signals in noisy conditions. The module has an uncommitted operation amplifier which enables it to create a three-pole low-pass filter for removing additional noise. A functional block diagram of the AD8232 is shown in figure 3.5.

Figure 3.5: Function block diagram of AD8232 module[1, p. 1].

The module can be connected in different configurations depending on its application. The different configurations can be found in the AD8232 datasheet [1, p. 25]. In this project the Cardiac monitor configuration will be used. The cardiac monitor configuration is a configuration for monitoring the shape of an ECG waveform. One drawback of this configuration is that the patient needs to remain relatively still during measurements, because the measurements become more sensitive to motion artifacts. The configurations consist of a 0.5Hz two-pole high-pass filter followed by a two-pole 40Hz low- pass filter. A third electrode is used for optimal common-mode rejection.

The ATSAM3X8E reads the measurements from the AD8232 using one analog input at pin 78. The electrode leads are connected to the PCB via a 3.5mm jack. A full circuit diagram is shown in appendix B.

(32)

3.5 USB On-The-Go

Universal Serial Bus On-The-Go (USB OTG) is a specification that allows two USB devices to communicate with each other without requiring a com- puter. USB devices usually consists of a host and a peripheral. The host initiates all communications on the bus and provides power, the peripheral can just communicate with the host device.

All OTG connections are between an A-device and a B-device. When connecting an A USB plug into an OTG port it becomes an A-device. The device connected to the other end of the cable, which can be another OTG device or a peripheral becomes the B-device. When these devices connect with each other, the A-device functions as the host, and the B-device as the peripheral [3].

Some peripheral devices have built in OTG capabilities and an AB con- nector allowing it to directly act as both host and peripheral. In some devices that supports OTG but only has a B-connector, an adapter can be used, con- verting it to an A-connector. A picture of a USB OTG adapter is seen in figure 3.6.

For a device to support OTG, it must have an OTG port and support role switching protocols. It also requires to be able to supply enough power on its VBUS to supply the connected peripheral.

Figure 3.6: USB-C to USB OTG-adapter.

(33)

3.6 Printed circuit board

3.6.1 Overview

All components used for the prototype are surface mount devices (SMD).

The passive components were chosen to be the 2012 size package if available.

The 2012 size package are relatively small components but large enough to be hand soldered using a soldering iron if needed.

When the components had been chosen, the schematics was drawn. All schematics and PCB design was drawn using Altium Designer. Altium De- signer is a computer-aided design (CAD) program for design of printed cir- cuit boards. Altium Designer offers a design vault where the user can import pre-made components to be used in the project.

Even though there is pre-made components, most of the components were designed manually using Altium Designer built in IPC compliant tool. This was to ensure that all pin configuration and footprints would be correct.

The schematics are drawn on multiple pages with smaller circuits. By doing so, it gives a better overview of the whole system and makes it easier to read. An overview of how the components connect with each other is seen in figure 3.7.

Since this is only a prototype, both nodes will have identical PCBs. The only thing that differ them apart is that the receiving node doesn’t have the ECG measuring circuit assembled. 3D-models of the designed PCB is seen in appendix C.

Figure 3.7: Overview of the circuit.

(34)

3.6.2 PCB layout

Before starting the design of PCB, some design rules and PCB specifica- tions must be chosen. The design rules are set both by the manufacturers tolerances and rules to minimize EMC as described in section 2.4.1. The manufacturer can also produce PCB with different specifications and layer stack-up which must be chosen to meet the requirements of the project.

It was decided to use a 4-layer PCB with the manufacturers standard layer stack-up. The benefits of using a 4-layer board is that it can use dedicated power and ground layers and multiple routing layers. Using dedicated power and ground layers results in a low impedance power and ground network.

The layer stack-up used and what each layer is used for is seen in table 7.

Table 7: Layer stackup of 4-layer PCB.

Material Thickness Layer Description

Copper 35 µm Signal layer 1 Signal traces and components Dielectric 0.175 mm Dielectric constant 4.29

Copper 35 µm Ground layer Ground plane

Dielectric 1.13 mm Dielectric constant 3.96

Copper 35 µm Power layer Power traces and polygons Dielectric 0.175 mm Dielectric constant 4.29

Copper 35 µm Signal layer 2 Signal traces

When choosing the design rule, it was decided to use the manufacturers

“standard tolerance”. The standard tolerance are suitable for this project and does not increase the cost of manufacture. Also, the minimum spacing be- tween components was set to 1mm for easier assembling. The manufacturers design tolerance and specifications is seen in table 8.

Table 8: Specifications of PCB.

Material FR-4

Layers 4

Thickness 1.6mm

Min track/spacing 0.1524mm

Min hole size 0.3mm

Surface finish HASL with lead Via process Tenting vias

Copper thickness 35µm

(35)

3.6.3 Component placement

Placing the components is one of the most important and time consuming during the design of PCB. The general idea is to place a component as close as possible to its connecting component. A good placement of components makes the routing easier and the traces can be kept short. It’s also important to place sensitive circuits as far away as possible from noise producing sources to reduce EMI as described in section 2.4.1.

Since the microcontroller is the “heart” of the PCB, it’s placed first to see how the peripheral circuits could be placed to minimize trace length. There are also several other things to think about when placing the components.

The clock circuits are high-threat circuits and needs to be placed as close as possible to the microcontroller to reduce the risk of crosstalk. The USB traces uses differential signaling as described in section 2.4.4 and is not noise sensitive so it can be placed close to the clock circuits. Other circuits that also produces noise is the power supply and UWB transceiver. All these noise producers need to be kept as far away as possible to the ECG measuring circuit. An overview of the circuit placement is seen in figure 3.8.

Almost all components are placed on the top layer of the PCB to make the assembling easier. The decoupling capacitor is placed as close as possible to the components power pin as described in section 2.4.2.

Figure 3.8: Overview of PCB layout.

(36)

3.6.4 Trace routing

Routing of traces is another important step in the PCB design. When routing the traces, it’s important to have the components orientated in such a way that the traces become as untangled as possible. The traces were routed on the top and bottom layer, except for some power traces that are routed on the power layer. It is also a good practice to try to route the traces on the top layer vertical and on the bottom layer horizontal or vice versa.

The minimum width of the traces is set to 0.2 mm and is also set to be the preferred width. Some power traces running on top and bottom layers are as wide as 0.8 mm depending on space available, pin width, the length of the trace and potential amount of current going through it.

When a trace needs to be connected or routed to another layer, vias are used. A via is a hole drilled on the PCB that is made conductive through electroplating. The vias used has a drill size of 0.3 mm and diameter of 0.65mm, except for wide power traces that had a drill size of 0.6 mm and diameter of 1.0 mm to match the width of the trace.

There are some traces that requires some extra attention when routed.

The clock signal traces need to be kept as short as possible to reduce EMI.

The USB 2.0 data lines is a differential signal which requires to run parallel, have an controlled impedance of 90 Ω ± 15% [26, p. 5] and matched length as described in section 2.4.4 to function properly. By using equation 9 and 12 in section 2.4.3 and 2.4.4 the differential impedance can be calculated. A differential pair with the width of 0.2 mm and 0.2 mm spacing was calculated to be 93.38 Ω, which is within the tolerance of USB 2.0 requirements. Both the clock traces and USB traces is prioritized to be routed on the top layer as vias ads extra impedance to the trace.

The clock traces, USB differential pair and SPI data traces are considered to be high-threat signals. So, to minimize the risk of crosstalking, the 3- Width rule described in section 2.4.5 is applied.

All unrouted space that is left over after the routing is covered in ground polygons on all layers except the power layer and the area on all layers underneath the UWB antenna. These ground spaces connect to the ground layer using ground vias spread out on the PCB to ensure a low impedance return path. Ground vias are also placed on areas forming ground islands between traces and on the tip of pointy areas that otherwise may act as an antenna.

(37)

3.6.5 Component assembly

The assembling of the PCB can be done either by manual hand soldering or with a reflow oven. The ATSAM3X8E microcontroller used in this project have 144 pins that are 0.2 mm wide and 0.3 mm edge-to-edge spacing between each pin. These small pins are nearly impossible to hand solder using a soldering iron, therefore a reflow oven was used.

A SMD stencil was ordered together with the prototype PCB and is used for applying solder paste. The SMD stencil used is a 0.12 mm thick metal sheet which have holes cut out perfectly for all solder pads, a picture of the stencil is seen in appendix D. The stencil is carefully aligned and secured on top of the PCB before the solder paste is spread over the stencil using a putty knife. The putty knife is dragged over the stencil until all solder paste is in level with the edge of the stencil, this ensures than an even layer of solder paste have been applied on all solder pads. A picture of solder paste applied to the solder pads is seen in figure 3.9, note the solder pads on the right don’t have solder paste applied.

Figure 3.9: Solder paste applied on solder pads.

(38)

Solder paste is available in different compositions. It’s was decided to use a composition of 63% Tin and 37% lead, since solder paste containing lead is easier to solder due to its lower melting temperature. Solder paste is also available in three different powder sizes T3, T4 and T5. The different powder size for each type is seen in table 9.

Table 9: Powder size of different solder paste types [21].

Type Less than 0.5% 10% Max. 80% Min. 10% Max. less

larger than (µm) between (µm) between (µm) than (µm)

3 60 45 - 60 25 - 45 25

4 50 38 - 50 20 - 38 20

5 40 25 - 40 15 - 25 15

Due to the small width and pitch of the microcontroller pins, the type 4 solder paste was chosen to minimize the risk of solder bridges.

When the solder paste had been applied, each component was carefully put in place using tweezers. After all components had been placed on the PCB it was put into the reflow oven. The reflow oven melts the solder paste using infrared heaters controlled by a time-temperature profile. A picture of the PCB being reflowed in the oven is seen in figure 3.10, note the temperature sensor close above the PCB which controls the time-temperature profile.

Figure 3.10: PCB during reflow process.

After the reflow process was completed, the PCB was carefully inspected using a magnifying glass. It is important to look for solder bridges, insuf- ficient amount of solder and other defects to be corrected before function

(39)

4 Software implementation

4.1 Android application

To present the ECG waveform on the smartphone an Android application was developed. The application was developed using Android Studio. Android Studio is the official IDE for development of Android applications and is based on IntelliJ IDEA [6]. The programming code can be written in either Kotlin or Java language, in this project all the code is written in Java.

4.1.1 Architecture

When developing a new Android application, it is important to design it using recommended architecture guidelines which can be found on Android Developers webpage [5]. An overview of the used architecture can be seen in figure 4.1.

Figure 4.1: Overview of android application architecture.

The application in this project should be able to read and transmit USB serial data to and from the designed PCB and present the measured ECG values in a graph. The applications consist of a Main Activity which handles the application, fragments which displays different pages of the application and a USB service that handles USB communication. The user interface (UI) for each page of the application is designed with the built-in layout editor

(40)

that creates XML layout files. Each layout file connects to its associated fragment that control its behavior.

Each fragment and Main Activity communicate with each other using ViewModels. The ViewModel is a built-in class that is designed to store and manage UI-related data. By using ViewModels as a layer between frag- ments/main activity, it allows the data to survive configuration changes such as screen rotations [8]. Another benefit of using ViewModels is that they feature LiveData, this means that functions or part of the code can execute when the LiveData changes its value. Each part of the application will be described in detail in following sections.

4.1.2 Main activity

The main activity is always active when the application is running and han- dles the fragments, messages from USB service and initiate variables. It has a navigation drawer which one can select which fragment to display, a function to restart the application and a function to start/pause incoming USB data.

When "Start communication" is pressed, the application sends the number

“1” to the USB and when "Pause communication" is pressed, it sends the number “0”.

Since the USB serial data don’t transfer a completed string at once it must be built into a sentence. It begins building the sentence when a dollar sign ($) is detected, which marks the beginning of a sentence. It then stores the incoming data into a string until it detects “\n” (command for new line), which marks the end of the sentence. If the second letter of the completed sentence is a “M” it passes the message to the graph fragment, if it’s a “S” it passes it to the debugging fragment.

4.1.3 USB service

To be able to use USB serial communication in the application, the open source project UsbSerial developed by the user felHR85 is used [10]. UsbSe- rial supports several of the most used USB to serial chipsets and communi- cation device class drivers. The UsbSerial example project is implemented into the developed application of this project.

The USB serial class is built as a producer-consumer handler. This means that the USB serial class (the producer) runs on a different thread then the Main Activity, and buffers up data until it’s consumed by the Main Activity.

This class also handles different USB notifications from the operating sys- tem (OS) such as USB attached, detached and permission responses via a

(41)

phone, the user is prompted to grant access to the device before the commu- nication is started.

The serial data received from the USB port is in byte streams and is then converted into a string before being passed to the Main Activity. To be able to be compatible with the microcontroller software, the serial baud rate is modified to 115200.

4.1.4 Help fragment

The help fragment is the the first fragment that shows when the application is started. This page only shows an instruction on how the electrodes should be placed on the patients body.

4.1.5 Heart monitor fragment

In the heart monitor fragment, only a live graph will show the measured ECG values. To be able to get a plot in the application the open source project GraphView developed by the user jjoe64 is used [12]. The GraphView project supports multiple plotting types and is highly customizable.

The Main Activity sends the incoming measured data to the heart monitor fragment. The fragment extracts the x- and y-values from the data string and converts them to double before being put into series and then plotted.

4.1.6 Settings fragment

The settings fragment handles all the personalized settings for the applica- tion. The settings are stored into SharedPreferences interface [7]. By storing the settings, each setting will be initialized to its previous value when the application is restarted.

4.1.7 Debugging fragment

The debugging fragment is mainly used during development of the applica- tion. It is used to see USB status, incoming serial data and a log of status messages.

(42)

4.2 Microcontroller code

To program the MCUs, Arduino IDE was used. Arduino IDE is an appli- cation used to write and upload code to Arduino compatible boards. All programming is written in C.

The microcontroller programming consists of two different programs, one for each node. The transmitter node measures the ECG of the patient and then sends it via UWB to the receiver node. The receiver node takes the data and transfers it over USB to the Android application. To use the DWM1000 UWB module, the DW1000 library was imported in both programs [23].

Each program will be described in further detail in following sections.

4.2.1 Transmitter node

The transmitter code is based on the example code BasicSender provided by the DW1000 library [23]. The program starts by initializing the pins that are going to be used by the microcontroller and settings for the DWM1000 module. The initialize settings are seen in table 10.

Table 10: Initialize settings of transmitter code

Description Value

Analog input A0

SPI reset D9

SPI interupt D2

DWM1000 device address 5 DWM1000 network ID 10

After the program is initiated it reads the measurement from the analog input, get current time of the measurement and puts it into a string. The program then tries to send the string, and if it was sent successfully it repeats the process. If the message wasn’t sent successfully it retries until it succeeds.

A flow chart of the program is seen in figure 4.2.

(43)

Figure 4.2: Flowchart of transmitter code.

4.2.2 Receiver node

The transmitter code is based on the example code BasicReceiver provided by the DW1000 library [23]. The program starts by initializing the pins that are going to be used by the microcontroller and settings for the DWM1000 module. The initialize settings are seen in table 11.

Table 11: Initialize settings of receiver code

Description Value

USB baud rate 115200

SPI reset D9

SPI interupt D2

DWM1000 device address 6 DWM1000 network ID 10

After the program is initiated it reads the USB serial port to check for the start command from the Android application. If it has received a start message and a message has been received from the DWM1000 module it con- tinues to handle the received message, if a message was not received it checks if an error has occurred. When the message has been received successfully it

(44)

formats the data before being sent to the USB port. The message formats and description is seen in table 12, where YYY is the ECG amplitude value, sss is seconds and mm is milliseconds of system time. A flowchart of the receiver code is seen in figure 4.3.

Table 12: Initialize settings of receiver code

Type Start symbol Message format End symbol

Status message $S "Status message" \n Measurement $M "YYY,sss.mm" \n

Figure 4.3: Flowchart of receiver code.

(45)

4.3 Adaptive notch filter

The potential difference measured by the ECG is relatively small and highly sensitive to EMI. One source of high-risk EMI is the interference induced by the 50Hz power line frequency. The power line interference is affecting the ECG measurement and needs to be filter through a digital filter to obtain a clean ECG waveform.

The ECG waveform frequency components are ranging between 0 – 100 Hz as described in section 2.1.1, meaning that the power line frequency is within its bandwidth. To be able to filter only the power line frequency without affecting the ECG waveform components makes the IIR notch filter described in section 2.3.3 well suited for the task. The frequency of the power grid is not always stable at exactly 50Hz but instead varies between 49.9 to 50.1Hz. This frequency variation is depending on the momentary power consumption and production to the power grid. To compensate for the varying frequency and still have a narrow notch bandwidth, the filter must be adaptive. The benefits of a digital filter are that the filer coefficients can easily be modified to make it adaptive.

Due to lack of time in this project the digital filter was never implemented into the software. To demonstrate how to perform this filtering of an ECG signal the filter was instead constructed and simulated using MATLAB.

The simulation is performed using an simulated ECG waveform sampled at a sampling frequency of 200 Hz, which meets the Nyquist criterion de- scribed in section 2.3.2.

A fast Fourier transform (FFT) is performed using the built in function fft, to find the current power line frequency. When the FFT is completed, the program finds the frequency component with the highest amplitude between 49 - 51 Hz to use as the notch frequency. The IIR notch filter coefficients are calculated using equation 4 described in section 2.3.3, using a bandwidth of 3 Hz and a filter gain of 1. The filter could then be visualized using the built in fvtool. The filters pole zero plot and magnitude response is seen in figure 4.4 and 4.5.

(46)

Figure 4.4: Pole zero plot of IIR notch filter at 200Hz sampling frequency.

Figure 4.5: Magnitude response of IIR notch filter at 200Hz sam- pling frequency.

A 50Hz sine wave is then added to the ECG waveform to simulate the interference induced by the power line. The noisy ECG waveform is then filtered using the built in function filter. The MATLAB code used is found in appendix E.

(47)

5 Results and discussion

5.1 Prototype system

Figure 5.1 shows the completed prototype system. The system consists of a Samsung galaxy S10 Android smartphone, USB OTG adapter, receiving node, transmitting node, ECG electrodes and a power bank. The receiving node is connected to the Android smartphone using a USB OTG adapter, the ECG electrodes is connected to the transmitting node which is powered by the power bank.

Figure 5.1: The prototype system with the receiver node to the left and the transmitting node to the right.

5.2 Printed circuit board prototype

When the prototype PCB had been assembled it resulted in two well-functioning nodes. The units are instantaneously recognized when connected with USB to a computer. The programming code is uploaded without any problems using Arduino IDE set to Arduino DUE(Native USB port). A picture of both nodes is seen in figure 5.2, note that the receiving node (left PCB) don’t have the heart measurements circuit soldered.

(48)

Figure 5.2: Prototype PCB, receiving node to the left and transmitter node to the right.

The transmitting node ECG measurement were tested with the ECG electrodes placed as described in section 2.1.2 and connected with a USB cable to a computer. The measurement were plotted using Arduino serial plotter set to 115200 baud, the resulting graph is seen in figure 5.3. The graph shows a clear ECG waveform with the P-wave, QRS complex and T-wave visable as described in section 2.1.1.

Figure 5.3: ECG waveform in Arduino serial plotter.

References

Related documents

A test chip had shown that the single ended design achieves a dynamic range of 15 bits for signal offsets up to ±1.2V [3].. The measured power consumption for one single modulator is

Again, the neck pain risk we found from rotation in a group of forklift operators (OR 3.9, Table 2 ) seems reason- able given that forklift operators are more exposed to un-

Kvinnor som inte var sexuellt aktiva uppgav att intresset inte fanns, att de var för trötta eller upplevde fysiska problem som gjorde att deras sexuella umgänge försvårats eller

Om totalkostnaden för dessa komponenter tas med i beräkningen redan vid förstudie och projektering skulle det kunna leda till minskade utgifter för fastighetsägaren över

Equation (3) shows the functional relationship between the dependent or outcome variable (i.e. child’s years of schooling) and a set of potential explanatory variables,

Enligt syftet så har forskningen tagit fram ett antal framgångsfaktorer för irreguljär krigföring i mellanstatliga konflikter, faktorerna kommer ur gerillakrigföring där en

Omsatt från analytiska kategorier till teoretiska begrepp uppnår Tyskland en immediate avskräckning genom punishment och en general avskräckning genom denial. Det sker genom

Det kan även anmärkas att förhörsledarens i tingsrätten lämnade uppgifter inte ter sig särskilt trovärdiga vid en jämförelse mellan uppgifterna och de av honom själv