Matlab Track GPS
Matlab Track GPS
MATLAB Mobile
Posted by Alexa Sanchez, June 24, 2020
Are you looking for something fun to try using MATLAB? Did you know you can use MATLAB
Mobile and MATLAB Online to create your own fitness tracker? If you want to learn more you
can download the code here.
Smartphones have sophisticated sensor suites onboard, including GPS, accelerometers, gyroscopes,
etc. You can use this sensor data along with an algorithm or a mathematical model to extract metrics like
calories burned, steps taken, or flights climbed, to inform someone about how effective their workout
was. Your task is not only to figure out what metrics you want to extract but also the algorithm or
mathematical model to help you transform the raw sensor data into your desired metrics.
Acceleration (m/s^2)
GPS Position
o Latitude (degrees)
o Longitude (degrees)
Speed (m/s)
Altitude (m)
Course/Heading (degrees)
Horizontal Accuracy (m)
Orientation (degrees)
Angular Velocity (rad/s)
To find out more about these sensors check out this documentation page.
4. Research Fitness Models
The fitness model is the computational portion of your tracker; this algorithm will accept data from the
sensors you choose, then compute and return the metrics you desire. The challenge here is
understanding the mathematical operations needed to transform the raw sensor data you selected for the
tracker into meaningful metrics. If you have downloaded the code from
GitHub, ExampleModel.mlx contains a sample fitness tracker model to inspire you.
When recording data to build the model other than identifying the correct sensor data to use, you must
also ensure that you have a variety of activity data to represent the anticipated activities, for e.g. if you
only test your model on data collected while walking, your model will not be robust enough to track and
reward more strenuous activities like running or cycling. If you want a robust model, you must account for
as many activities as possible and collect the data appropriately. To record sensor data, use the
MATLAB Mobile app:
1. Navigate to the “Sensors” screen by clicking on the three-lined icon on the top left
2. Set the Stream to field to Log – This will log sensor data to a MAT-file and save it to your MATLAB
Drive in a folder named ‘MobileSensorData’
3. Select the sensors you wish to log data from
4. Click Start to begin logging data and MOVE!!
5. Click Stop to save the log to MATLAB Drive – Use the ‘Acquire Data in Background’ option in Sensor
Settings to record data while your phone is locked
Android:
Iphone:
Accessing the Data
When working with MATLAB Online, MATLAB Drive can be accessed from the left-hand plane labeled
‘CURRENT FOLDER’ as shown below.
Any logged sensor data is stored in the MobileSensorData folder in your MATLAB Drive; to load the data,
double click on the appropriate MAT-file in that folder or use the following command:
>> Position.Properties
There are two dimensions held in the Position timetable: Variables –> the sensor data collected
and Timestamp –> the date and time of the corresponding sensor sample.
Use the parenthesis notation as shown below to access a specific range of sensor data as shown below.
The second timetable dimension –> Timestamp contains the year, month, day, hour all the way down to
the millisecond at which that sample was taken; use the following command to access the timestamp
information.
and calculate the distance between them. This works well when the distance covered is over a straight
line. What happens when the path taken to get from start to end is not a straight line? Consider the
following scenario:
Using this equation the distance traveled would be 300ft for this scenario because the start and end
position is 3 squares apart whereas in reality the person traveled much further. To counter this, use the
model along every point on the path traveled or every sampled GPS point and add the distance between
these points to calculate the total distance traveled so you must calculate the distance along the path
using each data point. Now we get a distance traveled of 1500ft which is significantly different.
Remember my recommendation to collect data or diverse situations?
Latitude and Longitude data from the GPS sensor is in degrees, so the distance between latitude and
longitude points as calculated from a GPS sensor is actually degreesTravelled; to convert this
to distanceTravelled in feet, use the following relationship:
The MATLAB implementation of this model is shown below.
%% Initialize Variables
%% Processing Loop
steps = totaldis_ft/stride;
MATLAB to explore the world of wearable technology. A group of students from Franklin High School in
Massachusetts, designed a fitness tracker using the full cellphone sensor suite to calculate distance
traveled, flights of stairs climbed, and calories burned. Post your files on MATLAB Central’s File
Exchange or GitHub and send us a link to your repository! We would love to see what you are able to
achieve!