Lab 3 - Processing and Analyzing Data (1)

.pdf

School

Oregon State University, Corvallis *

*We aren’t endorsed by this school

Course

351

Subject

Mechanical Engineering

Date

Dec 6, 2023

Type

pdf

Pages

10

Uploaded by SuperRose6727

Report
Page 1 of 10 Lab 3 - Processing and Analyzing Data ME 351 - Introduction to Instrumentation and Measurement Systems Lab Days: 2 What we’ll learn: How to do frequency analysis MATLAB FFT package How to filter data Moving average filter (software low-pass filter) MATLAB low-pass and high-pass Signoffs Email all signoff videos to: lab_3_s.8rz5dzg2xv47xnkb@u.box.com Part 1: Finding Trends in Data Before, we’ve extracted raw data from sensors. But oftentimes, we’re more interested in trends than each data point. For instance, data may be regularly repeating, and we may want to know how frequently it repeats. We can try to do so by determining how many times it peaks during a set time. Tasks 1. Open your MATLAB plotting script for your photocell data from Lab 2. 2. Write a program using the findpeaks() function built into MATLAB ( mathworks.com/help/signal/ref/findpeaks.html ) that counts the number of times your data “peaks”, or has a high po int. a. Note: You do not need to use the additional options (e.g “MinPeakDistance”). The most basic version of findpeaks() is fine. 3. Plot the position of the peaks your program identified (using the scatter() function) along with your raw data (using the plot() function). 4. Find and record the average frequency of the strobe light used in the last lab according to your program. a. Using the [pks, locs] results from findpeaks() helps with this.
Page 2 of 10 Discussion Question 1 Does the most basic version of findpeaks() tend to overestimate or underestimate the frequency of the signal (the trend in the data)? Why do you think this is? Tasks, Continued Another way to find trends is to analyze data to try to approximate it as waves and see if they fit well - this is called frequency analysis, and we can do it in MATLAB using fast Fourier transforms, or fft() ( mathworks.com/help/matlab/ref/fft.html ). 5. Go to the MATLAB help page for the fast Fourier transform function. 6. Using the “Noisy Signal” example, analyze your own photocell data with fft() . a. Keep in mind that the example generates data for analysis while we already have data to analyze. Make sure you are running the analysis on your own data! b. The initial parameters must also be changed to fit our data. You can determine the real sampling frequency (Fs) by finding the average sampling period (difference between timestamps) and dividing 1 by it. Remember to convert the period from milliseconds to seconds first. i. Note: Sampling frequency (Fs) is not a time difference. It is a frequency with units of Hz. If your FFT plot looks strange, the first place you should check to debug is your value for Fs. 7. Plot the single-sided spectrum analysis (P1) with respect to frequency in Hz. 8. Change the x-axis limits of your plot if necessary to ensure the frequency value associated with the peak is obvious to those looking at your graph. 9. Find and record the frequency of the light according to the FFT analysis. 10. Combine your peak-finding graph and your FFT graph as subplots in the same MATLAB figure ( mathworks.com/help/matlab/ref/subplot.html ). 11. Show your figure to a teacher for sign-off 1. 12. Alternatively, save your figure and submit it via email for sign-off 1. a. DO NOT take a screenshot of the figure. Save the plot programmatically with print or saveas , or, in the figure window, use [File] → [Save as]. b. Save the file as an .jpg, .jpeg., .png, or .pdf file and title it Firstname_Lastname-L3- S3”. The file must be smaller than 25 MB. c. Email the file to the box account above. You should receive a confirmation email that the file was uploaded successfully.
Page 3 of 10 13. Make a copy of your MATLAB code for your lab report. Discussion Question 2 Include the plot of your most basic version of findpeaks() and your fft() plot generated in the above tasks. What frequencies did you find for peak-finding and for FFT? How do your frequencies compare between peak-finding and FFT? If they are different, which one do you think is more accurate and why? You may find it helpful to do some simple visual analysis of your data. Keep in mind the formatting instructions on the template for figures. Discussion Question 3 In your FFT plot, you might see that there is a large peak at 0Hz. What does this peak represent? Hint: If a wave has a frequency of 0, does it oscillate or is it constant? Part 2: Filtering A Noisy Sensor Filtering is particularly helpful for noisy sensors. One very common noisy sensor is an inertial measurement unit (IMU) - a sensor that can measure some aspects of the motion it’s experiencing. Since our kits don’t come with an IMU, we have provided noisy data from an IMU on Canvas. We’re using the MPU -6050, an often-used IMU with an accelerometer and gyroscope in it. Because of its popularity, there are several guides and libraries for its use. If you need to get your own sensors for a project in the future, be sure to search for guides and libraries before you buy! Planning ahead like this can save you quite a lot of headache. Tasks 1. Go to this Adafruit MPU-6050 guide to learn about the sensor used to collect this data: learn.adafruit.com/mpu6050-6-dof-accelerometer-and-gyro/overview 2. Watch this video to learn how an accelerometer works: youtu.be/KZVgKu6v808 Discussion Question 4 How does a 1-axis accelerometer work? How might an accelerometer measure in 3 axes? How many axes does the MPU-6050 measure in? Tasks, Continued Noise can confuse our analyses, since they have to separate the real data (signal) from the random errors in the data (noise). The more random error, the noisier the data is. We can alleviate the effects of noise by filtering the data before we analyze it. One of the
Page 4 of 10 easiest ways to do so is to add a real-time moving average filter. Real-time filters are also useful for when your system acts on incoming data and is sensitive to noise. If you want your system to behave appropriately, you will often have to implement real-time filtering to avoid acting on noise, rather than the intended signal. An Arduino example for a real-time moving average filter can be found by going to your Arduino IDE and opening [File] → [Examples] → [03.Analog] → [Smoothing]. You can use this to smooth noisy data from any sensor you can read data from (keep in mind for final project). Since you do not have access to an IMU for the Arduino, we will not be using a real-time moving average filter. Instead, you will clean the data in post-processing by using pre- recorded data and running a moving average filter on it in MATLAB. The recorded data is from flipping the IMU around the Z-axis in time with a metronome set to 90 BPM ( https://youtu.be/I7mFvUl9HjA ). Tasks 1. Download the pre- recorded IMU data “imu_flipping_data.csv” from Canvas. a. The first column is time in milliseconds and the second column is the acceleration read by the z-axis accelerometer. 2. Download th e starter code “moving_avg_filter_starter_code.m from Canvas. 3. Read carefully through the provided code to understand how a moving average filter works. 4. To compare the effects of window size on our data, filter the raw data with window sizes 10, 50, and 100. 5. Plot your filtered signal at each window size on a single subplot (raw, 10, 50, 100). Run an FFT analysis on each set of data (4 in total), and plot each individual FFT analysis as a subplot under the combined plot of raw and filtered data. (The result should be five vertically stacked subplots.) a. Note: If your FFT plots don’t look right, make sure you convert from milliseconds to seconds and that your Fs value is appropriate. 6. Show your figure to a teacher for sign-off 2. 7. Alternatively, save your figure and submit it via email for sign-off 2. a. DO NOT take a screenshot of the figure. Save the plot programmatically with print or saveas , or, in the figure window, use [File] → [Save as].
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help