<<

UPTEC E 18 010 Examensarbete 30 hp Juni 2018

Wireless electrocardiogram trans- mission based on ultra wideband radio

Oskar Flink Abstract Wireless electrocardiogram transmission based on ultra wideband radio Oskar Flink

Teknisk- naturvetenskaplig fakultet UTH-enheten Ultra wideband (UWB) communications has been a subject of much discussion over the last decade. The method of UWB has had a hard Besöksadress: time to establish itself among other methods such as and Ångströmlaboratoriet Lägerhyddsvägen 1 WiFi but as internet of things (IoT) gains a foothold in our daily Hus 4, Plan 0 lives, UWB has presented some new application areas. These application areas are, among other things, self driving cars, Postadress: energy efficient data transfer, health care applications, sensor Box 536 751 21 Uppsala networks and real time location systems.

Telefon: This project aims to use UWB communications to real-world 018 – 471 30 03 applications, specifically, electrocardiography (ECG) - an

Telefax: application in health care in this project, and develop a 018 – 471 30 00 prototype for the application.

Hemsida: The prototype consists of two Android smart phones and two UWB http://www.teknat.uu.se/student modules (EVK1000 evaluation kits from DecaWave, Inc). Each smart phone connects a UWB module so that the two smart phones, one as sender and the other as receiver, can communicate directly through UWB radios. This is intended to serve as a proof-of-concept that UWB devices are well suited for short range data transfer applications.

The result achieved by the project is an android application along with sending and receiving programs for the development boards by Decawave and additional information regarding UWB and its uses. The results also include a comparison of UWB, Bluetooth and WiFi as of todays standard. The goal of the project is to learn how android applications are programmed, how UWB is used in todays technology and how to program and use development boards presented by companies.

The prototype has been built and shown that 12-lead simulated ECG signals from the sender can be transfered to the receiver through the UWB communications. The work includes programming (in C) the two UWB modules for UWB communications, and Java for the android applications (programs) on the smart phones. The Android application is handling transmission of ECG signals to the sending UWB module and then receiving them from the receiving UWB module as well as displaying them on the receiver. The future work to continue the present project is to replace the sending smart phone by an ECG device that sends real ECG signals.

Handledare: Håkan Sjörling Ämnesgranskare: Ping Wu Examinator: Tomas Nyberg ISSN: 1654-7616, UPTEC E18 010 Tryckt av: Uppsala Sammanfattning

I dagsl¨agetfinns det m˚angaolika s¨attatt skicka information tr˚adl¨ost,de vanligaste s¨atten¨arWiFi och Bluetooth men en mindre utforskad teknik ¨ar Ultra-Wideband, UWB. Det ¨aren teknik som blir mer och mer popul¨aratt anv¨andamellan apparater som inte beh¨over l˚angr¨ackvidd och samtidigt vill s¨andamycket information. En av teknikens st¨orstaf¨ordelar¨aratt den ¨arv¨aldigtenergieffektiv vilket passar bra till portabla applikationer. N˚agraav dessa applikationer ¨arsj¨alvk¨orandebilar, lokaliseringssystem, medicinala l¨osningar och tr˚adl¨osdata¨overf¨oring. I det h¨arprojektet beskrivs hur tekniken f¨orUWB fungerar och vad den kan anv¨andastill. F¨oratt visa anv¨andningenpraktiskt har en prototyp f¨ors¨andningav EKG-signaler mellan telefoner med hj¨alpav UWB har tagits fram. EKG, eller ECG st˚arf¨or electrocardiography och ¨aren sorts hj¨art¨overvakning som l¨akare anv¨ander f¨oratt hitta onormala hj¨artslagoch hj¨artflimmer.Tanken bakom prototypen ¨aratt en patient ska kunna ta ett ECG under l¨angretid. Informationen ska tr˚adl¨ostskickas till en telefon s˚aatt patienten inte ska beh¨ova ta upp l¨akartid och kunna b¨araden utan att vara bunden till en plats. Prototypen best˚ar av tv˚aAndroid smartphones som ¨arkopplade till tv˚aUWB- s¨andare. Kommunikationen mellan telefonerna och s¨andarnaanv¨anderUSB och kom- munikationen mellan s¨andarnaanv¨anderUWB. Detta f¨oratt telefoner inte st¨oderUWB- kommunikation ¨an,vilket g¨oratt en extern s¨andare¨arn¨odv¨andig. S¨andarnasitter p˚a utvecklingskort fr˚anDecawave kallat EVK1000 och dessa sk¨oterall den tr˚adl¨osakom- munikationen. N¨ars¨andningeng¨orsmellan telefonerna simuleras ECG-signaler i ena telefonen, skickas till UWB-s¨andarensom skickar det vidare till mottagaren. Hos mottagaren ritas dessa signaler ut i telefonen och anv¨andaren kan d˚al¨attse hur dessa ser ut. Signalerna simuleras ist¨alletf¨oratt fysiska m¨atningartas p˚agrund av att dessa ¨arsv˚araatt g¨ora. Det kr¨aver v¨alkalibrerad utrustning och utan s˚adanutrustning ¨ardet sv˚artatt fastst¨alla att signalerna kommer fram korrekt. Tanken med projektet ¨aratt visa hur UWB kan anv¨andassom ett s¨andningsmedium och grundligt visa en praktisk applikation till detta. Att anv¨andaUWB inom medicinala l¨osningar¨arett steg till att f˚amer energieffektiva apparater med l¨angrebatteritid och samtidigt ha en s¨aker ¨overf¨oringav information. Detta kan i framtiden str¨acka sig l¨angre ¨anbara ECG och skulle kunna anv¨andastill att skicka vilken data som helst. Resultatet av projektet blev en android-applikation som kan kopplas upp till De- cawaves EVK1000 utvecklingskort. Detta kort har programmerades till att kunna ta hand om informationen som skickas fr˚anandroid-applikationen och hantera meddelanden

i som skickas mellan tv˚autvecklingskort. Applikationen inneh˚allermenyer f¨oratt s¨atta upp USB-kommunikationen och hanteringen av denna. Den kan skicka ut ECG signaler ¨over tolv kanaler som sedan ritas upp i tolv olika f¨onsterhos mottagaren. I rapporten tas ¨aven f¨or-och nackdelar om UWB upp och en j¨amnf¨orelsemed Bluetooth och WiFi har genomf¨ortsf¨oratt visa skillnaderna mellan dessa protokoll som motivation till varf¨or just UWB passar bra till detta ¨andam˚al. M˚aletmed projektet och rapporten ¨aratt visa att UWB l¨amparsig f¨orm˚angaolika applikationer, bland annat ECG-signalhantering som anv¨andsinom sjukv˚arden.M˚alen innefattar ¨aven att bygga f¨orst˚aelseinom Androidprogrammering, programmering av utvecklingskort och tr˚adl¨oskommunikation. Den ger ¨aven insikt i hur protokoll anv¨ands, i detta fall IEEE 802.15.4-2011 samt hur projekt likt detta kan l¨aggasupp och hanteras. Projektet har legat som grund till fler andra projekt som p˚abyggnad av ECG-hantering och ¨aven distansm¨atningmed hj¨alpav UWB.

ii Acknowledgements

I would like to give a special thanks to Ping Wu, H˚akan Sj¨orling,Andreas G¨awerth, Viktor St˚ahl,Maria Toll and Tommy Holmberg for their support during this project.

iii Contents

1 Introduction 1 1.1 Background ...... 1 1.2 Overview ...... 3 1.3 Objectives ...... 3 1.4 Tasks and scope ...... 4 1.4.1 Tasks ...... 4 1.4.2 Limitations ...... 4 1.5 Outline ...... 5

2 Theory 6 2.1 Electrocardiogram ...... 6 2.2 Ultra wideband (UWB) communications ...... 7 2.2.1 Signals of UWB, wideband and narrow band ...... 7 2.2.2 Spectrum ...... 8 2.2.3 Path loss models ...... 10 2.2.4 Interference and noise ...... 10 2.2.5 Modulations ...... 11 2.2.6 Multiple access ...... 11 2.2.7 Error correcting ...... 13 2.2.8 Communications protocols ...... 15 2.3 UWB Ranging protocol ...... 19

3 Implementation 20 3.1 System overview ...... 20 3.2 Hardware ...... 21 3.2.1 Android devices ...... 21 3.2.2 EVK1000 evaluation kit ...... 22 3.3 Software and development tools ...... 25 3.3.1 Android Studio ...... 25 3.3.2 CooCox IDE ...... 25 3.3.3 MATLAB ...... 26 3.4 Implementation ...... 27 3.4.1 EVK1000 programming ...... 27 3.4.2 Android Application ...... 32

