Page 1 of 17 ENGR 102 - Data Collection and Analysis Project - Spring 2024 Background and Overview: The collection and analysis of various types of data is a basic,
yet common and critical part of science and engineering (and many other areas). As you progress through your studies in college you will be provided with data and/or will be required to collect data for labs, assignments, and other activities. There are many ways to collect data and reasons for collecting data, depending on the field and topic of research. For example, businesses gather data on consumers to predict market trends. In healthcare, data is gathered from digital medical records to help medical doctors provide a more accurate diagnosis for patients. In engineering, data from a downhole pressure sensor can tell petroleum and natural gas engineers if there may be an issue extracting hydrocarbons from a reservoir. These are just a few examples of data collection and its use, but there are countless more, including those that you will discover in your future studies and work as a professional. In this project, we will gather some of our own data using sensors that you most likely have available right now! These are the sensors in your smart phone (or tablet). Today's smart phones and tablets have multiple sensors with capabilities that we can take advantage of to collect our own data with the help of Matlab. Please download the "MATLAB Mobile" app on your phone or tablet from either the Apple App Store (iPhones/iPads) or the Google Play Store (Phones/Tablets with Android Operating Systems). If you do not have a smart phone or tablet or are unsure of how to do this, please contact your instructor. You will need to sign-in to the app using your MathWorks account that you set up for this course (using your @mix.wvu.edu email address). Please see the screenshots and instructions beginning on page 10 of this document for what the app will look like (from an Android perspective) to give you an idea of what you need to select to get ready for and perform data collection for this project. Once you have the MATLAB Mobile app set up on your phone/tablet and are ready to begin, you will need to determine what data you would like to collect. For the purposes of this project, you will have several options for the data you are collecting. Each team member must select one unique option from the following list (for each, you will start collecting data in the MATLAB Mobile app at the start of your activity and hit the stop button at the end of the activity): (1) take a ride on the PRT from the Medical Station directly (if possible*) to the Walnut Station (2) take a ride on the PRT from the Walnut Station directly (if possible*) to the Medical Station (3) take a ride on the Mountain Line (or any other) bus. Aim for ~10 minutes of data collection. (4) take a ride in a car (as a passenger, do not collect data while driving!). Aim for ~10 minutes of data collection. (5) go for a run, walk, or a bike ride around campus or where you live (please be mindful of your surroundings while collecting data!). Aim for ~10 minutes of data collection, regardless of the length of your run, walk, or bike ride. Please only use your phone and start and stop data collection when you are stopped and in a safe location. * Sometimes the PRT operates in a way that stops at all stations, instead of going directly to particular stations. If possible, choose to go directly from Walnut to Medical or vice-versa, depending upon the scenario you chose. If not possible, the all-station trips are also fine. Page 2 of 17 Important Notes: Perform the tasks presented on the following pages in a single Matlab (.m) script file. Your output should consist of two tables output to the Command Window, three plots output in three separate Figure Windows, and the text mentioned in parts (12) and (13) output to the Command Window. You must suppress all other output to the Command Window and your code must be well commented, use mnemonic variable names (this means that the variable names should make sense and make it easy to understand what each variable is used for), and your code must be easy to read/follow overall. The table may be created using either fprintf or the table command. Loops, conditional statements, and other advanced topics not yet covered in the course or in this document are not permitted in Project 1. You will be assigned to project teams of 3 to 5 members, depending on your section. Each team member will be responsible for collecting and analyzing their own unique collected data. Please select a different data collection activity from those mentioned on the previous page than the other people on your team. For this project, you will need to submit a .m file, the .mat file with your raw data, AND a published PDF file of your code. Not submitted all required files may result in significant deductions to your individual coding submission grade. To publish a PDF file of your code, ensure you have your .m file open and are in the Editor window, then go to the “Publish” tab at the top of your Matlab window, then click the down arrow, click “Edit Publishing Options", select html or whatever is next to “Output file format" and change it to or make sure it is set to “pdf", then click "Publish" at the bottom of this window to publish your .m file to a PDF file. Again, please submit all these required files to the submission link in eCampus to receive maximum credit for the individual code assignment for Project 1. If you have questions about anything you are responsible for in this project, please contact your instructor immediately. Page 3 of 17 Individual Matlab Calculations and Analysis Your individual task is to write the necessary MATLAB code to analyze the data you collected via the MATLAB Mobile app by following the steps presented below. Each team member will have the responsibility to analyze a different data set that they will independently collect. No team member will be analyzing the same data set for this project. Please see the "ENGR 102 - Project 1 Code Grading Rubric – Spring 2024" file in eCampus for how your Matlab Code will be graded for each step below. The following steps detail what you need to do to successfully complete the individual Matlab coding requirements for Project 1. All these steps must be completed using Matlab. (1) Choose one of the five scenarios from page one of this document and ensure that your scenario is different than your teammates. If you are not on-campus and are unable to ride the PRT or the Mountain Line, you may ride different routes in a car, bus, bike, or walk or run different routes. Using the MATLAB Mobile app on your phone, collect data using the guidance presented starting on page 10 of this document for one of the five scenarios presented on page one of this document. Please ensure you are stopped and in a safe location before using your phone and starting/stopping data collection. Once you have collected the data, please move to the next step. Note the time/day you collected your data. (2) Open Matlab Online by visiting matlab.mathworks.com, logging into your MathWorks account, and clicking the blue button at the top of the page to open Matlab Online. Once you are there, look at the "Files" window on the left and open the "MobileSensorData" folder. In this folder, you should see at least one .mat file corresponding to the data you recorded using the Matlab Mobile app on your phone. The file name will be in the following format: sensorlog_YearMonth Day_HourMinuteSecond.mat. .mat files are not script files and only store data in variables that you can load and use. Please ensure that the date and time match the timeframe when you recorded your data. If not, the file you are looking at may be incorrect. Next, you will need to download this .mat file to your computer if you use the desktop version of Matlab or put it in the correct location in your Matlab Drive, if using the online version of Matlab. If you are using the desktop version of Matlab to type your Project 1 code, you will need to download this .mat file to your computer. To download the file to your computer, right click on the file and then select the "Download" button. The file should automatically download to your Downloads folder (or Mac equivalent) on your computer. You will then need to move this .mat file to the location on your computer where you have or will have your Project 1 code (.m) file. If you are using Matlab Online to type your Project 1 code, right click on the file and select "Cut". Then, click on "Matlab Drive" directly above the "Files" window and navigate to where your .m Project file is or will be located. Right click in the blank space in the "Files" window in that location and click "Paste". Your .mat data file should now be in the correct location. (3) Next, you will need to load this .mat file to begin analyzing the data. This will only work if the .mat sensor log file is in your Current Folder where your .m Project 1 code file is also located. If it is not, you will see an error looks something like this "Error using load - Unable to find file or directory...” That means that you do not have the .mat file in your current folder - please move it to your current folder to fix this. To load the data into your Matlab Workspace, you will need to type a line of code similar to this in your .m Project 1 code script file near the top (after clear; clc, if you use that): load("/MATLAB Drive/Project1Code Folder/sensorlog_20990701_111523.mat") Note that this is just an example file path and yours will be different than mine. My file name is also going to different than yours. I was using Matlab Drive Matlab Online this example. Everything between the quotation marks is the file path, or where the file is located on your computer or on Matlab Online. My file happened to be in the Matlab Drive in a folder I named Page 4 of 17 Project 1 CodeFolder, and the file name was sensorlog_20990701_111523.mat. I just made up a year in the future, but yours should match the timeframe when you recorded your data in the Matlab Mobile app. (4) Now that the data is loaded into your Workspace (after running the .m file), you will notice that the data is not a standard data type we are used to seeing. If you hover over the variable named "Position", you will see that it is an XXX by 6 timetable. The XXX (number of rows) will depend on how many data points you have in your data set. There should be 6 columns, and these are your latitude, longitude, altitude, speed, course, and hacc. hacc stands for horizontal accuracy for the GPS coordinates and this varies depending on several factors that one of your team members should research for the background section of your technical report. We will need to bring this data over to a type we are more familiar with, so that we can work with it. To do this, we can use the following method to assign our data set to a new variable: Data_Set = Position{ (:, : }; You don't need to name your variable Data_Set, but you will need to give it a valid and relevant name to store all your recorded data in double (standard numeric) form. The curly brackets help us convert our data into the standard double form that we are used to and this is the data that is now stored in the variable we have created. We can now address/index this variable to help us complete subsequent steps. The data in the Position 2D array is now as follows: 1. The first column of this 2D array contains latitude data from the first time point to the last. 2. The second column contains longitude data. If you are not familiar with latitude and longitude, these two numbers are in degrees and can reference any location on Earth. 3. The third column contains altitude data. These values are in meters above sea level. 4. The fourth column contains speed data in meters per second. 5. The fifth column contains course data based on the direction you are travelling in degrees (relative to true north – degrees increase in a clockwise manner - 180 is south). 6. The sixth column contains horizontal accuracy data. This number is defined as the radius of a circle, in meters, around the latitude and longitude location for that time point. This is essentially the error for the GPS estimation of where exactly you are located at that time. (5) Next, let's plot the latitude and longitude values (vectors) on a different type of plot called a "geoplot". We will use the geoplot function. This is a new function not covered in class and information on how to use this function can be found here: https://www.mathworks.com/help/matlab/ref/geoplot.html. We will plot latitude values (on the vertical axis) versus longitude values (on the horizontal axis) on a map. Please include a title for this plot. The axes are already labeled. This plot must be in its own Figure Window. Also, please use the geobasemap function to set a custom basemap for the geoplot. You can read about how this function works here: https://www.mathworks.com/help/matlab/ref/geobasemap.html. This function should be used right after creating the geoplot and the syntax for using the function is in the following form: geobasemap basemap The word that you type in place of "basemap" will turn magenta and you can select from the options shown in the geobasemap Matlab help link above. I recommend using the satellite basemap for this project. (6) Create a new vector representing time in seconds going from 1 until the end of any of your imported vectors (the number of rows in the imported 2D array). Then, use this vector to plot the Altitude (in meters) versus time in minutes. Please fully format your plot with a title, x-axis label, and a y-axis label. This plot must be in its own Figure Window. (7) (8) (9) (10) (11) (12) (13) Page 5 of 17 Next, using the speed (velocity) vector, calculate the acceleration numerically using Matlab's diff function (https://www.mathworks.com/help/matlab/ref/diff.html). Note that the speed is given in meters per second (m/s) and the data points should be 1 second apart. The diff function takes the difference between subsequent speed values and we have a step size of 1. If we think of how we can approximate derivatives as slopes, the difference in subsequent speeds would be the rise and the difference in times would be our run. Then, we could find the slopes as rise over run. Since the run (difference in times in seconds) is 1 second, we do not need to divide to get the slope. Thus, we can simply use the diff function to find the approximate derivative for each speed. Also, calculate the cumulative position (total distance travelled) by integrating the speed vector numerically using the cumtrapz function. Read more about this method of numerically integrating here: https://www.mathworks.com/help/matlab/ref/cumtrapz.html. Do not output anything for this step. Plot the speed (velocity – in m/s) vs. time (in minutes) and the acceleration (in m/s²) vs. time (in minutes) on a single plot (a new single Figure Window for this step) that is fully formatted. This includes a title, x-axis label, y-axis label, and a legend, in this case. Note: The acceleration vector will have one less element than the speed vector due to the formula used by the diff function. Please concatenate a 0 to the start of the acceleration vector to address this and ensure all vectors have the same length. Calculate the minimum, maximum, and average altitudes in meters. Do not output anything specifically for this step. Calculate the minimum, maximum, and average speeds in m/s. Do not output anything specifically for this step. Take the results from steps (9) and (10) and create TWO tables using Matlab. One with m and m/s, and the other with ft and mph. You are welcome to use either the fprintf method of making these tables or the table function. They need to have the same general structure as the table below and must be neat and professional in appearance. Altitudes should be shown to one decimal place. Speeds must be shown to two decimal places. Altitude (m or ft) Speed (m/s or mph) Minimum Maximum Average Use an output function to type the following sentence: "While recording data, I traveled a total of XXX meters or XX.XX miles." You must use the appropriate output function that allows you to combine text and numerical values in a particular number format. You must not explicitly type the numerical values in the output text. The distance in meters must be shown as an integer. The distance in miles must be shown to two decimal places. Use one or more output functions to indicate the accuracy of the GPS data to where you actually travelled. Was it right on or was it off from where you would expect on the map? Why? Did the accuracy change along your route? Why do you think it did or did not and, if it did, does it make sense that the accuracy changed based on where you were? Please answer this question in at least 4 sentences using one or more output functions in Matlab. Please also keep the text horizontally contained. By this, I mean that you should ensure the text is wrapped and you do not need to scroll horizontally in the Command Window to read one long line of text. Use multiple \n to go to the next line if using the fprintf function or multiple functions if using disp to keep the text legible in the Command Window without the need for horizontal scrolling.