SMART MOVEMENT DETECTION for ANDROID PHONES a Degree Thesis Submitted to the Faculty of the Escola Tècnica D'enginyeria De Tele
Total Page:16
File Type:pdf, Size:1020Kb
SMART MOVEMENT DETECTION FOR ANDROID PHONES A Degree Thesis Submitted to the Faculty of the Escola Tècnica d'Enginyeria de Telecomunicació de Barcelona Universitat Politècnica de Catalunya by Pablo Navarro Morales In partial fulfilment of the requirements for the degree in TELECOMMUNICATION ENGINEERING Advisor: Sergio Bermejo Barcelona, October 2016 Abstract This project describes a decision tree based pedometer algorithm and its implementation on Android using machine learning techniques. The pedometer can count steps accurately and It can discard irrelevant motion. The overall classification accuracy is 89.4%. Accelerometer, gyroscope and magnetic field sensors are used in the device. When user puts his smartphone into the pocket, the pedometer can automatically count steps. A filter is used to map the acceleration from mobile phone’s reference frame to the direction of gravity. As a result of this project, an android application has been developed that, using the built-in sensors to measure motion and orientation, implements a decision tree based algorithm for counting steps. 2 Resumen Este proyecto describe un algoritmo para un podómetro basado en un árbol de decisiones y su aplicación en Android utilizando técnicas de aprendizaje automático. El podómetro puede contar los pasos con precisión y se puede descartar el movimiento irrelevante. La precisión de la clasificación general es del 89,4%. Un acelerómetro, un giroscopio y un sensor de campo magnético se utilizan en el dispositivo. Cuando el usuario pone su teléfono en el bolsillo, el podómetro puede contar automáticamente pasos. Un filtro se utiliza para asignar la aceleración del sistema de referencia de teléfono móvil a la dirección de la gravedad. Como resultado de este proyecto, la aplicación para Android que se ha desarrollado, utilizando los sensores incorporados para medir el movimiento y orientación, implementa un algoritmo basado árbol de decisión para contar los pasos. 3 Contents Abstract .. 2 …………………………………………………………………………………… Resumen .... 3 ………………………………………………………………………………… Contents . 4 …………………………………………………………………………………… List of Figures . 6 ……………………………………………………………………………… 1. Introduction .. 7 ……………………………………………………………………… 2. Background .... 8 ……………………………………………………………………… 2.1. Introduction ....... 8 …………………………………………………………… 2.2. Hardware .... 8 ………………………………………………………………… 2.3. Technology . 9 ………………………………………………………………… 2.3.1. Accuracy .. 9 …………………………………………………………… 2.3.2. Integration in personal devices .. 10 …………………………………… 3. System Structure ... 12 ………………………………………………………………… 3.1. Collection data .... 12 …………………………………………………………… 3.2. Acceleration mapping .... 13 …………………………………………………… 3.3. Processing the signal .. 13 ……………………………………………………… 3.4. Feature extraction .. 13 ………………………………………………………… 3.5. Decision making . 14 …………………………………………………………… 4. Sensors ... 15 …………………………………………………………………………… 4.1. Sensors Framework 15 ………………………………………………………… 4.2. Driver architecture . 15 ………………………………………………………… 4.2.1. SDK . 16 ………………………………………………………………… 4.2.2. Framework . 16 ………………………………………………………… 4.2.3. HAL . 17 ………………………………………………………………… 4.2.4. Kernel Driver ... 17 ……………………………………………………… 4.2.5. Sensor Hub . 17 ………………………………………………………… 4.2.6. Sensors .... 18 …………………………………………………………… 4.3. Sensors coordinate system . 18 ………………………………………………… 4.3.1. World coordinate system ... 18 ………………………………………… 4.3.2. Local coordinate system . 19 …………………………………………… 4.3.3. Other coordinate system ... 20 ………………………………………… 4.4. Sensors Offset . 20 ……………………………………………………………… 4.5. Sensors Noise . 21 ……………………………………………………………… 4.6. Position Sensors . 22 …………………………………………………………… 4.7. Computing the devices acceleration . 23 ……………………………………… 5. Accelerometer ... 24 …………………………………………………………………… 4 5.1. Introduction ... 24 ……………………………………………………………… 5.2. Implementation .. 25 …………………………………………………………… 5.3. Caveats ... 26 …………………………………………………………………… 5.4. Sensors code .. 26 ……………………………………………………………… 6. Gyroscope .. 27 ………………………………………………………………………… 6.1. Introduction ... 27 ……………………………………………………………… 6.2. Implementation . 27 …………………………………………………………… 6.3. Caveats ... 28 …………………………………………………………………… 6.4. Calibrated versus uncalibrated ... 28 …………………………………………… 7. Acceleration mapping ... 29 …………………………………………………………… 7.1. Introduction ... 29 ……………………………………………………………… 7.2. Linear acceleration . 29 ………………………………………………………… 7.3. Vertical acceleration .. 30 ……………………………………………………… 7.4. Complementary filter . 31 ……………………………………………………… 7.4.1. Orientation Angles filter . 32 …………………………………………… 8. Gait analysis .. 36 ……………………………………………………………………… 8.1. Mobile positioning . 36 ………………………………………………………… 8.2. Pattern recognition . 36 ………………………………………………………… 8.3. Walking and running .. 37 ……………………………………………………… 8.4. Downstair versus upstairs .. 40 ………………………………………………… 8.4.1. Location of the maximum .. 40 ………………………………………… 8.4.2. Variance of the signal . 40 ……………………………………………… 9. Processing the signal . 41 ……………………………………………………………… 9.1. Data segmentation algorithm . 41 ……………………………………………… 9.2. Feature extraction .. 42 ………………………………………………………… 9.3. Classification .. 42 ……………………………………………………………… 10. Results .... 44 …………………………………………………………………………… 11. Conclusion . 45 ………………………………………………………………………… 12. Bibliography ... 46 ……………………………………………………………………… 13. Annex . 48 ……………………………………………………………………………… 13.1. Android development .... 48 …………………………………………………… 13.2. Filter java Implementation . 57 ………………………………………………… 13.3. Weka training set 59 …………………………………………………………… 5 List of figures 1. Mobile phone in user pocket . 7 ……………………………………………………… 2. Sensors included on an Intel Soc . 9 ………………………………………………… 3. System chart of the pedometer . 12 …………………………………………………… 4. Layers of the Android sensors stack ... 16 ……………………………………………… 5. Universal coordinate system .. 19 ……………………………………………………… 6. Local coordinate system . 19 …………………………………………………………… 7. Other coordinate system .... 20 ………………………………………………………… 8. Acceleration data over time .. 21 ……………………………………………………… 9. Android accelerometer spec .. 21 ……………………………………………………… 10. Android testing results ... 22 …………………………………………………………… 11. Acceleration data over time ... 24 ……………………………………………………… 12. Acceleration data on each Axis .. 25 …………………………………………………… 13. Angular velocity over time . 27 ………………………………………………………… 14. Linear acceleration data over time . 29 ………………………………………………… 15. Linear acceleration vs raw acceleration . 30 …………………………………………… 16. Filter scheme .. 33 ……………………………………………………………………… 17. Intermediate filter signals .. 34 ………………………………………………………… 18. Annotated Graph 35 …………………………………………………………………… 19. Axis of the gyroscope . 36 ……………………………………………………………… 20. Walking stages .... 37 …………………………………………………………………… 21. FFT walking . 38 ………………………………………………………………………… 22. FFT Running 38 ………………………………………………………………………… 23. Decision Boundary . 39 ………………………………………………………………… 24. Decision Scheme . 39 …………………………………………………………………… 25. Signals of walking ... 41 ………………………………………………………………… 26. Weka decision tree . 43 ………………………………………………………………… 27. Table of results .... 44 …………………………………………………………………… 28. Smart pedometer project files ... 49 …………………………………………………… 29. Smart pedometer manifest file .. 50 …………………………………………………… 30. Android Activity lifecycle .... 51 ………………………………………………………… 31. Smart pedometer lifecycle . 52 ………………………………………………………… 32. Registering sensors . 53 ………………………………………………………………… 33. Sensors callback listener ... 54 ………………………………………………………… 34. Rotation vector from gyro . 57 ………………………………………………………… 35. Linear acceleration components .. 58 ………………………………………………… 36. Weka training set ... 59 ………………………………………………………………… 6 1 - Introduction Commonly used pedometers are often built as separate products and their accuracy is typically affected by random motions. In this project, we present a method to count steps of walking using a mobile phone. We use several sensors to extract signal features and a decision tree to perform data classification. Gyroscopes and accelerometers are widely used to detect human motions [1]. Gyroscope sensor is used to measure the angular velocity of an object. The work presented here uses gyroscope to measure angular velocity of user’s thigh, when the phone is in the user’s pocket shown in Figure 1. The accelerometer can be used as a sensor to measure the acceleration of an object [2]. The magnetic field sensor is often used in global positioning system navigation. In this work, data from this sensor are used to generate a rotation matrix. Using the matrix and the original acceleration, the vertical acceleration can be determined. Decision tree is one of the predictive modeling approaches used in statistics, data mining and machine learning. In a decision tree [3], leaves represent target values, which are also called class labels, and branches represent measurements about an item, which is also called a feature. Figure 1. Mobile phone in user pocket. 7 2 - Background 2.1 - Introduction Pedometers, now popular as an everyday exercise progress monitor and motivator, can encourage individuals to compete with themselves in getting fit and losing weight. Early designs used a weighted mechanical switch to detect steps, plus a simple counter. When these devices are shaken, one can hear a metal ball sliding back and forth, or a pendulum striking stops as it swings. Today, advanced pedometers rely on microelectromechanical systems (MEMS) inertial sensors and sophisticated software to detect true steps with high probability; MEMS inertial sensors permit more accurate detection of steps and fewer false positives. Taking advantage of the low cost and minimal space- and power requirements of MEMS inertial