iv 4 Results and discussion 36 4.1 Prototype ...... 36 4.2 Performance ...... 36 4.2.1 Data rate ...... 37 4.2.2 Latency ...... 37 4.2.3 Energy consumption ...... 38 4.3 Android application ...... 38 4.4 Problems and solutions ...... 38 4.5 Comparison of wide and narrow band communication ...... 39

5 Conclusion and future work 41

References 43

v Abbreviations and definitions

Acronym Definition AB Aktiebolag, corporation ACK Acknowledged frame ADC Analog to Digital converter ALOHA Multi access method ASCII American Standard Code for Information Interchange AWGN Additive White Gaussian Noise b Bit B Byte BLE Bluetooth Low Energy BPM Burst Position Modulation, see PPM. BPSK Binary Phase Shift Keying BT Bluetooth CDMA Code multi-access CRC Cyclic redundancy check, error detecting code dB Decibel dBm Milli decibel ECC Error correcting code FCC Federal Communications Comission FDMA Frequency Division Multiple Access FEC Forward error correction GUI Graphical User Interface IDE Integrated Development Environment IEEE Institute of Electrical and Electronics Engineers IoT Internet of Things MAC Media Access layer MHR MAC header NACK Not acknowledged OSI Open system interconnection PHR PHY header PHY PPM Pulse Position Modulation PRF Pulse repetition frequency RLTS Real Time location systems RS Reed-Solomon

vi SECDED Single-Error-Correct Double-Error-detect SFD delimiter SHR Synchronization header TDMA Time Division Multiple Access USB Universal Serial UWB Ultra Wide Band W Watt WiFi Wireless Network 802.11 standard

vii 1 Introduction

1.1 Background Electrocardiography (ECG) is often performed in a hospital. This occupies the doctor and it is also costly to keep patients with long term heart monitoring in hospital care. The idea behind this thesis project is to create a wireless communication solution that would make the ECG device easier to wear for extended periods of time to monitor heart activity. Several sensors are used when performing an ECG meaning that lots of data needs to be sent to a base unit which, in this case, is a smart phone. UWB communications and ranging have attracted lots of interest of academia and industries because it has many advantages:

• High time resolution for precise localization

• High energy efficiency

• Range/bitrate scalability

• Robust to interference and multipath

• Difficult to intercept (in traditional ways)

• Radio suitable for wireless sensors.

UWB has been researched extensively in theory but not so much in experiment. With the advent of commercially available UWB transceiver IC chips, e.g., DecaWave’s IC chip, DW1000 [1], much interest in UWB communications and ranging has, during the past two or three years, been shifted to realization and implementation. DecaWave recently claimed that they are going to integrate their UWB chips in smart phones in the near future. Thus, it is possible to use UWB radios to direct communications between smart phones, which is called device-to-device (D2D) communications; and communications of a smart phone with UWB-based wireless sensor networks, which is suitable for the Internet of things (IoT). The D2D communications can relieve the larger radio stations as much of the traffic is sent within a smaller area. The UWB-based sensor networks can be used for applications such as life monitoring and it can be set up in smaller networks that only communicates with one main unit, a smart phone, that can in turn communicate with the outside world through WiFi or 3G/4G. Using UWB will also make these smaller networks easier to make portable compared to WiFi as it’s more energy efficient and the devices can run much longer on battery using UWB.

1 Other applications include D2D communications in mobile phones used in text mes- sages and cellphone calls that uses UWB instead of the ordinary cell network. Another application of UWB device-to-device could be large festivals where lots of people are situated and data traffic can be very heavy. The project is done in collaboration with a company called Syntronic AB in G¨avle which is a company that produces electronics as consultants for other companies.

2 1.2 Overview The project is realised with two smart phones connected via USB to two development cards. As of today (2018), very few phones support UWB transmission so the phones need to connect a stand alone module to handle the UWB transmission. The transmitter and receiver communicates via USB to the UWB modules and the modules communicates via UWB with each other. As seen in Figure 1.1 the complete system has four main modules, two phones and two UWB modules

USB cable Smart phone UWB node transmitter T

USB cable Smart phone UWB node receiver R

Figure 1.1: Brief overview of setup. Schematic of the project setup showing the direct communications of two smart phones through UWB communications. The transmitting smart phones (T) is connected to a UWB module, and the receiving smart phone (R) is connected to another UWB transceiver.

1.3 Objectives The thesis project aims to investigate a energy efficient wireless method of sending and receiving data using UWB communications. Other candidates for this purpose are WiFi and Bluetooth. The messages sent between the smart phones are electrocardiogram signals, ECG signals, which are simulated and sent from one Android device to another via the evaluation kit EVK1000 from Decawave. The setup will serve as a proof of concept that UWB can be used to send streamed data as well as to provide a good foundation for future work with Decawave products. It will also serve as a comparison between other wireless technologies.

3 1.4 Tasks and scope This master thesis project will investigate how a given signal, in this case ECG, can be sent over multiple channels. The suggested method to be used is to send over multiple frequencies and then filter the signal in the receiving end using wide band-pass filters. The signal is to be simulated in MATLAB, sent via the analog sound and received via an ADC to the development cards as to simulate how a real ECG signal would be acquired from probes on a patient.

1.4.1 Tasks For this project a literature study will be the first step, after that familiarization of the testing equipment for the different technologies is necessary to find out how to design and implement the modules to create a system that can measure and process data and then send that data wireless.

• Literature study, investigate the following:

– Current technology with ECG. – Ultra Wideband, WiFi and Bluetooth. – Energy cost in the different technologies.

• Design an Android application to send/receive data through USB.

• Program EVK1000 board to handle USB messages and sending them between the two cards.

• Measure/calculate performance of EVK1000 for indoor data transmission.

1.4.2 Limitations Before the project was started some of the proposed limitations were that UWB had not been researched as much as other wireless communication techniques, e.g., WiFi or Bluetooth. Thus there are not much support and working prototypes available. The tools presented to realise the project were two smart phones, two EVK1000 evaluation kits that contains UWB transceivers and the necessary wired connections between them as seen in Figure 1.1. During the project many hardware related problems were presented. The most problematic problems were that the EVK1000 did not support multichannel transmission as first proposed. The EVK1000 can only send on one channel and receive on a different

4 (if required). The EVK1000 can not receive analog input either. Proposed solution to this is to simulate the signals and directly send them via USB from the Android application.

1.5 Outline The report is structured so that the reader can get all the required information regarding the theory in section 2, how the project was implemented in section 3 and the results along with discussion regarding the work process of the project is handled in section 4. The Theory section first introduces what an ECG is and how it’s used in todays technology. After that it takes up what UWB is and how such signals are sent. It also takes up which communication protocols are used. The Implementation section shows how the hardware was connected and used, as well as showing the software used in the project. The programming of the Android device as well as the programming of the development cards are presented here as well.

5 2 Theory

2.1 Electrocardiogram An electrocardiogram is a way to measure electric activity of the heart. This is done using electrodes placed directly on the skin that detects changes that forms when the heart pumps blood. The detected change comes from polarization of the blood cells that produces a measurable voltage. An ECG performed by a physician is usually called a 12-lead ECG, it uses 10 electrodes that measures 12 different voltages. For this project up to 12 channels of data can be sent and recorded to simulate the 12 channels in a real ECG. An ECG can be used to detect heart deceases and irregularities within the heart. A typical ECG signal can be seen in Figure 2.1. The ten electrodes have to be connected to a central unit that measures the waveforms so the need for conducting wires would still be a problem but the central unit can be manufactured very small and energy efficient. The measured voltage from an electrode is very small (microvolts) and thus the central units contains one or several amplifiers to amplify the different signals. These amplifiers are very noise resistant. The ECG central unit also contains different filters needed in order to get a cleaner signal. The application of a wireless ECG is to detect heart defibrillation in patients that need long term monitoring. The patient would carry the ECG for an extended time and the ECG device would send data wireless to a central unit, for instance a smart phone which could forward it to a server or directly detect irregularities. Today there are already companies that produces wireless ECG units that commu- nicate with WiFi or Bluetooth and the usage or UWB as a medium of transmission has been done in research groups, however, no commercial product that uses UWB could be found. Some of these companies are LifeSync(WiFi), IMEC and V&Hecg(WiFi).

ECG Signal 1.5

1

0.5 Voltage

0

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 Time Figure 2.1: ECG signal waveform for one channel.

