We have witnessed an enormous technological advancement of cell phones within the last decade. Smartphones are now equipped with multiple sensors such as accelerometer, gyroscope, magnetometer and rotation vector.
These sensors you might use to develop complex mobile applications, which respond to smartphone rotation or analyze user’s daily activity. For creating such apps, you would need to train the neural network with a high quality dataset.
So, where do you get the dataset?
In most cases, you would need to gather data by yourself. In the recent article, we explained how to organize the process itself. In this article we are about to go through five things you have to know when collecting the data with smartphone sensors:
- How do sensors vary depending on the device model?
- What is the difference between Android and iOS sensors?
- How to do the preparation each time you’re collecting data?
- What are the challenges when gathering data?
- How to avoid common mistakes?
An accelerometer is a hardware sensor that measures the acceleration force in m/s2 and is applied to a device on all three physical axіs (x, y, and z), including the force of gravity.
A gyroscope is a hardware sensor that measures a device's rate of rotation in rad/s around each of the three physical axіs (x, y, and z).
A rotation vector is a software sensor that represents the orientation of the device as a combination of an angle and an axis, in which the device has rotated through an angle θ around an axis (x, y, or z). It uses data from the accelerometer, gyroscope and magnetometer to get the orientation of the device.
We use a game rotation vector instead of a rotation vector because it does not use the magnetic field of Earth (does not use magnetometer) and has a higher operating frequency.
A magnetometer is a hardware sensor that measures the ambient geomagnetic field for all three physical axіs (x, y, z) in μT.
Android and iOS use their own sensor framework with provided access to the different types of sensors. This framework combines hardware-based or and some are software-based sensors. Hardware-based, or hardware sensors, exists physically and are embedded into the device. Software-based or just software sensors also known as virtual or synthetic sensors receive data from one or more hardware-based sensors.
To get the high-quality dataset you need to gather more than 50k vectors for each of the sensors, and all collected data (sensor output) should fit very strict requirements:
- basic frequency level;
- no corrupted vectors;
- no null vectors;
- no duplicate vectors.
How do sensors vary depending on the device model?
All smartphone sensors have a different
- vendor (BOSCH, InventSens, STMicroelectronics or STM);
- max range;
- current, etc.
This means, that the data you gather with these sensors might vary, so you need to take this into account when you choose the basic Hz level or max value.
We found out, that there is no correlation between phone model, price or the year of manufacturing and quality of the sensors (quality = frequency of work or stability of work). For instance, the gyroscope in Nexus P6 and Nexus 5X is slower (the frequency is slower than 100 Hz) than in the Nexus 4. But consider that, in newer models, all sensors are more energy efficient.
Also, some of the cheap devices may not have an orientation sensor. During our research we found two such devices — Moto G and Huawei GT 3, both of them do not have an accelerometer sensor either.
In the following tables, you can find sensors specification for some devices from the official sources.
The most important parameters are stability during work and high frequency. In our certain instance, the frequency range should be between basic frequency level and 100 Hz. We take basic frequently level as the minimal acceptable frequency because it is the maximum stable frequency for the magnetometer. For frequencies higher than basic frequency level, we will have a lot of duplicate vectors in the magnetometer output data.
What is the difference between Android and iOS sensors?
Android and iOS use different algorithms for data preprocessing, noise cancellation and approximation.
You should also remember that different operating systems use different units of measurement. Android always uses The International System of Units (System SI) also known as the "metric system" in contradistinction to iOS, which also uses this system, however not in all cases. For instance, the iOS accelerometer uses g as an acceleration unit of measurement: the nominal value on the Earth's surface is, by definition, 9.80665 m/s.2
Another important point is that Android and iOS use different sensor naming. According to Android documentation the rotation vector sensor or game rotation vector sensor is vector which contain last three parameters of quaternion. The three elements of the rotation vector are equal to the last three components of a unit quaternion.
How to do the preparation each time you’re collecting data?
Before starting work, the following you should:
check if all required sensors are supported (or physically presented) in this certain device;
- check if the sensor characteristics meet the requirements: resolution, max range, frequency, current, etc;
- calibrate all required sensors, some of them may be not calibrated and as result they will not be ready for proper work.
What are the challenges when gathering data?
The most popular challenges when you’re collecting data with sensors would be:
- Cold start or first start problem. During the first few seconds there is a high risk of 0 values or duplicate vectors in sensor output. For example, we noticed this problem on the Nexus 5X, Nexus 4 and MI LTE.
- Duplicates and 0 values in sensor output. There is a probability of occurrence of duplicates and/or 0 vectors in sensor output for old or budget phone models. This problem is possible for all models, in those cases when sensor frequency is higher than basic.
- Hardware restriction. Phones may not have the required sensor or the required sensor may have technical restrictions, such as a magnetometer with a maximum stable work frequency of basic frequency level.
- Problem with the energy saving policy. Android power-saving features (Doze mode). Some device may have a very strict energy saving policy (jelly-pro for instance). So you should add your app to doze mode exceptions.
How to avoid common mistakes?
There are a few common mistakes, you’d better to avoid to collect accurate data without corruptions.
Do not use a linear accelerometer sensor (software sensor with excluded gravity) instead of the default accelerometer (hardware sensor with included gravity).
Do not use orientation sensitive sensors. For instance, the gyroscope is sensitive to the device orientation. To avoid this problem you should use a rotation vector sensor, which is not sensitive to device orientation.
Do not use a software rotation vector sensor which uses data from the accelerometer, gyroscope and magnetometer to get the orientation of the device instead of the game rotation vector sensor which does not use magnetometer and has higher work frequency.
As you have noticed in comparison tables above, there is some deviation when you contrast data from two diverse device models as they might be equipped with different sensors. Since the main goal is to gather accurate data, it is necessary to collect 50k vectors for each of the sensors.
Also, you should remember about most important parameters, which are stability during work and high frequency. We hope, this article turned out handy for you to analyze common problems with sensors. If you need help with data science development services like gathering data, designing algorithms, and training a neural network for your individual project, contact us!