Practice Top-Down Program Design, Problem Solving in C
Work with arrays and functions defined on arrays
Investigate moving averages and their effect on data
Creating a New Folder
Create a new folder named lab7 in your cpre185labs folder on the U: drive. You will want to copy over ds4rd.exe to the lab7 folder.
When dealing with real-time data sources such as the DualShock 4, it is common to want to smooth out rough data. One way to do that is to apply a moving average to the data. In this lab, we will develop a program that reads from ds4rd.exe the x, y, and z values from the gyroscope and computes moving averages on the data in real time.
A moving average of length n computes the average of the last n inputs. For instance, a moving average of length 2 of (1, 3 , 5, 6,3) is (2, 4, 5.5, 4.5). A moving average of length 3 of the same data would be (3, 4.666, 4.666). Note that the moving average has to accumulate n inputs before it can output something.
For this lab, start with the source code linked above. Write a program that reads from ds4rd.exe (document your command line options that you use when running ds4rd.exe) and outputs the given x, y, and z gyroscope values followed by the moving averages of x, y, and z. It should also output the maximum and minimum values from the array used to compute the averages, which are calculated in a maxmin function. The output should be all on one line and separated by commas.
The length of the moving average shall be given on the command line to your program (code is included in the sample to help you read this input). Once
Save your output for three different motions of 5-10 seconds each to a sample data file. You will use the “> file” trick. Then, you will use this data to examine the 2 different moving average lengths. We are asking you to collect the sample data so that you can more easily compare the short vs. the long window lengths.
Motion 1: DualShock 4 lying on the table still. (short window length 20 and long window length 100)
Motion 2: A very fast repetitive rocking motion (short window length 20, and long window length 100)
Motion 3: A slow repetitive motion of your choosing (document it in your report.)
(short window length 20, and long window length 100)
Use a spreadsheet to graph the short and long window lengths. Label the data. You will turn in three graphs, one for each axis(X,Y, Z) with the three motions labeled (i.e. one graph will be for the X-axis and only contains the X-axis data for all three motions, one graph will be for the Y-axis and only contains the Y-axis data for all three motions, one graph will be for the Z-axis and only contains the
Z-axis data for all three motions.) Compare the short window length data to the longer window length data and the raw data on each. Describe at least 2 things about the graphs that seem to happen when window lengths get longer. Why?
What happens in comparing Motion 2’s data graph and Motion 3’s data graph? Would you be more likely to use a short window length or long window length for each of these? Explain your reasoning.
Your lab report including answers to the all questions, the graphs above, and all your source code that has been checked by your undergraduate TA.