6 2.2 Ultra wideband (UWB) communications Ultra wideband, UWB, is as the name suggests, a method of sending information wireless that occupies a large bandwidth. It is a method that has a low energy cost and a low range. Like most wireless communication it uses electromagnetic waves that propagate through the air to convey information. It uses very short impulses to send information which gives it a very large bandwidth. The bandwidth of a UWB signal is typically >500MHz and is situated in the 3.1-10.6GHz spectrum as first governed by the FCC [2].

2.2.1 Signals of UWB, wideband and narrow band UWB signals are sent as short pulses over an order of nano seconds depending on the desired frequency. The pulse is a sinusoidal pulse that can be modulated differently for different signals. Other radio technology uses continuous signals that are modulated in frequency (fm) instead of short pulses. The short pulses is what makes UWB get its large bandwidth and low energy consumption.

2.2.1.1 UWB signal waveform UWB pulses are constructed of a toneburst with a Gaussian envelope and of other shaped envelopes but the Gaussian envelope is commonly chosen as it does not bleed over (less energy outside the desired bandwidth) into neighboring spectrum as much as for instance a rectangular pulse [3]. A pure sinusoidal pulse also bleeds over but a Gaussian pulse bleeds very little into neighboring spectrum. Gaussian signals also retain their form from time domain into frequency domain. This can be seen in Figure 2.2. Shorter pulses have wider bandwidth which can be seen in Figure 2.2. In Figure 2.2 the signal is a UWB pulse with two different frequencies and their respective bandwidth. The radio signal bandwidth is defined as the width between a lower and upper cutoff frequency. The cutoff frequencies are defined as the point where the signal gain is 3dB (√1 = 70.1%) below the maximum value of the frequency response. For some signals, 2 as UWB the cutoff frequency is defined as the point where the signal is 10dB below the maximum frequency. To calculate the bandwidth of a wideband signal the two cutoff frequencies are required. f − f %B = 200 ∗ H L (1) fH + fL where fH and fL is the high and low cutoff frequency.

7 UWB pulse 1 1MHz 0.5 10MHz 0

Amplitude −0.5 −1 −5 −4 −3 −2 −1 0 1 2 3 4 5 Time [s] x 10−6 UWB bandwidth 1 10MHz 1MHz 0.5 Amplitude

0 0 1 2 3 4 5 6 7 8 9 10 Frequency [Hz] x 106

Figure 2.2: Bandwidth showing the difference between a short and longer pulse, the amplitude is normalized.

2.2.2 Spectrum As UWB occupies large portions of the usable spectrum it also intrudes on licensed frequencies. There are a few frequencies that can be used freely by anyone and typically these spectrum are occupied by wireless appliances such as Bluetooth, wireless phones and WiFi. Using the licensed space is an illegal action and must thus be avoided. However, regulations for Europe state that the power of wide band signal has to be under -41.3dBm/MHz [4], the limit where other channels would classify it as noise. [3]. The unlicensed spectrum can be seen in Figure 2.3 and it shows the different bands that can be used for narrow band and UWB applications. The main spectrum used in narrow band are 900-930 Mhz for GSM (not shown in figure), 2.400-2.483 Ghz for Bluetooth, WiFi and other wireless appliances and 5.15-5.35 for WiFi 5G and newer wireless appliances.

2.2.2.1 Narrow band versus wide band Traditionally radio transceivers have sent out signals with a small bandwidth and received these with a narrow band filter to filter out all the unwanted frequencies. This is how radio works and when tuning in on a specific frequecy you tune this narrow band filter to

8 Figure 2.3: Licensed and unlicensed spectrum and available UWB frequency allocation

a specific carrier frequency. The amount of data you can send is limited by the width of the band you are using. They are also prone to interference from reflections (multipath fading) and are more easily jammed. [5] Wide band signals have a much larger bandwidth and they are not prone to multi- path fading in the same extent as traditional radio signals. This is because UWB uses very short pulses instead of continuous sinusoidal signals. The received signals are also received in small time windows which is what makes them a bit more resistant to multi- path fading. It is harder to detect and jam UWB signals because of their low range and low energy density. The downside to this is the intensity of the signals are very low. This comes from the regulations for sending and receiving radio signals.

2.2.2.2 Future for wide band Using wide band instead of narrow band in the future seems like a more reliable solution than using narrow band. Most bands are licensed and those that are not are getting in- creasingly crowded. Almost all sending protocols for home appliances such as Bluetooth, wireless phones and keyboards and IEEE 802.11(WiFi) uses an unlicensed narrow band around 2.4GHz. This narrow band is getting increasingly crowded as more and more devices are connecting as part of Internet of Things. Many appliances are starting to use the next unlicensed spectrum at 5.1GHz but this space will also become overcrowded in the future. This problem can be solved with increasingly complex modulation or alternatively allocating more unlicensed spectrum for home appliances. Using licensed

9 spectrum is only permitted if the sending power does not interfere with other users in that spectrum.

2.2.3 Path loss models The path loss model describes how signal power decreases for increasing distance. It has three components, path loss, shadowing and multi path. Path loss describes only how the power decreases over distance. Shadowing describes how a signal is blocked by objects between sender and receiver, meaning how different frequencies are attenuated from sender to receive. When a radio channel has almost no attenuation for a certain frequency it is called deep fading meaning that the signal can’t be detected by the receiver. This happens both in time domain and in frequency domain causing the signal to have to be re-sent occasionally. Multi path fading is the interference of your own signal due to multiple paths of the signal arriving at slightly different times. UWB is subjected to path loss as much as any radio signal, which is reduced as 1/r2 which comes from the free space model [5]. Shadowing is a fading that is not affecting UWB too much as UWB signals have such a wide bandwidth. This is because shadowing blocks certain frequencies more than others and as UWB has a large bandwidth allocating a wide spectrum the chances of the signal getting through is higher than for a narrow band transmission. This means that UWB works especially well indoor for distance measurements as the signals goes well through walls. UWB suffers a bit from multi path fading (not as much as continuous signals). This has been solved by the receiver by using a preamble signal that models the multi path fading and uses it to attenuate the signal instead of interfering [1]. This works especially good indoors as parts of the signal reflects well of flat surfaces like walls and floors. The largest downside to UWB is the low intensity of the signal which is why it has such low range

2.2.4 Interference and noise Like all electromagnetic waves UWB also gets interfered from other devices. UWB uses a very limited amount of energy as it has to follow the FCC regulations [2] meaning that it is strongly interfered with other devices. This is solved with special receivers and long preamble codes that identifies other UWB devices. The noise a signal experiences can be modeled as AWGN, additative white Gaussian noise. White Gaussian noise is a disturbance that is deployed over all frequencies. This model is used as it closely resemble the actual noise a system experiences but it’s not perfect as it’s impossible to estimate the noise exactly. The noise comes from all electric devices and background radiation.

10 2.2.5 Modulations The modulation scheme used for sending the UWB signals is a combination of BPSK and BPM. For the preamble (first part of UWB transmission) single pulses are sent with three outputs, +1 for 0◦ phase, -1 for 180◦ or 0 for no signal. These pulses are rapidly sent so the preamble takes very little time to send.

2.2.5.1 BPSK (Binary phase-shift keying) When a signal is sent a string of bits has to be modulated into sinusoidal signals that can be sent wireless. This is done by assigning the phase of the sent signal to either a 1 or 0. The easiest case of this is where each bit is represented by either 0◦ or 180◦ phase shift in the sinus signal. This then maps to ± 1 in the Re/Im plane. This means that if the sender wants to send a 1, a sinus signal with carrier frequency fC is modulated so that it has 0◦ phase shift. A zero is sent the other way around with 180◦ phase shift. The receiver can demodulate this signal by mapping the received bit so that all signals > 0 is mapped to 1 and similarly all signals < 0 is mapped to 0.

2.2.5.2 BPM/PPM (Burst/Pulse position modulation) Burst position modulation, also called pulse position modulation is a modulation that uses time to determine if the sent signal is 0 or 1. This is done by having a time frame, called symbol interval, divided into four parts as seen in Figure 2.4. The positions represent different time delays. If the burst is sent at the beginning of the frame (no delay) the received symbol is a zero or if it’s sent in the third interval (delayed) the symbol is a one.

Burst/ Guard Burst/ Guard pulse = interval pulse = interval 0 1

Figure 2.4: One time frame in BPM/PPM, the symbol time.

2.2.6 Multiple access In order for multiple users to be able to access the same medium several different tech- niques are used. These techniques have been developed and deployed as the market for radio communications grew and usually a new generation of telecommunications was

11 born when a new method was found and implemented (GSM(2G), 3G, 4G). The method used in this project is a combination of TDMA and CDMA/FDMA along with the ALOHA access method. As there are only two users in the scope of the project the CDMA/FDMA only applies if multiple users try to access the same receiver or sender. The sender and receiver operates on a set frequency band with a set code and sends information in a TDMA fashion, if multiple users access at the same time the ALOHA principle will be used.

