intelligent device for sensing physical activity · intelligent device for sensing physical...

60
Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção do Grau de Mestre em Engenharia Electrotécnica e computadores Júri Presidente: Prof. José António Beltran Gerald Orientador: Prof. Francisco André Corrêa Alegria Vogal: Prof. Leonel Augusto Pires Seabra de Sousa Outubro 2007

Upload: others

Post on 20-Mar-2020

14 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Intelligent Device for Sensing Physical Activity

Luís Filipe Corrêa Martins Magalhães de Aguiar

Dissertação para obtenção do Grau de Mestre em

Engenharia Electrotécnica e computadores

Júri

Presidente: Prof. José António Beltran Gerald Orientador: Prof. Francisco André Corrêa Alegria

Vogal: Prof. Leonel Augusto Pires Seabra de Sousa

Outubro 2007

Page 2: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

i

Acknowledgment

I would like to sincerely thank my supervisor, Dr. Günter Edlinger, for providing

me the great opportunity to develop my project, in Austria. I appreciate his form of

guidance and the freedom given to me during the whole project. I was always

encouraged to work on my own, which I truly believe has allowed me to develop the

necessary skills to undertake future projects. Nevertheless I am quite aware of my own

limitations and the need to ask for help/guidance whenever necessary.

I am very grateful to Eng. Franz Laundl for his constant availability and support,

which demonstrates a real interest in fostering the success of my project. His ability to

encourage and to support me was extremely motivating and turned out to be a key

element for the success of this project.

I thank Dr. Francisco Alegria, for embracing the project, his suggestions and

assistance towards the completion of the present thesis. Although his fill and tight

schedule, he promptly offered assistance proving a real dedication.

I am also thankful for the sympathy and support given by the g.tec team. During

all the time at the company they have always made me feel extremely esteemed and

integrated in the team.

To my family, especially my mother, that always fostered my education and the

idea of studying abroad. Their financial and emotional support was very important to

make this ERASMUS adventure come true.

Page 3: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

ii

Resumo

A saúde e a actividade física estão fortemente relacionadas e o interesse por

ambas têm vindo a crescer consideravelmente. Consequentemente, a forma de medir a

actividade física revela-se importante. Este projecto visa a construção de um protótipo

de um monitor de actividade física com capacidade de transmissão possibilitando um

estudo mais detalhado.

O protótipo pode ser personalizado com o valor de actividade física diária

recomendada e a hora. O registo da actividade pode ser transmitida para um telemóvel,

via Bluetooth. A memória permite armazenar até 18 horas, com frequência de

amostragem de 1 Hz.

Palavras-chave: Saúde, actividade física, monitor de actividade, Bluetooth

Abstract

Health and physical activity are intimately connected and the concern for health

keeps on increasing. These make the measurement of physical activity an important

issue. The purpose of this project was to develop a prototype of a physical activity

monitor. The device can transmit the acquired data making a detailed study possible.

The prototype based on a tri-axial accelerometer was successfully produced. It

can be personalized by setting up the time and the recommended daily activity. The

registered data can be uploaded via Bluetooth to mobile phones. The memory can store

more than 18 hours with a sample rate of 1 Hz.

Key words: health, physical activity, activity monitor, Bluetooth

Page 4: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

iii

Table of Contents

Novembro 2007 ............................................................................................................................................i

Acknowledgment .........................................................................................................................................i

Resumo ........................................................................................................................................................ii

Abstract .......................................................................................................................................................ii

Table of Contents.......................................................................................................................................iii

List of Tables..............................................................................................................................................iv

List of Figures ............................................................................................................................................iv

Summary of acronyms ...............................................................................................................................v

Introduction ................................................................................................................................................1

Definition of physical activity ..................................................................................................................1

Measurement of physical activity ............................................................................................................3 Subjective Measures of Physical Activity...........................................................................................3 Objective Measures of Physical Activity............................................................................................4

Double labeled water......................................................................................................................4 Indirect calorimetry........................................................................................................................5 Direct calorimetry ..........................................................................................................................5 Motion sensors ...............................................................................................................................5

Objective .....................................................................................................................................................8

Methods .......................................................................................................................................................9

Signal characterization............................................................................................................................9

Proposed algorithm to calculate physical activity.................................................................................13

The analog block ...................................................................................................................................14 Idea ...................................................................................................................................................14 Simulation.........................................................................................................................................14 Implementation .................................................................................................................................16

The digital block ....................................................................................................................................18 Idea ...................................................................................................................................................18 Memory.............................................................................................................................................19 Telecommunication module..............................................................................................................19

USB..............................................................................................................................................19 RFID ............................................................................................................................................20 GPRS............................................................................................................................................20 Bluetooth......................................................................................................................................21 ZigBee..........................................................................................................................................22

Connecting the blocks.......................................................................................................................23 Power Supply....................................................................................................................................25 Microprocessor .................................................................................................................................26

Mobile Phone.........................................................................................................................................29 Idea ...................................................................................................................................................29 Selection of models and development environment .........................................................................29 The modules......................................................................................................................................30

Page 5: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

iv

Communication............................................................................................................................30 record_to_file ...............................................................................................................................32 take_care_request.........................................................................................................................33 Config ..........................................................................................................................................34

The main program.............................................................................................................................34

Server.....................................................................................................................................................35 Idea ...................................................................................................................................................35 Modules ............................................................................................................................................35

users .............................................................................................................................................36 Main script ........................................................................................................................................36

Client program ......................................................................................................................................38

Results .......................................................................................................................................................39

Discussion..................................................................................................................................................41

Literature ..................................................................................................................................................43

APPENDIX A ...........................................................................................................................................45

APPENDIX B............................................................................................................................................47

APPENDIX C ...........................................................................................................................................48

APPENDIX D ...........................................................................................................................................49

APPENDIX E............................................................................................................................................50

APPENDIX F............................................................................................................................................51

List of Tables

Table 1 Comparation of transmission technologies, adapted from (NEC 2006) and from (Wikipedia 2007) ........................................................................................................ 23 Table 2 Structure of messages..................................................................................... 31 Table 3 Record file's structure..................................................................................... 33 Table 4 Physical activity index in different activities................................................... 39 Table 5 Monitor components ...................................................................................... 40

List of Figures

Figure - 1 Rotating the sensor in three axes ................................................................. 10 Figure - 2 Sensor’s z component output while jumping ............................................... 11

Page 6: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

v

Figure - 3 FFT of the z component while jumping.......................................................12 Figure - 4 FFT of z component while walking............................................................. 12 Figure - 5 FFT of sensor while running ....................................................................... 12 Figure - 6 Simulation of the analog circuit with ADC..................................................15 Figure - 7 Intermediate calculation, after the sum block, while jumping ...................... 16 Figure - 8 Intermediate calculation, after the Integration block while jumping............. 16 Figure - 9 Intermediate calculation, after the ADC block, while jumping .................... 16 Figure - 10 1st order high pass band filter and first order low pass band filter .............. 16 Figure - 11 2nd order low pass band filter .................................................................... 17 Figure - 12 Full wave rectifier circuit .......................................................................... 17 Figure - 13 Schematic representation of the digital block ............................................ 18 Figure - 14 Logic level relation ................................................................................... 24 Figure - 15 Microprocessor program’s modules ..........................................................27 Figure - 16 Main flowchart of the microprocessor....................................................... 28 Figure - 17 Communication hierarchy......................................................................... 31 Figure - 18 Initial screen ............................................................................................. 34 Figure - 19 Main Menu ............................................................................................... 34 Figure - 20 Selecting file............................................................................................. 34 Figure - 21 Plot of record ............................................................................................ 35 Figure - 22 Server GUI ............................................................................................... 37 Figure - 23 Userman GUI............................................................................................ 37 Figure - 24 Client program’s window.......................................................................... 38 Figure - 25 Plot of record ............................................................................................ 38 Figure - 26 Monitor’s record with different activities for subject B (walking, running, jumping) ..................................................................................................................... 39 Figure - 27 Prototype of monitor plus repairs .............................................................. 40

Summary of acronyms

A Ampere (SI) is the unit of electric current, or amount of electric

charge per second

ADC Analog to Digital Converter

AT ATtention command set, a subset of the Hayes command set

Bit Bit - The basic unit of memory, "1" or "0"

Byte Group of eight bits

bps Bits Per Second

CRC Cyclic Redundancy Check

DAC Digital to Analog Converter

EPROM Erasable Programmable Read-Only Memory,

EEPROM Electrically Erasable Programmable Read-Only

Page 7: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

vi

g Relative acceleration 9,8 m.s-2

GPRS General Packet Radio Service

GND electrical GrouND, circuit reference (Zero) voltage level

GSM global system for mobile communications (Groupe Spécial

Mobile)

Hz Hertz (SI) is the unit of frequency 2H2

18O Hydrogen and oxygen isotopes used with doubly labeled water

technique

ID IDentification number

IDE Integrated development environment

IP Internet Protocol

I/O Input/Output

kg kilograms (SI) of mass

LAN Local Area Network

LCD Liquid Crystals Display

LDO Low Drop Out, linear voltage regulator

m Meter (SI), unit of length

MB Mega Bytes 1 MB = 1024*1024*8 bits

OS Operative System

PC Personal Computer

PROM Programmable Read-Only Memory

RAM Random Access Memory

