$24
In this lab, you will work through another series of exercises to finish off your introduction to Matlab (“Matrix Laboratory”). Note: All lab exercises and the lab report should be completed in groups of 2-3, with the same people as for Lab 1 Part One.
What Is Expected From You In Lab 1 Part Two
Completion of the Prelab Exercise (1 point)
Completion of 2 more in-lab check offs with TA (2 points)
Completion of a lab report summarizing all 4 exercises (3 points)
PRE-LAB:
Read the Matlab tutorials on plotting and sound file basics (Sections Matlab Plotting Basics and Working with Sound Files in the Getting Started document) and type “help sound” in Matlab to see how the command works.
1. Specify the command that you would use to plot the first of two signals that are displayed with one over the other.
2. Explain the difference between sound(y) and sound(y,Fs)
IN-LAB:
Complete Exercises 3 and 4, referring to the tutorials on Matlab Plotting Basics and Working with Sound Files if you are stuck.
1. Lab Exercise #3: Plotting functions
In this exercise, we will learn the basics of plotting functions in Matlab. Open a new script and call it Ex3.m with the outline below:
◦ FILE: Ex3.m
◦ NAME: [FILL IN NAME HERE]
◦ DESCRIPTION: Matlab Plotting Basics
◦ Clear all variables and close all windows
clear all;
close all;
◦ PART A
◦ PART B
◦ PART C
a) For PART A: Define a signal x(t) = 2 – t over the range -2 ≤ t ≤ 4 with a sampling frequency of Fs = 5. Plot x(t) vs. t on a 1 x 2 figure window as the 1st subplot. Adjust range of x-axis to be between -5 and 5, as well as range of y-axis to be between -5 and 5. Turn on the grid and be sure to label plot and axes appropriately.
Developed by Eldridge Alcantara (Spring 2015); modified by Trang Tran & Mari Ostendorf Page 1 of 3
b) For PART B: Using the same time samples from (a), define and plot y(t) = -0.5t2 on the
2nd subplot. Adjust range of x-axis to be between -5 and 5, as well as range of y-axis to be between -5 and 5. Turn on the grid and be sure to label plot and axes appropriately.
c) For PART C: Define a signal x(t) = cos(2πt) over the range 0 ≤ t ≤ 5. Create a 3x1 subplot window and plot three versions of this signal with three different sampling frequencies of Fs=10, Fs=1, and Fs=0.5. Turn on the grid and be sure to label plot and axes appropriately. You should see that we do not get an accurate plot of x(t) for one or more cases. This shows that the selection of the sampling frequency is very important, which will be discussed in a future lab. For now, it is useful to know about this in debugging Matlab problems.
CHECKOFF #3: Demonstrate your script for Ex3.m with your Lab TA.
Lab Report Question #1 of 2 : Comment on why the cosine frequency would influence your choice of Fs. Include the 3x1 plot in your lab report.
2. Lab Exercise #4: Working with sound files
In this last exercise, we will learn how to play and plot sound files. We will use sound files that are already built into Matlab. Open a new script and call it Ex4.m with the outline below:
◦ FILE: Ex4.m
◦ NAME: [FILL IN NAME HERE]
◦ DESCRIPTION: Sound Files and Wrap-Up
◦ Clear all variables and close all windows
clear all;
close all;
◦ PART A
◦ PART B
◦ PART C
◦ PART D
a) For PART A:
i) Load sound file chirp.mat. Store y in variable chirpSound and Fs in chirpFs
ii) Load sound file gong.mat. Store y in variable gongSound and Fs in gongFs
b) In PART B:
i) Using chirpFs, compute the time samples for chirp and call that vector t_chirp
ii) Using gongFs, compute the time samples for gong and call that vector t_gong
Developed by Eldridge Alcantara (Spring 2015); modified by Trang Tran & Mari Ostendorf Page 2 of 3In PART C: Using the sound and time sample vectors from (a) and (b), plot the two sound signals on one figure window using a 2 x 1 subplot window. No need to adjust the axes or turn on the grid, but do label plot and axes appropriately.
c) In PART D: Play the two sound files in succession with a 4-second pause in between. You can use the function pause to help you do this. Type help pause on the COMMAND window for assistance on the appropriate function syntax.
CHECKOFF #4: Demonstrate your script for Ex4.m with your Lab TA.
Lab Report Question 2 of 2: Try playing the sound files with a different Fs and without specifying Fs. Comment on the effect of changing Fs in your report.
LAB REPORT:
Turn in a PDF of your lab report (one per team) online via the link on the class website. A sample format for the lab report is on the class website. You may vary from this format but please include the basic sections. The report is due prior to the start of your next lab section. Lab turn- in times will be checked, so no late lab reports will be accepted unless arranged in advance with the instructor.
Developed by Eldridge Alcantara (Spring 2015); modified by Trang Tran & Mari Ostendorf Page 3 of 3