2.2.6.1 ALOHA access method The ALOHA access method is a random access method first deployed at the university of Hawaii that allows multiple users to send over the same medium. It dictates that a user can send whenever they want and the receiver receives everything all the time. The sender will begin transmission and wait for an ACK, meaning that the package has been correctly sent. If multiple users send packages at the same time the receiver will get collided, garbled data and will not send any ACKs to the senders (unless one of the messages can be recovered with ECC). The senders will then wait and resend their data after a time t = tpackage + δ where tpackage is the time it takes for one package to be sent and δ is a randomly generated delay that prevents other users from colliding again. If multiple collisions occur the time to resend a package becomes longer and longer. ALOHA is deployed in many applications but it can be very inefficient if the number of users become too large. The expected throughput of an ALOHA system:

T = Le−L,L = λτ (2) Where T is the expected throughput and L is described as the packet rate λ, times packet transmission time, τ [5].

2.2.6.2 FDMA (Frequency-Division Multiple Access) To send multiple arrays of data simultaneously frequency-division multiple access, FDMA, is used. It is a method that divides the available spectrum, also called channel, into smaller bands, or sub channels to send data over the different channels. This is the most common way of multiple-access used today. A spectrum is divided equally into N chan- nels where each sub channel is allocating a bandwidth and some guard band. The guard band is necessary to reduce interference between channels due to Doppler shift(due to movement) and leakage between channels. Ideally you would want each sub channel to be square shaped in the frequency domain with as little guard band as possible to not waste bandwidth. In reality the sub channels overlap, bleeding over into other channels but with very low energy. This method is very useful but because of deep fading you can

12 get some channels that get very good data rate and some with really bad. To prevent all data in one array from getting lost the different data arrays are divided into smaller arrays which are sent on different sub channels. Doing this with error correcting code means that much of the data can be retrieved even if one channel is completely offline. To receive FDMA signals multiple filters are required to distinguish the different chan- nels. This method also has the disadvantage that multiple channels can bleed over and a finite amount of data streams can be used at the same time.

2.2.6.3 TDMA (Time-Division Multiple Access) TDMA uses empty spaces in time to send multiple arrays of data in the same channel. The method divides a finite amount of time into equally long time frames that send small amounts of data in each time frame. This method also need some guard time to allow all multi path interference to fade. TDMA can support a very large amount of users at the same time but with lower bitrate as the number of users get larger. This method is sensitive to timing and if you get timing problems you might end up with lots of guard time and a very low data rate. Both the sender and receiver needs to be synchronized.

2.2.6.4 CDMA (Code-Division Multiple Access) CDMA is another way of dividing multiple arrays of data to be sent simultaneously. This is done by letting each sender and receiver have a unique code, also called orthogonal coding. All senders encode their data with their unique code before all the data is sent at the same time. The receivers get the whole signal with all the data but they all decode the datastream to get the correct sender. This method can be used over any given frequency and time frame. This means that the data spectrum is very efficiently used with CDMA. Analogy: A room full of people speaking different languages all speak at roughly the same volume and frequency. For one person to talk to the others he needs to speak the same language as the other person, it wont matter if he raises his voice or speak in a higher pitch, the other user wont understand him.

2.2.7 Error correcting To correct and detect errors in transmitted messages there are many different techniques. Two of these are SECDED and CRC which can both detect errors but only one of them can correct errors.

13 2.2.7.1 SECDED (single-error-correct, double-error-detect) SECDED is the abbreviation for a Hamming code that can detect two errors in a sequence and correct one of them. The code is a linear block code that adds extra parity bits to a message that checks if the message has been received correctly. The code makes the sent message longer so the total amount of bits sent is longer and it works best in a system where few errors occur. This is used in the PHY header as seen in section 2.2.8.2. The parity bits are generated by using the other bits in the data message. Each uses specific bits in the data message where the first uses every other bit, the second uses every 2 bits, 3rd every 4th and so on. The used bits are put through an XOR gate to generate the new bits. Example: We want to encode the message 10110001, we generate parity bit P1, P2, P3 and attach them to our message. These can be used to detect if any of the affected bits are wrong with the most significant being represented more times than the least significant. The messages can be decoded by calculating the parity bits in the receiving end and compare them to the received parity bits. If they don’t match up the position of the incorrect bit can be calculated and changed. The encoded message will be 10110001001.

P 1 = XOR(bit1, bit3, bit5, bit7) = XOR(1, 1, 0, 0) = 0

P 2 = XOR(bit1, bit2, bit5, bit6) = XOR(1, 0, 1, 0) = 0 P 3 = XOR(bit1, bit2, bit3, bit4) = XOR(1, 0, 1, 1) = 1

2.2.7.2 CRC (Cyclic redundancy check) Cyclic redundancy check is a method that’s easy to implement and very time efficient. It is an error detecting code meaning that it only detects if an error has occurred during transmission but it does not correct the error. This is a very reliant code that can detect up to 99% of all errors but it cannot detect intentional errors. It is very popular and used in many systems such as USB, mobile networks and RFID transmissions. The code uses XOR circuits and shift registers to generate a code that depends on the sent message. Every message will have its own code. This code is appended to the message as 1 to 64 bits depending on the safety required. The code is generated by using a divisor, a short code that both the sender and receiver knows. This code is shifted through the message from most significant bit to least significant bit. When the divisor has been shifted through the whole message the remainder will be the CRC code. This is appended to the end of the message and the receiver can easily do the same calculation to check if the remainder is 0, if it is 0 the

14 message has been sent successfully and the receiver can send an ACK. If it is not 0 the receiver has to send back a NACK, not-acknowledged and the sender can resend the same message.

2.2.8 Communications protocols A message sent via the IEEE 802.15.4-2011 standard has three different headers which comes from the OSI model [6]. The OSI model specifies that there are seven layers for telecommunications explaining how a message is sent from user input to sent bits. The lower the number of the layer the more hardware related the layer is. For this project some of the lower layers have been used but most of that is done via the DW1000 chip. The PHYsical layer is handled by the DW1000 chip while the MAC layer is partly handled by the chip and partly by the programmer. A typical message is sent with a synchronization header, SHR, physical header, PHY header, and a media access header, MAC header. This can be seen in Table 2.1. When multiple users access the same channel the ALOHA method is defined as the standard in IEEE 802.15.4-2011 [7].

SHR PHR MHR Data Synchronization header Physical header MAC header Payload (64,1024,4096)+(8,64) 19 bits max 37 bytes max 97-122 bytes symbols

Table 2.1: The general format for UWB frames.

2.2.8.1 Synchronization header The synchronization header is a made up of two parts, a preamble sequence and a delimiter called SFD (start of frame delimiter). The preamble code is a series of pulses (symbols) sent out before data transmission is sent so to synchronize the sender and receiver. At the end of the preamble sequence the SFD tells the receiver that it should switch from receiving symbols to receiving BPM/BPSK modulated signals instead. The sender use this information to determine how the impulse response between sender and receiver looks like. This means that the receiver can use the multipath fading to its benefit instead as interference and also to time how long it takes for the most direct path to be received. Both the receiver and the sender has a preset preamble code that they use to determine this. The DW1000 has three different settings for this that is used in this project. The pulse repetition frequency, PRF, that tells us how often the preamble

15 symbols are resent. The user may chose from 16MHz or 64MHz (default). The preamble code, which there are four to choose from at 64MHz and two at 16MHz and lastly the preamble length. A longer preamble length gives us a signal with longer reach but it takes longer to send it as well.

2.2.8.2 PHY header The IEEE 802.15.4-2011 standard PHY header consists of three main parts and is modu- lated with the BPM/BPSK modulation. It uses a Hamming error correcting code, ECC, to make sure the message header is properly received. The header is 19 bits long and consists of data rate, frame length, ranging packet, header extension, preamble duration and the parity bits generated by the ECC as seen in Table 2.2.

General PHY header format Data Frame Length Ranging header preamble SECDED Bits rate packet exten- duration sion

Table 2.2: PHY header attached to messages.

16 2.2.8.3 MAC header The IEEE 802.15.4-2011 standard MAC frame is composed of a header and a footer which is a maximum of 127 bytes long. This can be seen in Table 2.3. This frame type is used in all wireless protocols following IEEE 802.15.4 but for UWB transmission not all fields are currently used [7]. The header is composed of minimum 3 bytes and maximum of 37 bytes. The payload can be a maximum of 93-122 bytes depending of header size. The header consists of multiple fields as seen in Table 2.3

