Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ENGR 131: Elementary Computer Programming

Lab Exercise #8

INSTRUCTIONS

Complete the exercises below and upload them to Canvas as a single file containing your MATLAB .m file      using the naming convention “ENGR131_22F_Lab##_abc123.m”, replacing abc123 with your Case ID, and ## with the two-digit lab number.

For example, if Dr. Williams were submitting Lab 6 it would be ENGR131_22F_Lab08_mrw8.m

For your script, please perform the following:

1.   You may use the code and notes from class, the textbook, lecture videos, MATLAB’s documentation, and anything you find using Google to solve these problems.

2.   Use comments as appropriate to indicate your thoughts and how your code works (or is supposed to work). This is 5 points (10%) of your grade.

QUESTIONS

There are three questions for this lab.  The first question has 4 parts.  Please break out each part into its own section for ease of review.   For questions 2 and 3, place these in their own sections.

1. CLEANING A REAL-WORLD SIGNAL(35 PTS)

You’ve  just  recorded  a  biosignal,  but unfortunately   someone  was  running   a motor in the lab throwing off all sorts of interference   such   that   your   signal   is corrupted with a massive amount of noise as shown in Fig 1. This is really important and you don’t have the opportunity to re- record it, so you’re going to have to clean it up and figure out what it is from what

Fig 1. Your really important, noisy signal you have.


A. Display and review the signal (5 pts, 1 pts each)

i.   Load the data file Lab8Data.  This will load a structure that includes the time each sample was recorded as well as the amplitude.

ii. Plot this raw signal as a subplot with appropriate title and labels

iii. Since this is real data and you have the recording times, find the times between each sample

iv. Plot the histogram of the time differences between samples as a second subplot.

v.  Compute the average time between samples.  Does this match with your histogram?

B. Analyzing the Frequency Content (5 pts, 2.5 pts each)

You know there’s noise, but you can’t do much about it until you know what frequency it’s at.  Take a look by completing the following steps:

i.  Compute the Fourier transform of the corrupted signal using your estimated dt from part A.

ii. Plot the Fourier transform with appropriate title and labels.  Make a note of the larger spikes these are the dominant frequencies of the signal.

C. Display Spectrogram (10 pts)

The time domain analysis of the corrupted signal doesn’t show much. You should see something in the frequency domain.  Create a spectrogram using the following steps to see if there are any time varying components to the signal.

i.  Create a vector of frequencies from 0 to half the sampling frequency (2 pts).

ii. Compute the spectrogram using a window width that is a power of 2 (16, 32, 62 etc.) and an overlap of 80% of the window width (hint: the overlap needs to be an integer).  You may have to try a few window widths to find the best one (2 pts).

a. Keep in mind the relative samplingfrequency signals sampledfaster (like audio at in the 1000’s of Hz range) use wider windows than signals sampled more slowly (like this one in the 10’s of Hz range).

iii. Plot the spectrogram with appropriate title and labels.  Can you identify the frequency of the noise?  Does it match what you saw in the Fourier transform plot?  Use the disp command to answer these questions to command window (6 pts)

D. Filter the Signal (15 pts)

OK, now you’ve identified the frequency of the noise, it’s time to clean it up. Thing is, you’re not sure how much cleaning you should do.  You don’t want to over-filter it, but you also need to be able to identify the signal you recorded.  Try a range of filter orders by following these steps.

i.  You’ll be looking over five different filter orders.  For comparison, plot the raw signal in the first of 6 subplots. (3 pts)

a.   For close examination, set your x axis limits to 0.5 to 5 s.

ii. Use a loop to (10 pts):

a.   Compute the parameters  for the  appropriate type  of Butterworth  filter using  a  single  cutoff frequency for all iterations.   The exact frequency is up to you, but it should be away from the “legitimate”  frequencies  of your  signal, but well  enough before your noise  so that  it’s well attenuated.

b.   Iterate the order of the filter from 1 to 5.

c.   Plot the filtered signal with appropriate title (including the order in the title) and axis labels as separate subplots.

i.   For close examination, set your x axis limits to 0.5 to 5 s.

iii. Identify the signal. Use the disp command to send a message to the workspace with you guess as to what the biosignal recorded (hint: it’s regular and follows the frequency shown when someone is at rest). (2 pts)

2. MAKE CASE GREENER (6 PTS)

Case is all about improving their environmental footprint.   In order to illustrate Case’s commitment to this, download the logo from Canvas and use Matlab to revise it to be green instead of blue. Hint: check what kind of image it is and swap matrices as needed.

3. FIND THE HIDDEN MESSAGE (4 PTS)

An important message has been recorded in the file Lab8Q3MSG.wav on Canvas, but someone botched the sampling rate when they saved it.  Play the signal and find the best sampling frequency to play it back at in order to determine the message.  Use the disp function to write this message to the workspace.