Main Content

Sensor Data Collection with MATLAB Mobile

Overview

You can stream data from your mobile device sensors to your MATLAB® Mobile™, MATLAB Online™, or a MATLAB session on a desktop or laptop computer. MATLAB Mobile sends the data in real-time with a WiFi or cellular connection to MATLAB running in the MathWorks® Cloud. You can perform MATLAB operations on the sensor data in MATLAB, MATLAB Mobile, or MATLAB Online, which provide the MATLAB command-line interface with the ability to interact with device sensors. To connect to sensors on the device and collect data, you create a mobiledev object in MATLAB.

You can also acquire sensor data locally on your mobile device, with or without a network connection. This is an alternative method of collecting the sensor data instead of streaming it from the device to the Cloud. This is especially useful if you want to collect sensor data while your device does not have a network connection. For examples of using this method of acquisition, see Log Sensor Data Locally.

Use MATLAB to process sensor data in various ways, including creating plots. For an example of acquiring data and plotting it, see Process Logged Sensor Data.

You can also access the camera and acquire images from your mobile device in MATLAB, MATLAB Mobile, and MATLAB Online. You can set camera properties including resolution, autofocus, and flash. For an example, see Acquire Images from a Mobile Device Camera. For an example of processing acquired images, see Classify Images from Mobile Device Camera Using Pretrained Network.

Requirements for Using Sensors

To use mobile device sensors with MATLAB Mobile, make sure you have the following:

  • Installation of MATLAB Mobile on your mobile device. See Install MATLAB Mobile on Your Device.

  • To stream or upload sensor data to the MathWorks Cloud, you must have a MathWorks Account. If you do not have an account, you can set one up in MATLAB Mobile, MATLAB Online, or at Create MathWorks Account.

  • To access mobile device sensors from MATLAB on a desktop or laptop computer, you must install one of the following support packages appropriate for your device:

    • MATLAB Support Package for Apple iOS Sensors

    • MATLAB Support Package for Android® Sensors

    These support packages are available in the Add-on Explorer.

MATLAB Mobile Sensors Screen

To open the Sensors screen in MATLAB Mobile, tap Sensors on the menu.

At the top of the sensor display are the Sensor settings. See Sensor Settings.

Below the settings are the sensor displays. They are arranged in the following order, and show these measurements:

  • Microphone — Audio data, with sampling rate and recording level.

  • Acceleration — Acceleration reading in X, Y, and Z coordinates, in m/s2 (meters per second squared)

  • Magnetic Field — Magnetic field reading in X, Y, and Z coordinates, in microtesla

  • Orientation — Position reading in X, Y, and Z coordinates, in degrees, for azimuth, pitch, and roll

  • Angular Velocity — Angular velocity reading in X, Y, and Z rotations, in radians per second

  • Position — Data points representing latitude, longitude, speed, course, altitude, and horizontal accuracy. Position data is obtained from GPS, Wi-Fi®, or the cellular network, using whichever is available. The measurements indicate:

    • Latitude in degrees relative to the equator, with positive values indicating latitudes north of the equator

    • Longitude in degrees relative to the zero meridian, with positive values extending east of the meridian

    • Speed in m/s (meters per second)

    • Course in degrees relative to true north

    • Altitude in meters above sea level

    • Horizontal Accuracy in meters defined by a circle around the latitude and longitude

Tap the toggle switches to turn on and off individual sensors.

Acceleration toggle switch

When you turn on a sensor, the measurement readings begin and are displayed in each sensor's section. In this example, Acceleration and Magnetic Field are turned on.

Image showing acceleration and magnetic field enabled

Note: The microphone option does not appear on iOS devices.

After you have turned on one or more sensors, use the Start button to log data. To send the data to MATLAB on the MathWorks Cloud instead, go to the sensor settings and change the Stream to setting. See Stream Sensor Data with Mobile Device Controls.

You can also start the transmission of data from MATLAB programmatically using the Logging property of the mobiledev object. See Stream Sensor Data with MATLAB Object Properties. You must enable MATLAB programmatic access first in sensor settings.

Sensor Settings

Use the Sensors settings to manage sensor data collection on your device. The sensor settings appear before the sensor displays.

Image of sensor settings display

The options are:

  • Stream to — Select either MATLAB (in the Cloud) or Log.

  • Sensor Logs

    • View logs on MATLAB Drive — Displays a list of sensor logs uploaded to your MATLAB Drive™

    • Configure (also available via Sensors > More)

      • Sensor Access— Controls MATLAB access to the sensors. The access needs to remain on to control the sensors and data streaming from MATLAB.

      • Camera — Controls MATLAB access to the cameras. This option is available when Sensor Access is enabled, and needs to remain on to control camera input from MATLAB.

      • Acquire Data in Background (Android) — This setting is off by default, but you can turn it on to continue to send sensor data when the application goes into the background on the device.

      • Send Position Data in Background (iOS) — This setting is off by default, but you can turn it on to continue to send Position data when the application goes into the background on the device. iOS background acquisition is limited to only Position data.

      • Upload Folder — The destination folder for uploading log files. The default folder is MATLAB Drive/MobileSensorData. You can change the upload folder in this setting.

      • Auto Upload — This setting determines how data log files are uploaded to MATLAB Drive.

        • Enabled — If Auto Upload is on, and you have a network connection on your device, log files are automatically uploaded to MATLAB Drive. If Auto Upload is on and you do not currently have a network connection, the files will automatically upload the next time the device detects a network connection (WiFi or cellular, if selected).

        • Disabled — If Auto Upload is off, you must manually upload the file to your MATLAB Drive. See Transfer Sensor Logs.

    • Logs on Your Device — Displays a list of sensor logs on your device. Logs that have already been successfully uploaded to your MATLAB Drive display a successful Cloud icon . When there is a failure uploading a log file, this display shows a failure Cloud icon .

  • Sample rate — Enter the sample rate to apply to the following sensors: acceleration, magnetic field, orientation, and angular velocity.

  • Tap More to access the same options shown above in Sensors > Sensor Logs > Configure.

Device Orientation

The Acceleration, Angular Velocity, Magnetic Field, and Orientation sensors all log data in relation to the X, Y and Z axes. This diagram shows these axes relative to the device.

Image of the Acceleration, Angular Velocity, Magnetic Field, and Orientation sensors axes relative to the device

Note that the Z axis is a positive value when the device is lying face-up flat on a surface. This is by design and is consistent with MATLAB conventions. When the device lies flat on a surface, the acceleration value along the Z axis is +9.81, which corresponds to the acceleration of the device (0 m/s^2) minus the acceleration of gravity (-9.81 m/s^2).

Related Topics