General MAC format Mac Header (MHR) MAC Pay- MAC load footer (MFR) Frame Sequence Dest. Dest. Source Source Aux se- Frame FCS/ Control Number PAN Ad- PAN Ad- curity payload CRC ID dress ID dress 2 B 1 B 0/2 0/2/8 0/2 0/2/8 0/5/6/ Variable B 2 B B B B B 10/14 B

Table 2.3: The general format for UWB MAC messages with header, payload and footer.

Frame Control field The frame control field is used to specify what kind of message is being sent. It holds information regarding the rest of the header. It consists of 16 bits that are decoded in the receiver. The first bits tell of the frame type and for UWB messages it can take three values: Beacon, Data, acknowledgement/MAC command. It also holds more information regarding what the rest of the MAC header contains. This is a required field and cannot be skipped.

Sequence number field The sequence number field consists of one byte that keeps track of which message has been sent and to match ACKs with the correct message. It’s incremented for every transmission with modulo (256). Retransmissions are not being incremented. This is also a required field and cannot be skipped.

17 Destination and source PAN ID field The PAN ID tells us who the target audience is, a value of 0xffff means broadcasting. This should be set the same for transmitter and receiver.

Destination and source Address field The address tells us who sent and received the message. This should be set to a unique address in commercial use to ensure that the device does not conflict with other devices. A set of addresses can be bought from the IEEE Registration Authority to ensure that devices follow this.

Aux security header field This is used if extra security is needed. It can be used to tell the receiver about the authenticity of the message as to avoid receiving and processing messages from uniden- tified sources. This field is also used to describe which encryption should be used for the message so the receiver can decode it correctly. In this project no security is used.

FCS Field The FCS field stands for frame check sequence and it uses CRC coding to check for errors in the transmitted message.

18 2.3 UWB Ranging protocol Ultra wideband is currently used for short range data transfer but the main usage is to estimate range between two UWB transceivers. This is also DecaWaves modules main usage. The ranging works well as the UWB waveforms travel well through walls indoors and the pulses can be timed very accurately to give a ranging error or ±1dm which is why UWB’s main application is ranging. Ranging can also be done with Bluetooth or WiFi but this gives an error of several meters. To get the range between two transceivers a pulse is sent from the sender (S) to the receiver (R). When the pulse has been sent (S) starts a timer and (R) responds as soon as the pulse has been received. In this response (R) sends information about handling time for the pulse. Then (S) gets the message and stops the timer, the time of flight can then be calculated as total time minus handling time divided by two to account for flight time back and forth. (S) can then send the ranging information to (R) with a regular message. This can be seen in Figure 2.5

Sender Receiver

First pulse first request Timer T starts

Response contains handling time T_h

response

Response received Timer T stops Final time is calculated final message

Final time received

Figure 2.5: Calculating the time of flight between two UWB modules.

19 3 Implementation

3.1 System overview The basic system for sending and receiving signals can be seen in Figure 3.1. The overview describes how a message travels from one sending user to receiving user. The different steps have been sub-divided into android applications and the EVK1000 devel- opment boards. The sender inputs a message that is put as the payload. This message can be either text message or data message. This message is configured to fit the USB payload structure and sent via USB to the EVK1000 sending unit. The USB protocol handles error checking which is done inside the libraries described in section 3.3. Once the message is handled by the EVK1000 the payload is given a IEEE802.15.4-2011 header and sent via UWB to the EVK1000 receiver. The receiver then checks for errors and configure the message to be sent to the receiving application and the header is removed once the UWB message has been received error free. The receiving application receives the message in the same format as the sender configured it and then handles the message as desired.

UWB board Android Application EVK 1000 Sender Sender

Handling of USB S Data message USB message Configuration USB Payload communications Sender

Configuration UWB Error check

UWB Error communications check

Android Application Decode UWB Receiver message

R Data message USB Decode USB Payload communications Receiver Configuration USB

Error UWB board check EVK 1000 Receiver

Figure 3.1: Overview of the communication system.

20 3.2 Hardware 3.2.1 Android devices The Android devices used for the Android application in Figure 3.1 are a Samsung galaxy S5 and an ASUS ZenPad C 7.0 (Z170MG). The specifications can be seen in Table 3.1. Both devices run android and supports USB connections but none of them support UWB communications [8], [9]. To be able to run the application they need to run at least Android 3.0. Samsung Galaxy s5 Asus ZenPad

Device name Samsung Galaxy s51 Asus Zenpad C 7.02 Dimensions 142 x 72.5 x 8.1 mm 189 x 108 x 9.5 mm Mobile Network GSM/HSPA/LTE GSM/HSPA WiFi 802.11 a/b/g/n/ac WiFi 802.11 a/b/g/n Bluetooth 4.0 Bluetooth 4.0 Communications microUSB 3.0 microUSB 2.0 GPS/NFC/IR GPS Processor Quad-core 2.5 GHz Krait 400 Quad-core Cortex-A7 Operating system Android 6.0.1 Android 5.0 UWB support No No

Table 3.1: Specifications for Samsung Galaxy s5 and Asus ZenPad [8], [9].

1Image source: https://bit.ly/2I1W6Wb [10] 2Image source: https://bit.ly/2HYJpvs [11]

21 3.2.2 EVK1000 evaluation kit EVK1000 development board is made and developed by Decawave Ltd. It costs around $500 and should be used to test DW1000 UWB transceiver IC (integrated circuit) chip rather than being a complete product. The board is integrated with an ARM processor, several switches, an LCD screen along with the Decawave DW1000 chip and antenna. The development board comes with a standard open source program called DecaRanging which displays how far apart the two cards are. The board can be seen in Figure 3.2. The ARM processor is responsible for all the calculations while the DW1000 chip takes care of the sending and receiving of UWB signals. SPI is used between the DW1000 and the ARM processor, this is a common protocol that smaller wired modules use to efficiently communicate.

Figure 3.2: Decawaves EVK1000 development board front and back showing LCD display on the front and additional components on the back [12].

Other evaluation kits that could have been used are POZYX [13] or some of the newer models developed by Decawave.

3.2.2.1 Micro controller STM32F105 ARM Cortex M3 The ARM micro processor is the programmable unit on the EVK1000, it has lots of features where some can be seen in Table 3.2. The processor has been developed by STMicroelectronics and is programmed via their programmer/debugger ST-LINK/V2 which connects to the computer via USB and to the processor via JTAG.

22 Processor name STM32F105RCT6 Dimensions 10 x 10 mm Processor core (CPU) ARM 32-bit Cortex M3 CPU Frequency 72 MHz max frequency 64 to 256 Kbytes Flash memory Memories 64 Kbytes general purpose memory I2C Interface x 2 USART interface x 5 Communications SPI interface x3 USB 2.0 x2 10/100 ADC support Yes, 2 x 12-bit ADC 0-3.6V range

Table 3.2: Specifications for ARM processor STM32F105RCT6 [14].

3.2.2.2 DW1000, UWB transceiver The transceiver chip, called DW1000, is an integrated circuit chip compliant to IEEE standard 802.15.4-2011 [7]. The transceiver is developed by Decawave Ltd. and is currently being used mostly for indoor location systems but it’s building up a community to support other applications as well. The DW1000 costs between $5 to $10 (retailer digikey jan 2018). The chip can be seen in Figure 3.3.

Figure 3.3: UWB transceiver chip DW1000 from Decawave.

23 Some of the key features of the DW1000 chip are listed below and all the information about the chip can be found in resource [1].

• 6 RF bands from 3.5GHz to 6.5GHz. • Low Power consumption. • Data rates of 0.110Mb/s, 0.85Mb/s or 6.8Mb/s. • Compliant with FCC UWB standards. • SPI interface. • Supports packet size of up to 1023 bytes (larger than IEEE802.15.4-2011 standard).

For this project a data rate of 6.8 Mb/s was chosen to maximize data transfer speed. The packet size used is lower than 1023 but could be extended to contain much more information. The transceiver uses SPI (serial peripheral interface) to interface with the on board ARM processor and this is being handled inside the drivers provided by Decawave for the device. The chip can be bought separately.

24 3.3 Software and development tools 3.3.1 Android Studio Android Studio is the official IDE for Android OS [15]. It is a tool that offers easy to use interface to quickly get you set up with your application. The programming language is Java or C++ along with .xml files that controls the appearance of graphic objects in the application.

Library: USBSerial USBSerial: USB Serial controller for android v010 is a library used to make the smart phone able to act as a master in USB communication. This is necessary as the smart phone usually acts as a slave when connected to a computer or other device. Master and slave relationships can be found in lots of communication protocols and refer to the master as the one requesting information and the slave as the one giving out information when asked. The library also provides functions to send/receive USB messages. This library follows the MIT license [16], which is an open source license that anyone can use in their projects.