RFID Radio-Frequency Identification

ROM Read-Only Memory

RTC Real Time Clock

SI International sistem of units (Le Système international d'unités)

SIM Security Identity Module, used in cell phones

SMS Short Message Service, a GSM service

SPI Serial Peripheral Interface

TCP Transmission Control Protocol

USART Universal Synchronous Asynchronous Receiver Transmitter

UMTS Universal Mobile Telecommunications System

V Volt (SI) is derived unit of electric potential difference

Page 8: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

vii

VILmax Voltage input low maximum – maximum voltage interpreted as

‘0’

VOHmax Voltage output high maximum – Maximum voltage set as ‘1’

VOHmin Voltage output high minimum – minimum voltage set as ‘1’

VOLmax Voltage output low maximum – maximum voltage set as ‘0’

VCC Voltage at the Common Collector

VEE Voltage emitter, refers to the "emitter" voltage as supplied by the

power supply pin

W Watt (SI), is the unit of power

µP Microprocessor

Page 9: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Introduction

1

Introduction

Health concern has become one of the most important topics nowadays. A

sedentary life style is commonly associated with obesity, which can originate

cardiovascular problems, hypertension, diabetes and osteoporosis even in young people

(Martin and Houston 1994). During childhood, it can create orthopedic problems and

psychological ill health manifested by eating disorders, poor social relationships and

educational disadvantages.

According to the European Association for the Study of Obesity, in many

countries inside the European Union half of the adult population is overweight and up to

one third of the adults are clinically obese (BYRNE 2003). The obesity epidemic carries

significant costs for tax payers: it has been estimated to have an economic impact from

€118 up to €236 billion (Rettman 2006).

Physical activity has a pervasive effect on health among adults and children

(DuRant, Baranowski et al. 1993) Regular physical activity is effective in preventing

several chronic diseases and premature death.

A positive correlation between the volume of physical activity and health status

was shown by investigators. The relation is even more notable when non fit people

initiate an active physical life (Warburton, Nicol et al. 2006). The benefits are also

extended to psychological health (Carneiro, Lopes et al. 2002).

Definition of physical activity

Physical activity is a very complex human behavior, very difficult to measure

under free-living conditions. The most commonly accepted definition of physical

activity is “the voluntary movement produced by contraction of skeletal muscles

resulting in energy expense” (Caspersen, Powell et al. 1985). The amount of muscle

mass to perform a certain movement influences the quantity of energy necessary to

realize it. The energy source for muscular contraction is given by Adenosine

Triphosphate (ATP). When the energy is used, ATP is dephosphorylized to ADP. In

order to be able to transport energy again, ADP must be phosphorylized back to ATP

through several chemical processes (Tavares 2003).

Page 10: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Introduction

2

The percentage of energy consumed is inferior to 25%. The rest is converted in

to heat. The reason for such a low efficiency is that converting ADP to ATP has an

efficiency of 50%, approximately. From this less than 45% of the ATP energy can be

converted to physical work by the muscle.

The physical activity is characterized by the duration of the session, its

frequency and intensity (rate of energy expenditure), surrounding environment and

social conditions (Montoye 2000). It is also influenced by the type and purpose of

physical activity (recreational, obligatory, rhythm (continuous or intermittent), with or

without weight, aerobic or anaerobic). All these elements contribute to the calculation of

the dose or volume of physical activity, which is one of the potential mediators of the

health benefits of physical activity (Kesaniemi, Danforth et al. 2001).

A precise measure of both session duration and intensity of the physical activity

is imperative to clarify feasible health, resulting from a dose of physical activity.

The amount and the kind of physical activity have immediate repercussions on

physical fitness. Physical fitness refers to a physiologic state of well-being, compulsory

to daily-life’s routine or sport performance. Physical fitness involves aerobic fitness,

muscle strength, endurance, body composition, flexibility, agility, balance,

coordination, reaction and speed (1999). Non fit people have a 44% higher risk of

mortality (Blair, Kohl et al. 1995), risk of obesity and shorter life expectancy (Epstein,

Wu et al. 2000) rate when compared to fit people. The connection between physical

activity and health has already been mentioned. To further improve our knowledge on

this relationship it is imperative to have adequate and precise measures both for physical

activity and health condition. Only with reliable measurement techniques can the

researchers develop and improve valid theoretical models for physical activity, as in any

other field of investigation. At the present, there is no universally accepted gold

standard for measuring the physical activity (BioTrainerUSA 2007). Such absence

makes direct comparisons very difficult, if not impossible, among researchers that used

different physical activity measurement devices. The problem is particularly visible

when trying to compare studies of populations on an international basis.

Page 11: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Introduction

3

Measurement of physical activity

Several techniques have been proposed for measuring the physical activity level,

each of them having their advantages and disadvantages. An appropriate selection must

be done to ensure a suitable data collection for a particular research (Tudor-Locke and

Myers 2001). The measurement techniques can be classified in two distinct categories:

subjective and objective. The first category depends on the ability of the participant or

observer to register the physical activity. It includes methods as interviews,

questionnaires, surveys, recall diaries and direct observation. The second one falls upon

the observer’s ability to perceive and measure the behavioral aspects of physical activity

(Raustorp 2005).

Objective techniques relay on electronic devices able to provide information

without the participant or researcher bias. The use of such devices has led to a big

increasing development of new measuring tools and to an improvement of the existing

ones. Specific objective measurement tools that have been used in physical activity

research include double labeled water, indirect calorimetry, heart rate monitor,

pedometer and motion sensors.

Subjective Measures of Physical Activity

Epidemiologic studies on physical activity preferably relied on self-report

methods, interview-administered questionnaires and recall diaries. Their popularity is

easily explained due to their advantages. Some of the greatest advantages are their low

cost application, speed of implementation and low burden for the participant. These,

alone, make it possible to collect data, from a large sample size, efficiently and

inexpensively (Kohl, Fulton et al. 2000). Self-report techniques are able to provide

qualitative and quantitative information. However their reliability can be questioned

because they are based on the skills of the participant to register physical activity, which

can be corrupted due to subject bias. Also can special groups, such as children, have

difficulty in recalling activities accurately (Sallis and Saelens 2000; Raustorp 2005).

Direct observation provides accurate information of what is happening during

the physical activity, thus generating both qualitative and quantitative information.

Page 12: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Introduction

4

Among the disadvantages are time and expenses necessary for collecting data. The

observer must dedicate some time, before data acquisition, to self training in order to

increase data reliability. Furthermore the presence of the observer can influence the

regular physical activity patterns of the subject (Welk 2002).

Objective Measures of Physical Activity

Double labeled water

The double labeled water method measures the total energy expenditure and can

be used under laboratory and free-living conditions. It is widely used in hospitalized

patients. The doubly labeled water method, being noninvasive and nonrestrictive, is

ideal for the measurement of total daily energy expenditure in a free-living state

(Schoeller 1988). After a dose of heavy water (2H218O) being orally administrated, the

labeled hydrogen (2H2) will be eliminated as water (2H2O), corresponding to the water

output and the oxygen isotope will be connected to H2 and (H218O) exhaled as carbon

dioxide (C18O2). By measuring the difference between the elimination rates of labeled

oxygen and hydrogen, the carbon dioxide production rate can be calculated. The carbon

dioxide production rate is converted into energy expenditure by knowing the respiratory

quotient of the food ingested during the observation period (Metabolic Solutions 2007).

The double labeled water method can be used up to three weeks. However the technique

can not be applied to patients with restrict diets, high alcohol consumption or metabolic

disorders. It does only provide information regarding the total energy expense as a

result. Specific time-related information is not achievable. Probably the most important

disadvantage is the absence of distinct information regarding duration, frequency and

intensity of specific physical activity (Lamonte and Ainsworth 2001).

Page 13: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Introduction

5

Indirect calorimetry

Indirect calorimetry analyzes inhale and exhale gases concentration to measure

energy expenditure. The consumption of oxygen rate and the production of carbon

dioxide rate permit an energetic expenditure of short periods of time. The subject under

observation must use a facial mask or mouthpiece during all data acquisition. It is called

“indirect calorimetry” because the caloric burn rate is calculated from the measurement

of oxygen uptake.

Direct calorimetry Direct calorimetry is used for long-range measurements: the subject under observation

is placed inside a thermal isolated metabolic chamber, where all the produced gases’

concentrations and thermal heat are carefully measured and registered. This method was

named “direct calorimetry” after the fact of registering the temperature.

Both direct and indirect calorimetry techniques have a limited use because of the

required hardware being invasive and expensive.

Motion sensors

The motion sensors already introduced onto the market are the pedometer, the

accelerometers and the heart rate monitors. They register the raw data of the movement,

or heart beat, (the heart rate monitor) that can be converted into energy expenditure. The

fact of being based on different principles (physiological, biomechanical and

biochemical) invalidate the direct comparison of the results (Welk 2002). However their

assumed/ recognized advantages lead to an increasing use in physical activity research

and in personal use.

Page 14: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Introduction

6

Heart rate monitors

Heart rate monitors have been used either in the open field or in the laboratory

providing good valid data (Welk 2002).

The miniaturization of the technology we can find in the market reduced the size

and the weight of heart rate monitors. Their placement (chest strap, watches, etc.) is

simple and does not interfere with everyday activities. They work on a basis of direct

relationship between the level of exercise and the number of heart beats per minute

(HealthGoods 2007). The devices can be programmed to acquire data at a specific rate

and to download the data to computers in order to be processed and analyzed. Valuable

information for physical activity research, such as intensity, frequency and duration

(Lamonte and Ainsworth 2001), can be inferred. Cardiac rhythm, disturbed due to

psychological events (emotions, for instance) and changes in the inhaled air

composition, can be totally unrelated to physical activity. The consumption of oxygen is

related to heart rate in a very complex way and alterations in the first does not (always)

affect the latter. Factors such as exercised muscle groups, smoking, drugs, food, time of

the day, previous activity and body position can skew heart rate data.

Pedometers Pedometers detect the vertical acceleration of the body and try (they can only

provide a statistic) to count the number of steps (Welk 2002). Most pedometers use a

simple pendulum or swing-arm system to open and close a binary electric circuit

(BodyTronics 2006). The signal encodes the number of steps. Their small size, the

simplicity of the inside system and the fact of being very easy to use are the keys for a

very low cost production. To find the energy expenditure every step is assumed to

consume the same amount of energy, no matter its size or rhythm. For example, the

Yamax DW-500 has the assumption of 0.55 calories/kg/step, regardless the speed.

Some can indicate the estimated walked distance considering an average step length,

approximately 42% of the subject’s height. The devices are not sensitive to isometric

exercise, upper body movement or activity that does not require locomotion. As a

consequence, they have a poor result in their ability to estimate energy expenditure. Due

to their built-in detection system, they do not measure the intensity, duration or

frequency of physical activity.

Page 15: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Introduction

7

Pedometers were commonly used on the belt or waist but we can find nowadays

several models designed to be used on the wrist, ankle and shoe.

Accelerometers

Accelerometers are the newest way to measure physical activity. They have been

available for decades, but only in the last ten years advancements dramatically

improved their accuracy. They transduce acceleration into electric voltage. Provided

with acceleration and time, velocity and distance can be simply calculated, by

integration. The main function of the accelerometers is to convert (by the sensor)

physical movements into electric signals. Proportional to the muscular force producing

motion. Consequently, they can provide direct, objective and accurate values of physical

activity. The sensor’s output signal is sampled by an analog to digital converter, and

sent for a microprocessor for storage. Some devices have a front panel where

information regarding the activity can be displayed. Accelerometer monitors can store

data in order to upload to a computer for further calculation and analysis. They can also

estimate energetic expenditure (Welk 2002) because energy expenditure is a function of

total body acceleration and of the mass of the body displaced. Assuming that the

movements of the limbs and torso are closely related with the whole body energy

expenditure, the device is placed near the center of gravity (waist) to increase its

validity and accuracy. The monitors are small, easy to use and well suited for adults and

children. Perhaps, the overwhelming advantage of recent devices is the built-in

microprocessor. It can be used to compute simple or complex algorithms, to display

multiple features and to communicate with computers. Ultimately, it can be

personalized by setting up parameters according to the subject’s (under observation)

corporal mass. However, using a single accelerometer only in the waist, will enable the

reading of the upper body movement. The placement of the sensor on this particular

place will disregard the movement of the arms and head. Such restriction makes the

study of the energy expenditure in many daily activities and sports, making it

impossible to be accurately measured.

Page 16: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Objective

8

Objective

Project and build a working prototype of a physical activity monitor. The

monitor should be able to capture and record the physical activity of daily routine.

Extreme situations (i.e. extreme sports, accidents, etc.) should not be considered.

Stored information should be able to be uploaded to a computer for data storage,

processing and analysis. Available transmission technologies should be considered for

implementation.

The interface to the device should be simple, allowing the storage of several

sessions and uploading all data on demand. Once uploaded, all the registered sessions

should be deleted.

The monitor should be personalized by setting up a recommended daily physical

activity.

Page 17: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

9

Methods

The monitor is divided in two parts. The first one (sensor block) concerns the

sensor, the analog treatment of the signal: filtering and partial calculation. The second

one (digital block) involves the analog to digital conversion, storage of data,

telecommunications and display. Such separation confers a modular structure and

allows the use of the same sensor block with different digital blocks.

The mobile phone acts as a server collecting data from the monitor via Bluetooth

and forwarding it to a server connected to the Internet.

The server can store session’s logs, supply the date, time and the previous

recorded sessions’ logs. A validation method (ID/password) is implemented on the

server, but not for Bluetooth transmissions.

All monitors, mobile phones and servers have unique IDs. The ID is stamped on

each session’s upload by the monitor. Even when the sessiona’s log are passed from

server to server, the ID on the register will remain unaltered. Consequently, it is always

possible to know which monitor was used.

Signal characterization

Based on the pros and cons of the existing techniques to measure the physical

activity (presented in the Introduction) the accelerometer was chosen to be the preferred

sensor.

Several accelerometers are available, differing in number of axis sensitivity and

range (bandwidth and intensity of acceleration). To maximize the detection of the

movements, a tri-axial sensor was chosen because it’s can sense the vertical, the

mediolateral and the anteroposterior planes. The NASA study (NASA 1959) shows that

people start losing conscience when submitted to accelerations superior to 3.5g in the

positive longitudinal axis. A commercial activity monitor, GT1M (Actigraph, USA), is

limited to sense accelerations with magnitude between 0.05 and 2g. Therefore, an

accelerometer with a range of ±3 g seems reasonable to measure physical activity. The

acceleration frequencies produced by body movement are relatively low. Digitrack (a

commercial physical activity monitor) has the bandwidth of 0.8-12 Hz, what makes any

Page 18: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

10

sensor containing this spectrum being acceptable. The sensor iMEMS® AXDL330 from

Analog Devices fits all the requirements with a range of 0-3g, bandwidth 0.5-550Hz and

it is tri-axial. Extended advantages of this sensor are the low power consumption (1

mW), small monolithic package and ability to detect static acceleration. With static

acceleration we know the relative position of the sensor, being able to determinate the

body position. Although not used in this thesis, advanced algorithms to determinate

caloric expenditure can give useful information.

Representing common physical activities performed by general populations, a

list of particular activities was elaborated. It’s composed by running, walking, jumping,

sleeping, and cycling. To study the signal of the selected accelerometer, the sensor was

firmly attached to the waist through a strap. Electrical cables connected the sensor to a

modified g.®MOBIlab (g.tec, Austria). To store the information in memory, an iPAQ

(Hewlett Packard, USA) was linked to the g.®MOBIlab by RS-232. Figures 1 and 2

represent some of the acquired data.

To verify if the sensor was

working proper the static gravity was

measured in all three axes. The

relation between output voltage and

gravity is ~300mV/g. In Fig. 1 the

proper functioning of the

accelerometer can clearly be seen.

Figure - 1 Rotating the sensor in three axes

Jumping on the same place registered the most intense acceleration as can be

seen in figure 2. The vertical axis (z1) was subjected to 4.3g. A value clearly outside the

accelerometer range and should not be trusted. The lack of information in the datasheet

regarding the maximum voltage output makes plausible to infer that the sensor entered

in a non-linear mode. The usability of the sensor due to its measurement range will be

commented in the discussion chapter.

1 For future reference, the vertical axis will be denoted as z

Page 19: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

11

Figure - 2 Sensor’s z component output while jumping

All the signals were decomposed through a Fast Fourier Transformation.

Illustrations of some components are in figure 3 (jumping), figure 4 (walking) and

figure 5(running). Jumping components with higher frequency than 6Hz become

irrelevant in all axis. The same for frequencies 9.6Hz and 7.5Hz, for walking and

running, respectively. From our sample, the highest relevant frequency is 10Hz.

Leaving a security margin, only frequencies less than 15 Hz are considered relevant.

Rising the arbitrarily is counter producing because vibrations transmitted to the person

will influence the measures.

Page 20: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

12

Figure - 3 FFT of the z component while jumping

Figure - 4 FFT of z component while walking

Figure - 5 FFT of sensor while running

Page 21: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

13

Proposed algorithm to calculate physical activity

In classical mechanics, Newton established the proportional relation between

force and acceleration through mass. He also introduced the concept of inertia implying

effort during jumping in the air, as well as upon reception.

The proposed calculation for physical activity index, during a certain period of

time, is represented in equation 1, where ∆ represents the duration of the activity and a�

represents the dynamic acceleration by the waist.

(((( ))))

t3

Index ii 1 t 0

PA a e t dt,∆====

==== ====

====

∑∑∑∑ ∫∫∫∫

� �

(1)

PAIndex – index of physical activity

a�

- dynamic acceleration

e�

- unity vector

∆ - duration of activity

To minimize the power consumption and to maximize the batteries’ life, part of

the calculation is done in the analog section of the circuit. Each axis from the

accelerometer is filtered, and then the absolute value is summed. This value is sampled

and registered once per second by the ADC. The physical activity index for the whole

activity is obtained by summing all the samples.

Page 22: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

14

The analog block

Idea

This block involves sensing the activity and calculating the physical activity in

small periods of time. All the calculation is done analogally; therefore the output will be

too.

To simplify the hardware implementation, the algorithm proposed in equation

(1) can be rewritten as (2)

(((( ))))

t 3

Index ii 1t 0

PA a e t dt,∆====

========

====

∑∑∑∑∫∫∫∫� �

(2)

Filtering the accelerometer signal is essential to remove the static acceleration

and unwanted frequencies components. A second order Butterworth band pass filter was

designed to be transparent to signals between 0.5 and 15 Hz.

Simulation

To verify the formula, in conjunction with the available hardware, the algorithm

was digitally simulated.

The algorithm was simulated with Simulink® in Matlab® (Mathworks Inc.,

Natick, USA) using data collected by the g. ®MOBIlab. The design of the system is

represented in figure 6. The simulation took into account the power supply values, the

saturation of the circuits involving operational amplifiers and the 10 bits discretization

from the ADC.

Page 23: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

15

Figure - 6 Simulation of the analog circuit with ADC

Raw data from jumping was introduced into the simulation. The intermediate

results for the calculation of the physical activity can be seen in figure 7, after the

summing block, tagged as “aux” in figure 6. The final result, after the integration block

(marked as “aux1” in figure 6), can be observed in figure 8. The ADC, although not

being part of the analog block, was also simulated and its values can be observed in

figure 9. The ADC is represented in figure 6 as the junction of three blocks: saturation,

zero-order-hold and quantizer.

Page 24: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

16

Figure - 7 Intermediate calculation, after the

sum block, while jumping

Figure - 8 Intermediate calculation, after the

Integration block while jumping

Figure - 9 Intermediate calculation, after the ADC block, while jumping

Implementation

The band pass filter is based on a band pass pass followed by a triple order low

pass filter. The first is composed by the internal impedance of the sensor, a condensator

and one resistor, visible in figure 10. The triple low pass is composed by first order low

band pass filter (figure 10) followed by a second order low pass band filter (figure 11).

Figure - 10 1st order band pass band filter and first order low pass band filter

1st order band pass filter

Input Output

1st order low pass filter

Page 25: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

17

Figure - 11 2nd order low pass band filter

Figure - 12 Full wave rectifier circuit

The circuit to calculate the absolute value of the signal is represented in figure

12.

The entire analog block was simulated in LTSpice (Linear Technologies, USA)

before assembled in a prototyping board.

To power the accelerometer, the font of 3.3V, relative to VEE, from the digital

block was used. The VEE and the VDD are provided from two batteries in series where

the middle voltage is used as ground. Consequently the ground of the analog block is

not at the same level as the digital block. Before the calculated signal can be sampled by

the ADC, a shift of reference potential must be done. A subtraction of VEE to the signal

would be enough because the signal is always positive. The voltage output swing from

rail adds a small unpredictable value when the signal is very low. To overcome the

problem, a constant voltage must be added, allowing the signal to be removed from the

critical zone. The value of the constant voltage can be as low as the maximum voltage

output swing from the rails intrinsically dependent on the used operational amplifier. To

extend the possible values of such constant voltage, the ampop OPA735 is used due to

its low rail drift of 0.1V.

The circuit was mounted on a bread board and tested. The slow nature of the

output signal simplifies the selection of components. A signal generator and the

accelerometer were used as source to test the circuit and one oscilloscope permitted to

visualize the output of the analog block. When the source had only DC component or

Input

Input Output

Output

Page 26: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

18

frequencies outside the pass band output was very close to 0V. Signals between 0Hz

and 15Hz presented output’s amplitudes proportional to the source signal.

Technical characteristics of the analog module are:

• Power supply : 3.3V, -3.7, 3.7 and GND

• Power consumption:

o theoretical: 0.066 W

o Measured: 0.080 W

• Signal frequency range: 0.5 to 15 Hz

The digital block

Idea

This part of the system is responsible to create the log of the physical activity, to

manage telecommunication and to interact with the user. The storage of the data is done

digitally after the conversion of the analog signal, representing the physical activity, to a

digital value. The transmission is done on command by the user.

The module composed by a microprocessor, memory, display,

telecommunication module, power supply and a user interface. All the components are

schematically represented in figure 13, as well as the connections with the other blocks.

Figure - 13 Schematic representation of the digital block

µP

Bluetooth /

GPRS

Power supply

Memory

Analog Block

ADC

Digital Block

Display

Buttons

Page 27: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

19

Memory

The memory used has to be non-volatile to avoid data losses caused by power

failure. Non-volatile memories can be mechanically addressed systems (hard drives,

tapes, holographic memory, etc.) or electrical addressed systems (PROM, EPROM,

EEPROM, flash etc.). Having mechanically addressed system is counter-producing in

costs, weight, life time and speed. From the electrical addressed systems EEPROM and

flash are suitable. They need no battery to hold data, they can be rewritten many

millions times and additionally they have low power requirements. The flash memory is

a close relative to the EEPROM; it differs in that it can only be written/erased one block

or "page" at a time and its capacity is substantially larger than that of an EEPROM. It

was chosen to implement the EEPROM in order to have byte-level control. The

memory used was 25LC1024 (Microchip, USA) which is accessed by fast (<20MHz)

SPI bus (2.5-5V level), has low power requirements (5.5mA read/write and 1.1µA in

standby) and a storage capacity of 1Mbit.

On the memory the ID of device, Bluetooth host address, password,

recommended daily activity, version of software, size of address, URL of the server and

the data from each session are stored. The organization of data can be found in

appendix A and the structure of memory for each session can be seen in appendix B.

Telecommunication module

Several communication technologies were considered: ZigBee, Bluetooth,

GPRS, RFID and USB.

USB

The communication through cable, USB, is host controlled: there must be one

(and one only) host per bus controlling the communications, and multiple daisy-chained

peripheral devices. The transfer rate of data is very fast 12 Mbps (USB 1.1) or 480

Mbps (USB 2.0). The commonly available smart phones were designed to act as client

to connect to a PC, the host. Implementing a host controller with drivers for many

Page 28: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

20

mobile phones is not viable. For this reason, the use of USB communication was

discarded.

RFID

Radio frequency identification (RFID) is an automatic identification method,

relying on storing and remotely retrieving data using devices called RFID tags or

transponders2. Uploading the data to another device would not require special human

intervention, it’s only necessary to touch the RFID transponders (the prototype) with the

RFID reader (PC’s peripheral or mobile phone). The protocol can achieve a speed of

26.48kbps(Crisp, Dhokia et al. 2007). Unfortunately only at the end of the project were

mobile phones with RFID technology commercially available, which prevented this

protocol to be implemented.

GPRS

GSM is a digital cellular technology for transmitting voice and data services.

It’s the most used standard for mobile phones, and it’s available in 212 countries and

territories. The total subscribers reached the 2.2 billion, 80% of the world’s cellular

marked, by the end of 2006(GSM 2007).

GSM operates in the 900 MHz band (890 MHz - 960 MHz) in Europe and Asia

and in the 1900 MHz (sometimes referred to as 1.9 GHz) band in the United States. To

suppress the necessity of portability many GSM devices are tri-band and even quad-

band compatible. The distance of communication depends on the base antenna, on the

mobile device antenna and on the radio waves propagation’s conditions. The longest

distance supported by the GSM specification is 35 km. The communication offers a

moderate level of security by implementing shared-secret cryptography. The device is

identified in the network by its SIM card which contains the user’s subscription

information. The card is provided by the network operator to which the subscribers pay

for the services.

GPRS is one among many services provided by the GSM network. The service

is packed-switched implying that all users share the same bandwidth. The available 2 “An automatic device that transmits a predetermined message in response to a predefined received signal”. In http://en.wikipedia.org/wiki/Transponder

Page 29: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

21

bandwidth is distributed by the users according to their use. When one user enters in

idle mode, the resources assigned to it can be reallocated to others that are actually

transferring data. The GPRS provides a maximum rate of 80 kbps for download and 40

kbps for upload. The range is the same as the GSM service, since it is laid over it.

To provide independence from other devices and enhance the mobility, this

technology was adopted. The drawback of this technology is the high power

requirements which are far more demanding than all the other technologies compared.

The GPRS module adopted was the GM862-GPS (Telit, Italy). The

communication with the microprocessor is done by serial interface with 2.8V CMOS

logic level. The communication with the base station can be done in any of the four

frequencies, enabling its use almost in every part of the world. The module is controlled

by AT commands. The easy GPRS extension (telit 2007) allows the module to contact a

device connected to the Internet and to trade raw data over the GRPS and Internet

networks, i.e. a virtual serial communication between the microchip and the server.

In addition to the GPRS module, a SIM card was necessary. Therefore, a

contract with a mobile company was celebrated.

Bluetooth

Bluetooth is a protocol for wireless personal area networks, typically limited to a

small cell radius. Within the cell a maximum of 255 devices can be connected, but only

up to seven can be active. It was designed to short-range transmission (1 – 100 m) of

digital voice and data for point-to-point and multipoint applications. Bluetooth uses

omni directional radio waves that can transmit data, through thin walls and other non-

metal barriers, at a maximum speed of 720 Kbps3 in the 2.4GHz band. Each device has

a name, class, list of services, technical features (manufacturer, device features,

Bluetooth protocol version, etc.) that will be transmitted on demand. Every device has a

48-bit address to uniquely identify them in the whole world, but generally the addresses

are not shown in the enquiries. Some applications, for security reasons, demand the

user’s authorization for accepting a connection. To automate the process it is possible to

pair two devices. Once paired, the communication is established without human

3 Today, Bluetooth version 2.0 + EDR is able to reach 3 Mbps.

Page 30: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

22

interaction. The data can be encrypted before transmission for privacy enhancement. To

minimize interference, the used bandwidth is divided in 79 channels with 1 MHz each

and hop from channel to channel up to 1600 times per second. This hopping technique

reflects in power consumption.

There are many profiles defined, for example: generic access profile, service

discovery application profile, cordless telephony profile, intercom profile, serial port

profile, headset profile, dial-up networking profile, fax profile, LAN access profile,

generic object exchange profile, object push profile, file transfer profile and

synchronization profile. Only two of them are suitable for our application: generic

object exchange profile and serial port profile. The first defines a set of protocols and

procedures to exchange objects. It is based on the serial port profile and is suitable for

uploading the data but once the information is on the phone, it is mandatory to install a

program in order to read it. The serial port profile can easily be configured to be used as

cable replacement providing emulation of RS232 (a common interface standard). By

using the RS232 standard the software implementation is simplified. These were the

main reasons to adopt the serial port profile. By programming at a lower level, more

freedom is achieved.

The Bluetooth module selected was BISM2 (EZURIO, UK). It’s a class 1 model,

able to transmit up to 100 m (free space); the protocol implemented is Bluetooth 2.0

with a maximum transmission rate of 300 kbps, a power consumption of 22mA during

transmission, a power supply of 3.6V – 7V and a serial interface (3.3V level) with AT

commands. The module is configured to be non-detectable (doesn’t respond to

scanning), i.e. the device does not accept incoming communications/requests (this

implying that the device will always start the communication).

ZigBee

ZigBee is a protocol aimed for embedded applications with low data rates and

low power consumption. Using a mesh network (enabling redundant paths), automatic

retries, high interference tolerance the protocol provides high reliability. Information

can be transmitted until 75 meters with the transmission rate of 250 kbps. Available

solutions in the market demand only 1.1 µA in standby and 300 µA in transmission

mode. When it was necessary to decide which type of communication to use, there

Page 31: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

23

were only a few mobile phones available with ZigBee incorporated. For this reason this

protocol was not adopted. At the end of the project, several innovations happened: new

mobile phones with ZigBee incorporated are available and the ZigBee SIM card was

developed. This ZigBee SIM card can upgrade a common phone with ZigBee

functionality.

Summary of communications

The ZigBee and RFID could not be used because they were not accessible.

The USB is not wireless and its implementation to communicate with mobile

phones is not viable.

The main characteristics of the adopted technologies are presented on table 1.

GPRS Bluetooth

Application Focus Wide area voice and

data trasmission Cable replacement

System Resources 16 MB+ 250 KB+

Battery Life (days) 1-7 1-7

Network size 1 7

Bandwith (KB/s) 80 720

Transmission

Range (m) 1000+ 1-10+

Success Metrics Reach, Quality Cost, Convenience

Table 1 Comparation of transmission technologies, adapted from (NEC 2006) and from (Wikipedia 2007)

Connecting the blocks

To connect the telecommunication modules to the microprocessor it is

imperative to respect each device’s voltage requirements. Improper connection can

result in incorrect functioning or even in the destruction of the module.

By looking at the datasheets, the serial ports of the microprocessor, the

Bluetooth module and the GPRS module have different voltage levels. The GPRS

Page 32: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

24

module works at 2.8 CMOS logic level, the Bluetooth module works at 3.3 CMOS logic

level and the microprocessor can work at several levels depending on the power supply.

By analyzing the voltages levels in a more detailed way it is possible to see if the two

voltage levels are compatible.

The microprocessor and the EEPROM are connected through a SPI bus. The

voltage of the SPI port of both components are determinate by their supply voltage. The

level of the voltage used limits the maximum speed. It was decided to use the maximum

voltage that ensures the compatibility with the Bluetooth or the GPRS modules.

Consequently the voltage for SPI and serial communication is 3.3V. To force the µP and

the memory to communicate at this voltage level, their power supply must be 3.3V.

By representing VILmax, VOLmax, VOHmin and VOHmax, in figure 14, the

compatibility of modules becomes visible: the µP can connect directly with the

Bluetooth module, but there is no guarantee that the µP can communicate directly with

the GPRS module (VIHminµP > VOHminGPRS). There is no guarantee that the

communication between the PIC and the GPRS module can be done without any

voltage level translator. To test if these two modules can communicate directly, they

were assembled on a prototyping board. The two modules were able to communicate

successfully. Based on this result, the circuits were drawn with direct connection for

both the Bluetooth and the GPRS modules to the microprocessor.

The possibility of using a level translator for the serial port of the

microprocessor was also considered. It’s not necessary to change the output levels, but

the input should have a gain of 1.3V. The logic levels of the microprocessor, with the

level translator, are also represented in figure 14 as “PICtranslated”.

Logic levels relation

0

0,5

1

1,5

2

2,5

3

3,5

GND

VILm

ax

VOLm

ax

VIHm

in

VOHm

in

Vmax

Vol

ts

PIC

BLUETOOTH

GPRS

PICtranslated

Figure - 14 Logic level relation

Page 33: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

25

Power Supply

The power supply was designed to be versatile, to power all the components and

to be easily modifiable. The µP, the accelerometer, the memory and the display must be

powered by 3.3V. But the highest demands are imposed by the GPRS module with:

• Nominal supply voltage: 3.8 V

• Max. supply voltage: 4.2 V

• Supply voltage range: 3.4 V - 4.2 V

• Max. peak current consumption (impulsive): 1.9 A

• Max. average current consumption during GPRS transmission: 400 mA

• Average current consumption during power saving: ≈ 4 mA

• Average current consumption during idle (power saving disabled) ≈ 17 mA

Two batteries Li/Ion accumulators were connected in serial providing 3.7V and

7.4V. Li/Ion accumulators have a very constant voltage during discharging until almost

depleted, where the voltage drops abruptly. The accumulators chosen provide 3.7V of

nominal voltage, 3500 mA and have a capacity of 2600 mAh. One LDO, connected to

3.7V provides a stable voltage of 3.3V. A second LDO, controlled by the µP and

powered by 7.2 V, provides 3.8V. In spite of the LDO inefficiency, it can deal with high

currents and have a fast response time. The selected LDO, LT®1528 (Linear

Technologies, USA), is able to deal with loads up to 3A and has a wide input voltage

range (1 to 15V). It has a fast transient response (~10 µs) and a voltage controlled

shutdown. By controlling the power supply to a module, it’s possible to force an

absolute no consumption by the module when not needed.

The drawback of the configuration is a faster discharge of one accumulator

relatively to the other one. The 3.3V LDO is always on, while the second LDO using

both accumulators is only on during transmission. When the second LDO is on, the

current is provided by both cells, adding extra load to the low voltage accumulator.

Page 34: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

26

Technical characteristics of the digital module are:

• Power supply : 2 x 3.7 V Li/Ion batteries

• Power consumption:

Theoretical

[W]

Measured

(Average)

[W]

Average Maximum

Transmiting 0.223 0.867 0.496

Idle 0.06 0.11 0.059

Recording 0.08 0.127 0.1

Microprocessor

The digital system is centered on one microprocessor 18F2680 (Microchip,

USA). It was selected because it presents several analog inputs, incorporated ADC,

digital input/output, flexible oscillator structure, USART, SPI, interrupts, in-circuit

debug and nanoWatt technology. The selected programming language was C and it

makes use of the many libraries provided by the fabricant. The development

environment was is the MPLAB IDE (Microchip, USA) and the µP programmer the

MPLAB ICD 2 (Microchip, USA).

The µP runs in two speed modes: normal and slow. To provide different clock

speeds, two resonant circuits were implemented. Each circuit is composed by two

condensators and one crystal. The normal speed is provided by a 20 MHz crystal and

the slow one is obtained with a 32.768 kHz crystal. It’s possible to select the speed

mode, by changing clock sources, at any point of the program by software instruction.

The slow mode is for waiting periods (waiting for a key to be pressed, waiting for the

next acquisition). All the other activities run at normal speed. The slow mode saves

energy by executing fewer instructions per second or even disable CPU core4. The

circuit is also used to trigger the Timer1’s counter from 0 to 216, which overflows every

two seconds creating an interrupt. By preloading the counter with 215 an interrupt is

generated every second. Keeping track of the number of seconds elapsed a RTC is

implemented by software. The interrupt routine’s flowchart is in Appendix C.

4 Even with the CPU core disabled, the microprocessor has the peripherals on.

Page 35: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

27

The program was designed in a modular structure, according to figure 15.

Figure - 15 Microprocessor program’s modules

The main flowchart of the program is in figure 16.

After a cold start5 the µP tries to contact the server to ask for the current time

and the recommended daily activity. If connection or transmission fails it will go on

trying until being successful. After having the necessary information, it will wait until

the transmission or the start/stop button is pressed.

In case of the transmission button being pressed, a new connection to the server

will be attempted. If it fails, it will return to the previous state. If it succeeds an upload

of information will start. During the transmission, the display shows a bar chart

informing the user of the evolution of the process. After transmission, the device returns

to the main menu. The transmission routine flowchart is in appendix E.

5 Turning the power on when previously was off long enough to loose all information in volatile memory

Memory basic

routines Memoria.c

Memory mapping

Memory.c

Bluetooth interface

Bluetooth.c

Sensor

Sensor.c

Real Time Clock RTC.C

Display

LCD.c

Communication protocol Client.c

Activity log

LOG.C

Human input

Buttons.c

GPRS interface GPRS.C

SPI communication

Serial Interface Analog I/O

Digital I/O

Initialization and main cycle

Main.c

Libraries provided by manufacturer

Interface with memory

Interface with the analog block

Interaction with the subject

Interface with the communication block

Page 36: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

28

In case of the start/stop button being pressed, a new session record will

be created and every second a sample will be added to the session until the start/stop

button is pressed again. The flowchart of the record session routine is in appendix D.

Figure - 16 Main flowchart of the microprocessor

Cold start

Contact Server and

retrieve data

Success? Yes No

Main menu

Sleep

Transmit Start/Stop

None

Is Button

Pressed?

Record session

Transmit

Page 37: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

29

Mobile Phone

Idea

The mobile phone can be used as a server and a client. When accepting the

connection by Bluetooth it acts like a server. It is a client, when uploading the data to a

server in the internet. The upload can be done by GPRS/UMTS. A simple user interface

also enables to visualize the physical activity of each session in a graph.

Selection of models and development environment

Mobile phones are constantly present in everyday’s life. There are many brands

and kinds of cellular devices, from the simplest to the most complex. The simple mobile

phone that can only handle voice calls and SMS is not the consumer’s most favorite.

He demands entertainment (games, sounds, movies, etc.), scheduler, alarms and

connectivity with different devices (PC, handheld, internet, domotics, etc.). To achieve

these demands different communication technologies are incorporated, some of them

are presented in the telecommunication module. A mobile phone with these

characteristics is often referred as a smart phone (TechTarget 2007) .

There are many operative systems available for these devices. Some of them are:

Symbian OSTM (Symbian Limited, UK), LinuxTM, Windows MobileTM (Microsoft

Corporation, USA), GarnetTM OS (Palm Inc, USA) (Coustan and Strickland 2007).

Symbian leads the market with more than 50% of every smart phone shipped since 2005

(symbian 2007). The Symbian OS is adopted by Nokia. This company has the

leadership in the production of smart phones with a 56%, representing 40 millions of

devices, in 2006 (abiresearch 2007). The selection of the mobile phone was done aiming

to engage as many costumers as possible. Two smart phones were selected: Nokia N70

and Nokia N73 Music edition. For our application, they are quite similar but have

different versions of operative systems: Symbian OSTM 8.1 and Symbian OSTM 9.1.

The selected mobiles phones natively handle java or C++. Shortly after starting a

deeper study on the java environment, it was abandoned in favor of the python

programming language. A contact from Nokia recommended the use of python for its

high level of abstraction, modular structure and fast growing popularity. Python is a

Page 38: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

30

recent programming language and there is not much documentation available but the

python’s community proved to be the source of much help and information.

To be able to run python’ scripts, it’s necessary to install the pys60. The file

installs the python interpreter, based on Python 2.2.2. It supports many of the Python

Standard Library but has on the top some mobile platform specific modules. For

instance the modules consist of graphical user interface, Bluetooth, GPRS, and SMS.

The development environment can be a simple text editor, but Wing IDE

(Wingware, USA) was the one used. The list of features is long, but the most important

are: syntax highlighting, auto-completion for Python and extension modules, error

indicators and powerful debug.

The modules

The program is based on several modules. Each module was created to handle an

independent problem and to simplify the structure of the program:

• config – contains parameters that control the program (message coding,

timeouts, internet parameters, etc.).

• communication – holds the interface for Bluetooth and TCP/IP

• record_to_file – handle files regarding the sessions’ records

• take_care_request – used by the server to process the client’s requests

• phone – main program script

• show_graph_app – script to visualize sessions’ records

• bluetooth_server – script with the implementation of the Bluetooth server

Communication

The communication is done in client/server architecture. The server is waiting

for the incoming connection of the client. The client initiates the connection and issues

commands to the server that processes them. After successful connection establishment,

the client identifies itself by providing the ID and the password. If the pair

(ID/password) is not valid, the server will close the connection. If it is correct, it will

Page 39: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

31

wait for the incoming commands. Several commands might follow until the connection

is closed, on the client’s request.

The package_communication class

creates an abstraction layer for the

Bluetooth and the TCP communications.

The transport layer (TCP) is above the

Internet layer (IP), which is over the data

link layer (Ethernet or GPRS). This

hierarchy is schematically drawn in figure

17.

The Bluetooth_comunication and

the TCP_communication classes implement

the following procedures: connection

dialing, waiting for connection, sending

data, receiving data and end of connection.

Figure - 17 Communication hierarchy

The package_communication implements the message protocol developed

according to table 2. The client-server exchange information through messages with a

rigid format. In addition, the message is composed by a header, with fixed length (56

bits), and by a payload, with variable lengh. All the fields were coded with little-endian

codification to be compatible with the microprocessor codification.

Code (8 bits)

Device ID (16 bits)

Length of the payload 32 bits

Payload Variable length 0..232-1 bytes

Table 2 Structure of messages

The number of different kinds of messages is restricted to a maximum of 256,

which seams reasonable. Only eleven kinds of messages were coded for normal

operation. There are also some kinds of messages coded just for testing during the

development phase of the project. A list of the messages can be found in appendix F.

The ID is always referring to the machine which is transmitting the message.

Bluetooth

Ethernet

TCP/IP

GPRS

package_communication

bluetooth_ _communication

tcp_communcation

Symbian standard sockets

pyS60 socket extension

Page 40: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

32

To establish a connection, both the server and the client must initialize the

package_communication. On one’s hand the server must listen to incoming requests and

accept them; on the other hand the client must provide the IP/Bluetooth address and the

port of the server. For the Bluetooth connections the port is omitted, because the

operative system channels all the incoming connections with serial port profile to the

program.

To send a message, the package_communication receives the code of the

message and the data as parameters and creates a datagram. Afterwards the whole

datagram is passed to the under layer that transmits the message.

To receive a message, the package_communication waits until the message’s

header arrives. The header is decoded by extracting the code of the message, the ID and

the data length. In the possession of the expected length of data, the channel is read until

all expected bits are extracted. This successive reading is necessary because the data

provided by the under layers do not arrive altogether. Packages might be fragmented

and sent by different paths. At the destination the packages are reordered and placed in

the socket buffer as they are coming. When reading the buffer, it’s quite possible that

not all data have arrived. Subsequent readings will take care of the problem.

Every time a message is sent, the sender waits for one OK message from the

receiver. If the message does not arrive during a certain period of time (defined in the

module config) the message will be resent. In case of a broken connection an error will

be generated and the connection will be eliminated.

Error checking was not implemented because both Bluetooth and TCP/IP have

CRC error checking.

record_to_file

The module implements the file handling for sessions’ records.

All uploads from one device are saved in a directory that is named after the ID.

In this directory each session has its unique file. The name of the file is given according

to the starting date and the time of the recording process. The name is the ordered

concatenation of the year, month, day, hour and minute. Its extension is represented by

a string defined in the config module. This method can not distinguish between two

Page 41: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

33

records done in the same minute, but this is unlikely to happen. If it happens, it is

assumed that the previous session was aborted and the first record will be overwritten.

The file is recorded in a binary file with the structure represented on table 3. To

separate the items, the line feed character is used.

Fields Type of data Description

ID unsigned 16bit int ID of the monitor

time_of_recording unsigned 32 bit long Time in seconds since 00H00

1/1/1970

frequency unsigned char Sampling frequency [Hz]

number_samples unsigned long The number of samples in the

data field

recomended_activity unsigned int The recommended activity at the

time it was recorded

number_channel unsigned char Number of sampled channels

data 16 bits x number_channels

Table 3 Record file's structure

All the fields use the little-endian codification.

The file structure can handle multiple channels. The number of the channel is

used to decode the data sequence. The field data contains all the channels’ samples

ordered by time (sample1channel1, sample1channel2, sample2channel1,

sample2channel2 …).

take_care_request

The module embeds the processing of the client’s commands.

The identification process is not implemented in this block, as it should be

processed immediately after accepting the connection.

The list of commands is listed in appendix F.

Page 42: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

34

Config

The simplest of the modules contains the parameters for the program: paths, the

IP address and port number of the server, the machine ID, messages’ codes and

extensions for naming records’ files.

The main program

The main program has the graphical user interface and, according to the user,

runs other modules.

The program shows the company logo when it starts (figure 18) and then it

presents three choices: uploading data to the server (upload record), starting Bluetooth

server (Bluetooth server), and plotting (plot record) some previously stored

record/session’s log (figure 19).

The Bluetooth server is an external script, “bluetooth_server”. It listens to the

Bluetooth connections with the serial port profile. When the connection is established,

the identification message is received, but no validation takes place.

To upload a file, a list of directories with different IDs is presented, if there are

more than one directory. Inside the directory, the file to upload must be selected (figure

20). Then the GPRS communication is established and the file is uploaded.

In order to plot the graph, the external script “show_graph_app” is called. After

an identical selection of the file, the record is displayed in a line graph (figure 21).

Figure - 18 Initial screen Figure - 19 Main Menu Figure - 20 Selecting file

Page 43: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

35

Figure - 21 Plot of record

Server

Idea

The server accepts incoming connections from mobile phones, from monitors

equipped with GRPS modules or from other computers. It’s used as a repository of

information that can always be available. The computer overcomes some of the

limitations of the monitor and of the mobile phone: the monitor has a just a small

amount of memory and the mobile phone has limited processing power and small

display. Furthermore, the computer offers the possibility of easy data manipulation and

of printing/publishing data.

The server also has a unique ID and is able to deal with multiple requests at the

same time. The maximum number of simultaneous connections is specified in the

module “config”.

To create the graphical user interface, the program VisualWx (2007) was

adopted. The program should be compatible with Linux, but it was never tested.

Modules

One great advantage of python is its portability. Almost all the modules created

or improved can be used for both programs. Therefore, almost all files are shared. The

modules containing the main program, the graphical user interface, are not compatible.

Two more modules were developed for this application:

Page 44: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

36

• users – contains login handling and file storage for logins

• userman –GUI for manage logins

To simplify the development, the config module was divided in three parts. The

first part refers to the mobile phone, the second to the server, and the third refers to

both.

The module “handle_client_request” was also extended to hold specific

messages from the Client program. The full list of implemented messages and their

description is available in appendix F.

users

The logins are stored in the text file “users.txt”. The structure consists in one

entry per line, respecting the previously presented format (ID, password, recommended

daily activity).

Several methods were implemented: to validate the pair ID/password, to create a

new user, to delete one user, to load data from file and to save data to file.

Main script

The program consists in one main cycle listening to incoming connections on

one port defined in the “config” module. Each time a connection with one client is

established, a new thread is created to handle the client. The maximum number of

simultaneous threads allowed is specified in the module “config”.

The client, upon connection, must identify itself by issuing the

MSG_IDENTIFY6 message. If the client is not validated by the module “users”, the

connection will be closed and the thread terminated. If the client is accepted, the server

will wait for incoming messages. The messages will be processed until the client

terminates the connection by issuing the MSG_CLOSE_COMMUNICATION.

6 The specification can be seen in appendix F.

Page 45: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

37

In the main window (figure 22) the currently connected client’s ID are displayed

in one list. The activity log on the server is visible too. The activity log contains

incoming connections, incoming messages and their results and connections’

terminations.

This interactivity with the server is simple. There is only one button to launch

the “userman” script. This script handles the management of logins and has a simple

GUI (figure 23).

Figure - 22 Server GUI

Figure - 23 Userman GUI

Page 46: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Methods

38

Client program

The only purpose of this script is to retrieve the session’s logs and to display

them graphically with some statistic information.

It connects to the server, provides the pair ID/password and retrieves the list of

records available for that user. By selecting a particular record (session’ log), the

download starts automatically. Once the duration completed, the maximum value, the

minimum value and the integration of all values will be displayed on the main window

(figure 24). The graph is plotted in a new window with some basic control (zooming

and saving).

The graph (figure 25) is drawn by using the module “matplotlib” (Hunter 2007).

The module is a python 2D plotting library with simple interface.

Figure - 24 Client program’s window

Figure - 25 Plot of record

Page 47: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Results

39

Results

The physical activity monitor was attached to a belt fastened to the waist. The

light weight of the box didn’t disturb the activity. But, on the other hand, the size

restricted the natural swing of the arm.

Three subjects equipped with the monitor performed different kinds of activities:

walking, running, jumping, climbing and descending stairs. The statistical information

of the collected data can be observed on table 4.

Figure 26 shows a graphic of the physical activity index through a battery of

exercises. The level corresponding to no activity (standing still) is 438.

Subject A

(Male) Subject B

(Male) Subject C (Female)

max min average max min average max min average walk 549,0 514,0 539,1 548,0 511,0 538,0 581,0 511,2 533,9 downstairs 574,0 509,0 551,4 596,0 517,0 542,9 597,0 512,2 540,5 upstairs 560,0 509,0 550,1 549,0 509,0 548,0 592,0 517,2 539,2 jump 642,0 515,0 606,4 629,0 512,0 602,0 670,0 510,2 619,3 run 603,0 512,0 575,9 600,0 513,0 573,0 669,0 508,2 577,6

Table 4 Physical activity index in different activities

Figure - 26 Monitor’s record with different activit ies for subject B (walking, running, jumping)

walk stop run stop jump

abnormality

Act

ivity

Page 48: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Results

40

The monitor’s prototype (the printed circuit board) can be seen in figure 27 and

the description of the components on table 5. The equipment was mounted in a card box

with the exterior dimensions of 19cm x 13.5cm.

Figure - 27 Prototype of monitor plus repairs

# Description 1 Microprocessor 2 Batteries 3 Bluetooth module 4 Record button 5 LCD display 6 Transmit button 7 Prototype board with circuit corrections 8 Tri-axial accelerometer 9 EEPROM 10 LDO to power the transmission module

Table 5 Monitor components

10

2

5

3

4

6

7

1

9

8

Page 49: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Discussion

41

Discussion

Table 4 shows the physical activity index for different kinds of activities. The

most demanding was jumping followed by running, descending stairs, climbing stairs

and walking. Different values for physical activity are observed among the several

activities performed by both subjects. The difference of the average physical activity

during jumping is explained by the different styles of jumping. Subject C jumps faster

and has more rigid receptions, therefore subject to more intense accelerations.

It is interesting to notice that, for Subject B, jumping and running are not clearly

distinguished. It can be explained by observing the difference of the movements. The

intensity of the impulses given by the inferior limbs is similar but the projections in the

three axes are not. While running the body is propelled forwards and while jumping the

body is mainly propelled upwards. The physical activity index is calculated without

concerning the direction of the acceleration. Therefore, jumping and running can

produce similar results.

By comparing figure 26 with table 4 it’s observable that the minimum index of

physical activity is not always the same. This fluctuation is caused by form the added

constant in the analog block is produced: a voltage divisor composed by two resistors

connected directly to the batteries. Any alteration on the batteries’ output voltage

reflects in the change of the value of the constant. A good alternative can be the use of

the microprocessor’s DAC to provide a software controlled value.

The big size of the box proved to be intrusive to the performed activity. The

movement of the arms is reduced by the presence of the apparatus. There are also

psychological effects: some people were reluctant to wear such uncommon and visible

box strapped to the waist. The size and the weight are very important not to interfere

with the activity and to the mental well-being.

After the fabrication of the PCB some bugs were detected and had to be

corrected. It was not possible to correct the analog circuit board. Therefore the rectified

circuit was mounted on a prototype board (visible in figure 27). The prototype board has

spring connections that have poor performance in vibrating environments. This problem

was the cause of the abnormality in figure 26.

Page 50: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Discussion

42

The communication among all the components presents no problems. Although

the scheme of the monitor version with GPRS was designed, no prototype was made.

The GPRS interface, in the µP program, was not implemented due the lack of time.

Sometimes the sensor registers accelerations outside its normal range. In those

cases there is no guarantee that the real acceleration is not even higher. Although the

high amplitude, they have very small time duration. Therefore, the effects over the

physical activity index are not so visible.

The algorithm to calculate the physical activity index can be greatly improved.

Its performance and accuracy should be compared with similar devices on the market

and with other methods used to measure the physical activity.

Page 51: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Literature

43

Literature (2007). "Visual Wx." 2007, from http://visualwx.altervista.org/. abiresearch. (2007). "Nokia Leading Smartphone Market with 56%, While Symbian's

Share of OS Market Is Set to Fall." Retrieved 06.07.2007, 2007, from http://www.abiresearch.com/abiprdisplay.jsp?pressid=826.

BioTrainerUSA. (2007). "BioTrainer™ Clinical Studies." 2007, from http://www.biotrainerusa.com/clinical.asp.

Blair, S. N., H. W. Kohl, 3rd, et al. (1995). "Changes in physical fitness and all-cause mortality. A prospective study of healthy and unhealthy men." Jama 273(14): 1093-8.

BodyTronics. (2006). "Pedometer Theory of Operation: How do they work?" 2007, from http://www.bodytronics.com/page/bodytronics/pedometershowwork.

BYRNE, D. (2003). The health status of the European Union — Narrowing the health gap, Office for Official Publications of the European Communities.

Carneiro, A. L., T. Lopes, et al. (2002). Mecanismos de adaptação ao exercício físico. Porto.

Caspersen, C., K. Powell, et al. (1985). "Physical activity, exercise, and physical fitness: Definitions and distinctions for health-related research." Pub Health Rep 100(2): S126-30.

Coustan, D. and J. Strickland. (2007). "Smartphone Operating Systems." 2007, from http://communication.howstuffworks.com/smartphone2.htm.

Crisp, D., S. Dhokia, et al. (2007). RFID and Multimedia. DuRant, R. H., T. Baranowski, et al. (1993). "Association among serum lipid and

lipoprotein concentrations and physical activity, physical fitness, and body composition in young children

" J Pediatr 123(2): 185-92. Epstein, L. H., Y.-W. B. Wu, et al. (2000). "Asthma and Maternal Body Mass Index Are

Related to Pediatric Body Mass Index and Obesity: Results from the Third National Health and Nutrition Examination Survey

" Obesity Res 8(8): 575-581. GSM. (2007). "GSM Brochure 2007." 2007, from

http://www.gsmworld.com/documents/gsm_brochure.pdf. HealthGoods. (2007). "Heart Rate Monitors." from

http://www.healthgoods.com/Shopping/Health_and_Fitness_Products/Heart_Rate_Monitors.asp.

Hunter, J. (2007). matplotlib. Kesaniemi, Y. K., E. Danforth, Jr., et al. (2001). "Dose-response issues concerning

physical activity and health: an evidence-based symposium." Med Sci Sports Exerc 33(6 Suppl): S351-8.

Kohl, H. W., J. E. Fulton, et al. (2000). " Assessment of Physical Activity among Children and Adolescents: A Review and Synthesis." Preventive Medicine and Science in Sports and: 31.

Lamonte, M. J. and B. E. Ainsworth (2001). "Quantifying energy expenditure and physical activity in the context of dose response." Med Sci Sports Exerc 33(6 Suppl): S370-8; discussion S419-20.

Martin, A. D. and C. S. Houston (1994). "Physical activity and obesity Osteoporosis, calcium and physical activity." CMAJ 151(12): 1732-1733.

Page 52: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

Literature

44

Montoye, H. J. (2000). "Introduction: evaluation of some measurements of physical activity and energy expenditure." Med Sci Sports Exerc 32(9 Suppl): S439-41.

NASA (1959). ASTRONAUTICS AND ITS APPLICATIONS, GOVERNMENT PRINTING OFFICE.

NEC. (2006). "Wireless Sensor Network Solution." Retrieved 06.06.2007, 2007, from http://www.eu.necel.com/micro/technology/zigbee/pdf/ZigBee_Solution_Nov_2006_E_v01.pdf.

Raustorp, A. (2005). Physical activity, body composition and physical self-esteem among children and adolescents Neurotec Department Stockholm, Karolisnka Intitutet.

Rettman, A. (2006, 06.06.2006 - 09:39). "Obesity epidemic costs EU €59 billion a year." Retrieved 02.06.2007, 2007, from http://euobserver.com/867/21720.

Sallis, J. F. and B. E. Saelens (2000). "Assessment of physical activity by self-report: status, limitations, and future directions." Res Q Exerc Sport 71(2 Suppl): S1-14.

Schoeller, D. A. (1988). "Measurement of energy expenditure in free-living humans by using doubly labeled water." J Nutr 118(11): 1278-89.

Solutions, M. (2007). "Energy Expenditure Using Doubly Labeled Water." Retrieved 2007, from http://www.metsol.com/energy_expenditure.htm.

symbian. (2007). "Syambian fast facts." from http://www.symbian.com/about/fastfacts/fastfacts.html.

Tavares, A. M. (2003). "POTENCIAL DE AÇÃO (PA)." Retrieved 02.06.2007, 2007, from http://www.geocities.com/amtavaresj/sistemapotenciacao.htm.

TechTarget. (2007). "SearchMobileComputing.com Definitions." 2007, from http://searchmobilecomputing.techtarget.com/sDefinition/0,,sid40_gci330613,00.html.

telit. (2007). "Easy GPRS User Guide." from http://www.telit.co.it/data/uploads_EN/products/80000ST10028_Easy%20GPRS%20User%20Guide_r1.pdf.

Tudor-Locke, C. E. and A. M. Myers (2001). "Challenges and opportunities for measuring physical activity in sedentary adults." Sports Med 31(2): 91-100.

Vogel, J. A. (1999). Research Workshop on physical fitness standards and measurements within the military services. M. Military Operational Medicide Research program Fort Dtrick, USA.

Warburton, D. E. R., C. W. Nicol, et al. (2006). "Health benefits of physical activity: the evidence." CMAJ 174(6): 801-809.

Welk, G. (2002). Physical activity assessments for health-related research. Champaign, IL, Human Kinetics.

Wikipedia. (2007). "General Packet Radio Service." from http://en.wikipedia.org/wiki/General_Packet_Radio_Service.

Page 53: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

45

APPENDIX A Memory Organization

ADDR Field data type

Byte

0 ID_low 1 ID_high

Int16

2 Version of software 3 number_of_sessions_recorded 4 size of memory H 5 size of memory 6 size of memory 7 size of memory L

Size of memory float

8 Bluetooth_primary address 0 9 Bluetooth_primary address 1

10 Bluetooth_primary address 2 11 Bluetooth_primary address 3 12 Bluetooth_primary address 4 13 Bluetooth_primary address 5 14 Bluetooth_primary address 6 15 Bluetooth_primary address 7 16 Bluetooth_primary address 8 17 Bluetooth_primary address 9 18 Bluetooth_primary address 10 19 Bluetooth_primary address 11 20 Bluetooth_primary address 12

Bluetooth Address of the server

21 url address[0] 22 url address[1] 23 ... 24 ... ... 51 url address[30]

URL of server

52 Password_H 53 Password_L

Int16

54 Recomended_daily activity_H Recomended_daily activity_L

Int16

... 100 session_1_high adress 101 session_1_mid adress 102 session_1_mid adress 103 session_1_low_adress

4 bytes address

104 session_2_high adress 105 session_2_mid adress

... session_2_mid adress

... session_2_low_adress

4 bytes address

100

reco

rds

TLR Table

of Records

Page 54: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

46

400 Data 401 Data 402 Data 403 Data 404 Data 405 Data

Page 55: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

47

APPENDIX B Session’s memory organization

Address Contents description

base magic number start of record

base + 1 seconds since 1/1/1970 high

base + 2 seconds since 1/1/1970

base + 3 seconds since 1/1/1970

base + 4 seconds since 1/1/1970 low base + 5 Freq_sampling = 1

Time of starting recording

base + 6 Number_samples_H

base + 7 Number_samples_M Length of the record

base + 8 Number_samples_M base + 9 Number_samples_L

base + 10 Recomended Daily activity h

base + 11 Recomended Daily activity l

base + 12 Number of channels

base + 13 RESERVED base + 14 RESERVED

base + 15 RESERVED

base + 16 Sample 1 channel1 base+16+number_sample*2

base + 17 Sample 1 channel 2

base + 18 ...

... Sample 2 channel 1

Sample 2 channel 2

Page 56: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

48

APPENDIX C Interrupt flowchart

Interrupt Timer1

Clear interrupt flags

Increase counter of seconds by one

Return

Page 57: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

49

APPENDIX D Record Session routine flowchart

Record Session

Create new record session in memory

Sleep for one second

Return

Turn the ADC module on

Sample once

Turn the ADC module off

Record value in non-volatile memory Increment the number of samples in

memory

Button Start/stop Pressed?

Yes No

Page 58: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

50

APPENDIX E Transmit routine flowchart

Transmit

Turn the transmission module on

Test correct function of the transmission module

Transmission module OK?

Yes No

Connection established?

Yes No

Successfully received?

Yes No

Return

Display error message

Update progression bar on display

i = number of session in memory

i=0?

No Yes

i = i - 1 Display success message

Send session i

Decrease the number of session

in memory

Page 59: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

51

APPENDIX F Different messages coded

- IDENTIFICATION – Authenticate the client on the server. If the pair

(ID, password) is not valid, the connection is terminated by the server.

o Payload is a 16 bits password composing a integer (16 bits) o There is no answer from the server

- REQUEST TIME – The server will respond with the current time o The payload of the request is empty o The server returns a message with the payload of a long

integer (32 bits). The number represents the seconds since 00H00 1/1/1970.

- CODE_MSG_UPLOAD_DATA_SESSION – uploads a data session.

o The payload is the raw binary content of a session and follows exactly the same structure as the binary file for records

o The name is generated based on the starting date and time of

recording. The file will be saved on the folder of the ID (this ID is in the payload and not the one in the message header)

o There is no answer from the server

- CODE_MSG_CLOSE_COMMUNICATION – Terminates the session

o No payload

- CODE_MSG_FILE_UPLOAD – uploads any kind of file. o The payload follows the codification:

o I

f The first field is delimited by the ‘\n’ character. The field is

used to encode and decode the following ones, through the standard Python module “struct”.

The size of the file data is limited to 4 TB. This limitation is imposed by the message’s header implementation.

String with

encoding format

‘\n’ Name of file

(string)

Size of file

(unsigned long)

File data

Page 60: Intelligent Device for Sensing Physical Activity · Intelligent Device for Sensing Physical Activity Luís Filipe Corrêa Martins Magalhães de Aguiar Dissertação para obtenção

52

If an error occurs during transmission, or the data is not coherent, the file will not be saved. o There is no answer from the server

- CODE_MSG_FILE_UPLOAD_FORMAT – Not used

- CODE_MSG_GET_RECOMMENDED_DAILY_ACTIVITY – Request the recommended daily activity

o No payload o The server returns a message with the same code, the size of

the payload is 2 bytes and the payload is one integer (16 bits) with the recommended daily activity.

- CODE_MSG_GET_LIST_OF_FILES – request the name of the files

in the directory of the ID in the header.

o No payload o Returns a string, coded by cPicke (Python’s function)

containing a list with strings with names of the files.

- CODE_MSG_GET_FILE – request a record o Payload is a string with the name of the wanted file. The file

must be in the folder of the device that is identified in the ID field on the message’s header.

o It returns the file in the payload coded by cPickle (Python’s

function).

- ERROR – indicates that an error occurred either on receiving a message either on processing a command

o No payload

- OK – indicates the success of command or message well received o No payload