Library: Graph View Android Graph View plotting library 4.2.1 was used to create plots inside the applica- tion. This library contains several functions for plotting and handling data streams. Graphview supports real-time graphing but for faster applications the graphing takes a lot of CPU power. This library follows the apache license [17], meaning that you can use it within your own enclosed projects.

3.3.2 CooCox IDE CooCox IDE [18] is designed for ARM processors, commonly found in newer evaluation boards such as Raspberry pi and in smart phones and tablets. The IDE is open-source and offers a working environment sufficient for programming. It supports both C and C++ programming and has several built-in libraries for developers [18].

25 3.3.3 MATLAB To analyze and create the data used in this project Matlab [19] was used. Matlab provides a great foundation for easy code-writing and it is a powerful tool used to analyze and plot data. In this project the ECG waveforms were created using matlab [20] and then exported to the android application. The ECG waveforms can be modified to display irregular shapes but for this project the standard healthy ECG wave form was used.

26 3.4 Implementation 3.4.1 EVK1000 programming The EVK1000 was programmed to send and receive following IEEE 802.15.4-2011 stan- dard. The protocol for receiving ACK was also programmed. The DW1000 chip driver supports a number of handy functions to setup and use the chip. As the EVK1000 did not support multi channel transmission as first proposed in the project plan the initial idea had to be changed. To clarify this section the multiple data channels which contains the ECG data will be called tracks and the channels in frequency domain will be called channels. Instead of sending over multiple channels in frequency domain the different tracks had to be sent over one channel. This means that the tracks are send in series, which is called TDMA. Sending the tracks over different channels would have been FDMA but as that was not possible TDMA had to be used instead. The EVK1000 supports multiple users where each user can choose one of 6 frequency bands to operate on. On each band the user can choose a preamble code, CDMA, out of 6 different codes. The UWB standard 802.15.4-2011 supports up to 20 codes on each frequency band but the decawave chip supports a maximum of 36 users working in the same proximity without interference. If multiple users should use the same channel and code the ALOHA principle will be be deployed to allow users to send and receive over the same channel.

DW1000 antenna settings DW1000 can be configured to send on one specific channel with other antenna settings. The antenna is then initialised with the dwt configure(settings). The chosen antenna settings can be seen below: 4 , /∗ Channel number. ∗/ DWT PRF 64M, /∗ Pulse repetition frequency. ∗/ DWT PLEN 128, /∗ Preamble length. TX only. ∗/ DWT PAC32, /∗ Preamble acquisition chunk size. RX only. ∗/ 9 , /∗ TX preamble code. TX only. ∗/ 9 , /∗ RX preamble code. RX only. ∗/ DWT BR 6M8, /∗ Data r a t e . ∗/ DWT PHRMODE STD, /∗ PHY header mode. ∗/ (65 + 64 − 32) /∗ SFD timeout ∗(preamble length + 1 + SFD length − PAC s i z e ) . ∗Used in RX only. ∗/

27 The different settings listed were chosen to get as high throughput as possible. The chan- nels available to the DW1000 chip is channel 1, 2, 3, 4, 5, 7 specified in the IEEE802.15.4- 2011 standard. Channel 1, 2, 3, 5 all has a bandwidth of 500MHz while channel 4 and 7 has a bandwidth of 900MHz. Channel 4 was chosen as it gives a larger bandwidth than the other (channel 7 could also have been used). The pulse repetition frequency is how fast the preamble code is sent out and DWT PRF 64M was chosen as it is the fastest possible repetition. The faster you send out the preamble the quicker the message is sent but with a lower range and higher chance of error. For this application the fastest setting was chosen though as the testing area was very limited. The same goes for the preamble length, the shortest one was chosen to make it as quick as possible. The preamble code is the same for sender and receiver, which was chosen as the 9th pre-programmed code in the decawave driver. Dif- ferent codes can be used if you want to make a network that only forwards information where nodes can receive on one channel and send on another. The data rate was chosen to be the maximum, which is 6.8Mb/s although the sent ECG stream is not sent in that rate. This was because of handling time in the receiving android device. The standard PHYsical header was chosen and the SFD timeout, that is how long the receiver expects to wait before the SFD(Start of frame delimiter) is sent.

Default program: Decaranging The code used in this project was built on the code provided by Decawave as the default program, called DecaRanging which supports USB commands to be sent/received from the EVK1000. This program uses a state machine that handles ranging, sending of text messages and handling of ACKs. A lot of time was spent reviewing this before a decision was made to rewrite the program to better suit the application of data transfer. Some new methods were written for the handling of USB messages to support Android devices and the main program was completely rewritten. The code for transmission is explained by the Figure 3.4 and for receiving by Figure 3.5.

Sending and receiving program overview The programming of the development boards were rewritten from scratch to include only data transfer, this was done to understand the software, it was also easier to rewrite than to modify the existing state machine from Decawave’s Decaranging program. The program is fairly straight forward and consists of one program taking care of the trans- mission and another taking care of the receiving of messages. As the EVK1000 did not automatically take care of ACKs the program had to be written to handle that. The transmitter takes a USB message, adds the MAC header from 802.15.4-2011 and then

28 transmits the message. It then starts listening for an ACK from the receiver. It waits 2ms maximum before getting a timeout and retransmitting the message. To ensure that it doesn’t get stuck in endless transmission and overflowing buffers if the receiver misses packages over and over again a limit was set that ensures that the transmitter only sends the message 3 times before dropping it. The receiver is constantly listening for incoming messages and compares them to ensure that the message that is received is of the correct format as specified by the standard. If a message is correctly received it immediately sends out an ACK and handles the message by removing the MAC header and footer and sending the message via USB to the phone instead.

USB message

Format for IEEE 802.15.4

Transmit message

Wait for ACK

Yes No

Received No No Re-sent 3 Timeout? ACK? times?

Yes Yes Message Message sent scrapped

Figure 3.4: Overview of EVK1000 transmitter program.

29 Incoming Message

Correct Message format? scrapped No

Yes

Send ACK

Remove IEEE 802.15.4 header

Send USB Message message received

Figure 3.5: Overview EVK1000 receiver program.

Sending and receiving protocols The protocol for sending and receiving messages follows the IEEE 802.15.4-2011 standard but the EVK1000 can use a non-standard format that extends the payload to 1023 bytes instead of maximum payload size of 122 bytes (standard). For this project the standard packet size was chosen as the system might be used later to talk to other devices

IEEE 802.15.4-2011 Message frame In this project the messages are composed like the standard IEEE 802.15.4-2011 MAC frame. It is possible to extend the frame length from 127 bytes to 1023 bytes but this does not comply with the IEEE standard for UWB message reception. Thus the standard frame was chosen for this project.

30 MAC header The fields used in the header from the standard were frame control, sequence number, PAN ID (2 bytes), destination address (2 bytes), and source address (2 bytes). The MAC payload depends but it can be up to 108 bytes followed by the footer, which is two bytes long consisting of the CRC check. This can be seen in Table 3.3

Message format Mac Header (MHR) MAC MAC Payload footer (MFR) Frame Sequence PAN ID Dest. Source Frame FCS/ Control Number Address Address payload CRC 0/1B 2B 3/4B 5/6B 7/8B 9-124B 125/126B

Table 3.3: The general format for UWB MAC messages with header, payload and footer.

MAC Payload In this project the message is sent as a string of values, this is done to be able to use different messages denoted by the payload header ’M’ for message, ’D’ for graph message and ’A’ for address which is currently not used but can be used for future reference, support for ranging message could also have been implemented but was deemed unnecessary for this project. This way of sending is inefficient as every digit of the data we want to send takes up one byte, meaning that for instance 1.250 is sent as 4 bytes or 32 bits which is many more bits than are necessary to represent the number 1.250. This is done to ensure simplicity in the data transmission and as the payload messages consists of both characters and values this method was chosen to save project time although it is inferior to sending only the data values. This also enables us to send chat messages.

Serial communication, USB Serial communication means that data bits are sent in a sequence. It is easy for the receiver to interpret the data, as long as both sender and receiver use the same baud rate. Baud rate is the unit used to measure how many times a signal changes per second. The serial communication between the EVK1000 and the attached Android device follows the USB 2.0 standard with a maximum bit rate of 480 Mb/s.

31 3.4.2 Android Application An android application was built for this project based on another application [21] pre- viously done as another master thesis project but completely reworked over the course of this project. The application is designed and used as both a debugging tool for fu- ture developers and also to display and send the ECG signals through the EVK1000 development boards.

Application: ECGgraph, ECG graphing tool The application built to interface with the EVK1000 has one main activity which is divided into three subclasses. The main activity handles which of the subclasses to display on screen. An overview describing the system can be seen in Figure 3.6.

Main activity

Navigation drawer USB TX / RX Global variables

Communications Settings menu menu Graph menu USB Setup Formating message Channel rate Graphing windows Sending message Sending rate Sending ECG data Displaying message

Figure 3.6: Overview of Android application.

The subclasses are extensions of the class fragment which is a kind of sub-activity within the main activity. The desired fragment that the user wants to display can be obtained via a navigation bar that opens from the left. The three fragments are called Settings, Graph and Communication with Settings being opened first.

32 Main Activity The main activity handles all the communication between the fragments and the frag- ments call for methods and global variables (such as the number of channels, sending rate) from the main activity. The main purpose of this class other than to distribute the fragments is to connect the USB. It has methods for USB setup and handling of USB messages. The graphic user interface (GUI) can be seen in Figure ?? and an enhanced version showing the different elements inside the GUI can be seen in Figure ??. Handling of incoming and outgoing USB messages are being handled by the main activity, this is done as sending information between fragments can be hazardous and information might get lost doing so. It’s easier to handle it from one activity. The messages, which is the payload in the whole sent frame (PHY + MAC) are encoded with a starting character ’M’ for regular text messages and ’D’ for graphic messages. The payload messages con- taining the data we want to send has a structure that can be seen in Table 3.4. The handling of the messages received through USB is the biggest bottleneck of the system as graphing takes a lot of time.

Header payload M TEXT MESSAGE D data1 data2 ... data12 Table 3.4: Structure of payload messages

Settings The settings GUI consists of three settings where the most important one is called ”CONNECT USB”. This button calls a function to set up the USB connection by broadcasting itself on the USB line every second. While it’s broadcasting the button turns yellow, indicating that the setup is not yet complete. The broadcasting can be turned off and the button turns gray again to indicate that the device is no longer broadcasting. Once the device has a connection with the other device the button turns green. Before the application can be properly used the setup must be complete. In this menu it’s also possible to enter number of channels to send and the rate which to send the messages.

33 Graph The graph GUI is used to display incoming signals. The signals are displayed on twelve different channel windows. Every window is called a graphView which has a series object attached to them. It’s possible to attached several series to the same window but for this project one per window was chosen. They are continuously updated via functions in the GraphView Library. The graphs can be tailored with maximum and minimum X and Y axis as well as the background color and line color and other handy settings. A test button was also incorporated to test the function of the graphs (not visible in latest version).

Communications The communications menu main purpose is to display and send messages in a text format. It has a log window to display incoming text messages and text input which can be used to send individual text messages. They can be sent as either GRAPH message or MESSAGE. The difference being the short header character added to the message for the receiver to know if the message should be graphed out in the graph menu or displayed in text format. There are three toggle buttons called SEND COS(), SINGLE CHANNEL and MULTI CHANNEL which sends out test signals, the first one being a cos(t) signal. Single channel sends one one ECG signal to the receiver and multi channel sends as many channels of data as the user has specified in the Settings menu. They send the signals with the rate also specified in the Settings menu.

34 Figure 3.7: Android application GUI with a) MainActivity, b) Communications menu, c) Graph Menu, d) Settings Menu.

35 4 Results and discussion

4.1 Prototype The prototype built in this project is designed to send and receive messages as well as graphing out ECG data messages. The full prototype consists of two Android phones and two EVK1000 development boards connected with two USB cables. The prototype can be seen in Figure 4.1.

Figure 4.1: The finished prototype consisting of two smart phones and two UWB trans- mission boards. Sender on the left and receiver on the right.

4.2 Performance The transmission works well but the handling of data in the Android device was not as good as I would have hoped. It can handle the multichannel transmission when getting a message every 5ms without losing any data but the display of data in the Android device is very slow.

36 4.2.1 Data rate Data rate (or data throughput) is the amount of data that can be continuously transferred between two devices without taking into account the time it takes when starting and ending a transmission. Each message has a payload of 48 bytes (4 bytes/channel over 12 channels) although the number of bytes with headers is larger than that. We send with a rate of 200 messages/s. Every 5ms as it is the maximum that the graphing application can handle. This gives 9.6kB/s [Bytes/second] (48B*200) or 76.8kb/s [Bits/second] (48B*8*200). If we send just one data channel we get 4 Bytes/message and this can be handled even at the maximum sending rate. The theoretical maximum is 6.8 Mb/s if we use the non-standard format for sending messages without the MAC-header where each message can be 1023 Bytes long and we don’t take the processing of messages into account. As we use the standard UWB frame of 127 Bytes instead of 1023 we get a theoretical maximum throughput of 0.85 Mb/s. This is the limit for the EVK1000 cards. The USB 2.0 link protocol used between phones and EVK1000 is 480Mb/s so the bottleneck of the system is firstly the processing of messages (76.8kb/s), then the sending via UWB (0.85 Mb/s) and lastly the sending of USB messages (480Mb/s). This can be seen in Figure 4.2.

Android USB UWB USB Android Application 0.85Mb/s Application 75kb/s 480Mb/s (6.8Mb/s) 480Mb/s 75kb/s

Figure 4.2: Overview of bottlenecks in system.

4.2.2 Latency Latency is defined as the time it takes for one package to travel between devices. Devices that has a low latency are very good for sending data in irregular intervals. A device that has high latency does not necessarily have bad throughput as latency is the time it takes to start the transmission, a delay in time. For this project the latency was very low. The transmission of a single package is sent without noticeable delay but this varies with distance as with a larger distance the packages has to be retransmitted

37 multiple times. To avoid too large delay from the EVK1000 the maximum amount of retransmissions have been limited to three. The EVK1000 will wait 2 µs between each retransmission so the maximum delay from the EVK1000 is 6 µs. The handling time for sending and receiving a package (containing the data of all channels) in the Android devices is approximately 2 ms. The delay from the EVK1000 can thus be neglected as the handling time is much larger.

4.2.3 Energy consumption I could not find any data of the energy consumption of the EVK1000 board but it requires at least 250mA via 5V USB to function properly. The EVK1000 has to power LEDs, the microprocessor and the LCD screen which consumes extra power. The DW1000 UWB transceiver chip has a low power consumption and can enter sleep or deep sleep mode to conserve lots of energy during downtime. The currents shown in Table 4.1 gives the average current for the different operating states [1].

State TX RX IDLE Sleep Deep Sleep Current 62 mA 125 mA 18 mA 1 µA 50 nA Table 4.1: Energy consumption for DW1000 chip for different operating modes.

4.3 Android application The android application has a couple of problems. The main one being that while displaying the graphs it is very slow and CPU heavy. To work around this it would be possible to try out other libraries or write your own to display the graphs.

4.4 Problems and solutions Many hardware problems were encountered during the project, which slowed down the progress of building a control system. Some of these problems were

• EVK1000 not being able to send/receive as expected.

The initial idea behind the project was to send data over several frequencies to maximize data throughput for the available spectrum (3-7 GHz [1]). However, EVK1000 limits the user to only send on one channel at a time, meaning that this cannot be parallelized by

38 using all channels simultaneously. Perhaps this will be available in future UWB chips. The idea was dropped and instead one channel is used. • EVK1000 not having an ADC input soldered. One idea was to simulate analog ECG signals as input for the EVK1000. This proved to be difficult as the EVK1000 does not have a soldered pin to the built in analog-digital converter on the microprocessor. Soldering a pin onto the EVK1000 could have solved this problem but that was left as future work. Instead ECG signals were simulated in one smart phone and sent to the other.

4.5 Comparison of wide and narrow band communication As of today (2018) the UWB protocol hasn’t been as developed and researched as narrow band communication (WiFi/Blutooth). In theory the use of UWB should be more energy efficient than both WiFi and bluetooth as sending information in pulses requires less energy than continuous waveforms. One article from 2016 mentions the use of UWB sending over three bands reaching data rates of 1 GB/s [22] while other applications uses data rates of 250 MB/s. The three bands take up a bandwidth of 1500 MHz. The module used in this project has a fairly low data rate but the DW1000 is mainly used for ranging application and not high data rate transmission. When talking about Bluetooth communication there are three main protocols that are currently in use. These are classic (v2.x) high speed (3.0) and low-energy (v5.0). The classic BT is getting outdated and is replaced with BT 5.0. The high speed version of BT can support high data rates but it uses a network that uses the same structure as WiFi (802.11) where the BT part is used as a gateway to connect to WiFi. The BT 5.0 gives a very large range but it can’t apply such high data rate. WiFi has several versions of the classic 802.11 protocol. The most common right now is 802.11g or 802.11n which has speeds supporting up to 450 Mb/s or 54 Mb/s. There are also faster versions called 802.11ac wave2 which supports up to 1.73 Gb/s. An article from 2014 describes and compares the specifications for some of the wireless protocols [23]. We can use this comparison between the different technologies to compare energy efficiency. The data seen in Table 4.2 describes the different technologies presented in the study with updated WiFi and UWB specifications from 2018 [22], [24]. When talking about power in radio technology we often talk about Watt (mW/µW or nW) or decibel (dB/dBm). This is because the power of a signal is easiest described like this. The intensity of the signal will vary depending on range and medium it travels through but the sending power is often in the range of nW or µW. We express the power in terms if dBm as the dB scale is logarithmic and to avoid having too large or too

39 small numbers we use dB instead of W. To calculate this we use the conversion given by Equation 3 and Equation 4. Where P is given in mW and dBm is milli decibel.

dBm = 10 ∗ log10(P/1mW ) (3)

P = 1mW ∗ 10(dBm/10) (4) The calculated values of transmission (TX) power is presented in three comparative units, W, dBm and dBm/MHz. UWB is most often presented in dBm/MHz and to clarify the difference in TX power the three conversions have been made. The conversion for UWB from dBm/Mhz to W and dBm is done for the three banded 1Gb/s previously mentioned and represents the maximum power allowed for such a device. We can see from the table that UWB is much more efficient although WiFi has a higher throughput and the different technologies have different usage areas. Blue- tooth is more suited for small appliances that doesn’t need too high data rate such as battery-powered headphones, speakers and printers while WiFi is more directed to home networks. UWB can be a contender on both of these areas as it has a high throughput and low energy cost.

Name WiFi UWB Bluetooth Protocol 802.11a/b/g/n/ac 802.15.4-2011 802.15.1 v3, v4, v5 Max data rate 1.73/0.45 Gb/s 1Gb/s 24/1/2Mb/s Frequency 2.4 GHz, 5.1 GHz 3.1-10.6 GHz 2.4 Ghz Channel bandwidth 22 MHz 0.5-7.5 GHz 1 MHz TX power dBm 15-20 dBm -9.5dBm(1.5GHz) 0 - 10 dBm TX power dBm/MHz 6.58 dBm/Mhz -41.3 dBm/MHz 10 dBm/MHz TX power W 30-100 mW 0.11mW(1.5GHz) 1-10 mW Range 0-100 m 0-100 m 0-100 m/0-400m

Table 4.2: Comparison of the three main sending protocols

40 5 Conclusion and future work

We can conclude from this project that it is possible to use two EVK1000 as a way of transmitting ECG signals and that the bottleneck of the system is the graphical handling of messages. UWB is an excellent method of sending information over short distances even though it’s not as developed as Bluetooth or Wifi. I believe that UWB will play a much larger role in the future for short range data heavy transmission like real time wireless streaming. Improvements of the system would be to firstly take care of the problem with the graphing, making it faster. One could also program the EVK1000 to send messages in a faster pace and let the ACK waiting time be longer, the problem with that is that the device cannot send and wait for receiving messages at the same time so this has to be timed in a better way, perhaps by sending 255 messages, then wait for ACKs for all of them and then see which messages needs to be retransmitted. This would lower the overhead of each message as the sender doesn’t have to switch over to listening mode after each message sent and the transmitter doesn’t have to switch to sending mode for each message. For future work a proper ECG instead of the simulated data could be attached to the prototype. This would be done by either attaching, to the system, a full ECG system (nodes, amplifier and analog-to-digital converter) that outputs an digital signal signal or just the nodes and amplifier. The problem here is that the EVK1000 does not have soldered pins available for analog to digital conversion. The ARM processor supports this but the development board does not. The specifications for the project was to design a system to transmit 12 channels of data. The original idea had to be scrapped due to hardware limitations but in the end a working prototype that sends 12 channels of data from one Android device to another was successfully constructed. Over all many new things have been learned during this project, the most important being how important it is to plan out your work and to do your research properly. The hardware limitations were discovered after the start of the project and I had to make do with the hardware available. I also got lots of experience with Android application development and ARM programming during the project. The most time consuming part of this project was to research the program on the EVK1000, called DecaRanging and to deduce how that worked. In the end that was scrapped and I deployed my own version of the program with some changed functions and a new main method for the cards that only handled data transmission and not ranging. Writing the android application took a lot of time as I had no prior experience

41 in application coding. If we were to remake this project I would have researched more into similar project before diving head first into the project. Over all the project was a success and the project fulfilled the description and question set up at the start of the project.

42 References

[1] Decawave Ltd., “DW1000 Data sheet version 2.13,” 2017.

[2] Federal Communications Commission, “Revision of part 15 of the commission’s rules regarding UWB Transmission systems,” Apr. 2002.

[3] K. Siwiak and D. McKeown, “Ultra-wideband radio technology,” John Wiley and Sons, Ltd, 2004.

[4] Decawave ltd., “UWB Regulations, A summary of worldwide telecommunications regulations governing the use of ultra wideband,” Apr. 2015.

[5] A. Goldsmith, “Wireless communications,” Cambridge university, pp. 461–464, 2013. [Online]. Available: http://dx.doi.org/10.1109/35.267438

[6] International telecommunication union, “Data networks and open system commu- nications ITU-T recommendation X.200,” 1994.

[7] IEEE Computer Society, “IEEE Standard for Local and metropolitan area networks- Part 15.4: Low-Rate Wireless Personal Area Networks(LR-WPANs),” IEEE Std 802.15.4-2011, 2011.

[8] GSM arena, “GSMarena Samsung Galaxy S5,” Mar. 2018. [Online]. Available: https://www.gsmarena.com/samsung galaxy s5-6033.php

[9] ——, “GSMarena Asus Zenpad C7.0 Z170MG,” Mar. 2018. [Online]. Available: https://www.gsmarena.com/asus zenpad c 7 0 z170mg-7364.php

[10] Samsung, “Galaxy s5 16gb,” May 2017. [On- line]. Available: https://www.samsung.com/us/mobile/phones/galaxy-s/ samsung-galaxy-s5-verizon-shimmery-white-sm-g900vzwavzw/

[11] Asus, “Asus zenpad c 7.0,” May 2017. [Online]. Available: https://dlcdnimgs.asus. com/websites/global/products/j6NVqIO5IONwrloP/v3/design/imgs/ultimate.png

[12] Decawave Ltd., “Decawave EVK1000 product brief,” 2017.

[13] Pozyx labs, “Pozyx, accurate positioning,” Jan. 2018. [Online]. Available: https://www.pozyx.io/

[14] STMicroelectronics Corp., “STM32F105xx, STMF107xx Data sheet,” 2009.

43 [15] Google Inc., “Android studio 3.0.1,” Jan. 2018. [Online]. Available: https: //developer.android.com/studio/index.html

[16] Massachusetts Institute of Technology, “MIT License,” Jan. 2018. [Online]. Available: https://opensource.org/licenses/MIT

[17] Apache Software Foundation, “Apache License, Version 2.0,” Jan. 2018. [Online]. Available: https://www.apache.org/licenses/LICENSE-2.0

[18] CoIDE, “CooCox COIDE 2.0,” Jan. 2018. [Online]. Available: www.coocox.org

[19] Mathworks Inc., “Matlab 2017,” Jan. 2018. [Online]. Available: https: //se.mathworks.com/products/matlab.html

[20] K. Raviprakash, “ECG Simulation using MATLAB v1.0,” Jan. 2018. [Online]. Available: https://se.mathworks.com/matlabcentral/fileexchange/ 10858-ecg-simulation-using-matlab

[21] A. G¨awerth, “Embedded wireless communication: Connectivity of a smartphone with bluetoothle and uwb devices,” Uppsala University, 2017.

[22] N.-S. Kim and J. M. Rabaey, “A high data-rate energy-efficient triple-channel uwb- based cognitive radio,” IEEE Journal of Solid-State Circuits, vol. 51, no. 4, pp. 809–820, 2016.

[23] K. Pothuganti and A. Chitneni, “A comparative study of wireless protocols: Blue- tooth, uwb, zigbee, and wi-fi,” Advance in Electronic and Electric Engineering, vol. 4, no. 6, pp. 655–662, 2014.

[24] , “St-link v2 programmer,” Dec. 2017. [Online]. Avail- able: https://www.intel.com/content/www/us/en/support/articles/000005725/ network-and-i-o/wireless-networking.html

44