George Mason University 1 Introduction 2 Pre-Lab - the GMU ECE [PDF]

Feb 13, 2017 - (c) Now use the phasor addition theorem. Carry out a phasor addition of complex amplitudes for x1(t) and

2 downloads 7 Views 209KB Size

Recommend Stories


George Mason University (PDF)
If you feel beautiful, then you are. Even if you don't, you still are. Terri Guillemets

Untitled - George Mason University
No amount of guilt can solve the past, and no amount of anxiety can change the future. Anonymous

Untitled - George Mason University
Happiness doesn't result from what we get, but from what we give. Ben Carson

George Mason University
Don't fear change. The surprise is the only way to new discoveries. Be playful! Gordana Biernat

Untitled - George Mason University
Ask yourself: What's one thing I would like to do more of and why? How can I make that happen? Next

Untitled - George Mason University
Everything in the universe is within you. Ask all from yourself. Rumi

Untitled - George Mason University
We must be willing to let go of the life we have planned, so as to have the life that is waiting for

George Mason University Microeconomics 103
We may have all come on different ships, but we're in the same boat now. M.L.King

Untitled - MARS - George Mason University
You often feel tired, not because you've done too much, but because you've done too little of what sparks

Untitled - MARS - George Mason University
The wound is the place where the Light enters you. Rumi

Idea Transcript


George Mason University ECE 201: Introduction to Signal Analysis

Spring 2017

Laboratory Project #2 Assigned: February 02, 2017 Due Date: Week of February 13, 2017 Due Date Your lab report must be submitted on blackboard by 5:00 PM on the day of your lab on the week that it is due. Late lab reports will be penalized as noted in the Lab syllabus. Lab Report Your lab report for this lab will consist of answers and complete documentation of the questions and exercises in Section 3. The pre-lab, Section 2, is designed to get you ready for the problems in Section 3. Guidelines for preparing the lab report have been discussed during the first week of lab, and the format for the report has been posted on Blackboard. If you have any questions, talk to your lab TA. For any plots that you make, make sure to label the axes and include a title for every plot. In order to keep track of plots, include your plot inline within your report. Honor Code Forgeries and plagiarism are a violation of the honor code and any reasonable suspicion of an honor code violation will be reported. You are allowed to discuss lab exercises with other students, but the submitted work should be original and it should be your own work.

1

Introduction

Before going to lab you should, at a minimum, read the pre-lab to get familiar with plotting, writing script files, and listening to sound files. As in the previous lab, you may find it helpful to read the help that is available for the MATLAB commands used in this lab. If you do not have access to MATLAB at home, or are unable to access the GMU Virtual Commuting Lab (VCL), you may read about these commands on the MATLAB web page: https://www.mathworks.com/help/matlab/ It may be difficult to complete all assignments for your lab report during the lab period if you do not come prepared. Since you will be listening to some sound files in this lab, it is recommended that you bring headphones to the lab for listening.

2

Pre-Lab

The pre-lab is designed to get you ready for the exercises that are to be completed in your lab report. In this pre-lab, you will be learning how to make plots, write MATLAB scripts, and listen to sound files. The primary goals of this lab are: 1. To learn how to write and edit your own script files in MATLAB, and run them as commands.

2. To explore more plotting capabilities, learn how to make labeled plots, and print them to a file. 3. Learn how to use the soundsc.m to listen to audio files. 4. To plot sinusoids and sums of sinusoids, and to understand how to find the frequency, phase, and amplitude of a sum of sinusoids.

2.1

The Colon Operator and Vectorization

In the first lab you were introduced to the colon operator, which is one of the most useful operators in MATLAB. One way to use this operator is to create a vector of equally spaced numeric values. For example, >> n=0:10 n = 0 1

2

3

4

5

6

7

8

9

10

creates a vector of integers from zero to ten that are stored in the variable n. To create a vector of equally spaced numbers between zero and one, in increments of 0.1, one would type >> n=0:0.1:1 n = Columns 1 through 8 0 0.1000 Columns 9 through 11 0.8000 0.9000

0.2000

0.3000

0.4000

0.5000

0.6000

0.7000

1.0000

There are other uses for the colon operator that we will learn about in later labs. (a) Experiment with vectors in MATLAB. Think of the vector as a set of numbers. Try the following: >> xk = cos( pi*(0:11)/4 );

% help plot Here we will continue exploring the plot command and see some of the other things that it can do. First, make a plot of a sinusoidal signal that is similar to the one that you created in part (b) of Section 2.1 as follows, >> >> >> >>

tdur=0.1; t=0:tdur/100:tdur; x=cos(2*pi*10*t); plot(x)

These commands will plot one period of a 10 Hz sinusoid using 101 samples of the sinusoid over the interval t = 0 to t = 0.1. This plot does not have the labels that we would like it to have. Note, for example, that the horizontal axis is indexed by n, which represents the indices of the values stored in the vector x. What we would like is to label the axes with values of time that go from t = 0 to t = 0.1. A simple way to do this is to replace plot(x) with plot(t,x) as follows, >> plot(t,x) With this syntax, values that are stored in the vector x (instead of the index) are plotted versus the values that are stored in the vector y. Some other commands that are useful in labeling plots and making them more descriptive are the following: >> >> >> >> >>

title(’Example Plot’) grid on xlabel(’t (sec)’) ylabel(’Magnitude’) legend(’10 Hz Sinusoid’)

% subplot(211), plot(current) >> subplot(212), plot(voltage) creates a plot of current in the top half of the window and voltage in the bottom half. If, instead, two side-by-side plots were desired, one would type >> subplot(121), plot(current) >> subplot(122), plot(voltage)

2.4

MATLAB Script Files

It is very useful to be able to type a sequence of MATLAB commands to execute and save them in a file so that they may be run multiple times, or so that you may edit them to change their function. These MATLAB programs, or script files, may be created by invoking the MATLAB editor, entering the commands, and then either running the script file from the editor, or saving them to a file so that they may be run from the MATLAB command line. (a) Start the built-in MATLAB editor by typing: >> edit and use the editor to create a script file containing the following lines: >> >> >> >> >> >>

tt = -1 : 0.01 : 1; xx = cos( 5*pi*tt ); zz = 1.4*exp(j*pi/2)*exp(j*5*pi*tt); plot( tt, xx, ’b-’, tt, real(zz), ’r--’ ) grid on, title(’Test plot of Sinusoid’) xlabel(’Time (sec)’)

%> A=1, f0=440, phi=0; >> mysine(A,f0,phi); where the mysine script is expecting to be passed values for the amplitude, frequency and phase of the sine function that it is to create.

(c) Explain why the plot of real(zz) that is created in the script file that you created is a sinusoid. What is its phase and amplitude? Calculate (estimate) the phase shift of the sinusoid from the plot. (d) Run your script that you created.

2.5

MATLAB Sound

The exercises in this section involve sound signals, so you should bring headphones to the lab for listening. (a) Run the MATLAB sound demo by typing xpsound at the MATLAB prompt. If you are unable to hear the sounds in the MATLAB demo then ask an instructor for help. Remember: When unsure about a command, use help. (b) Generate a tone (i.e., a sinusoid) in MATLAB and listen to it with the soundsc() command.2 Refer back to part (a) of Section 2.4 for some code that creates values of a sinusoid. The frequency of your sinusoidal tone should be 1300 Hz and its duration should be 0.9 sec. Use a sampling rate fs equal to 11025 samples/sec. Remember that the sampling rate defines the length of the interval between samples of the sinusoid, so the time-vector should be defined as follows: >> tt = 0:(1/fs):dur; where fs is the desired sampling rate and dur is the desired duration (in seconds). Read the online help for both sound() and soundsc() to get more information on using this command. What is the length of your tt vector?

3

Laboratory: Manipulating Sinusoids with MATLAB

You are now done with the pre-lab and prepared to work the following exercises that are to be written up in your lab report.

3.1

Sums of Sinusoids

Write a MATLAB script file to do steps (a) through (d) below. Include a listing of the script file in your report. (a) Generate a time vector tt to cover a range of values of time t that will span approximately two cycles of a 4000 Hz sinusoid. If we use T to denote the period of the sinusoid, define the starting time of the vector tt to be equal to −T , and the ending time as +T so that the two cycles will include t = 0. Make sure that you have at least 25 samples per period of the sinusoidal wave. In other words, when you use the colon operator to define the time vector, make the increment small enough to generate 25 samples per period. 2

The soundsc(xx,fs) function requires two arguments: the first one (xx) contains the vector of data to be played, the second argument (fs) is the rate for playing the samples. In addition, soundsc(xx,fs) does automatic scaling and then calls sound(xx,fs) to actually play the signal.

(b) Using the time vector that you created in part (a), generate two 4000 Hz sinusoids with amplitudes A1 and A2 and time delays t1 and t2 , x1 (t) = A1 cos(2π(4000)(t − t1 ))

x2 (t) = A2 cos(2π(4000)(t − t2 ))

where these amplitudes and time shifts are defined as follows. Let A1 be equal to your age and set A2 = 1.2A1 . For the time-shifts, set t1 = (37.2/M )T and t2 = −(41.3/D)T where D and M are the day and month of your birthday, and T is the period of the sinusoid. In your lab report, make sure to document the values that you used for M and D. Make a plot of both signals over the range of −T ≤ t ≤ T . Use subplot(311) and subplot(312) to make a three-panel subplot that puts these two plots in the top two panels in the figure window. (c) Create a third sinusoid that is the sum of x1 (t) and x2 (t), x3 (t) = x1 (t) + x2 (t) In MATLAB this amounts to summing the vectors that hold the values of each sinusoid. Make a plot of x3 (t) over the same range of time as used in the plots of part (b). Include this as the third panel in the plot by using subplot(313). (d) Before saving these three plots to a file, put a title on each subplot, and include your name in one of the titles. You may want to see help orient, especially orient tall.

3.2

Theoretical Calculations

Remember that the phase of a sinusoid can be calculated after measuring the time location of a positive peak,3 if we know the frequency. (a) Make measurements of the “time-location of a positive peak” and the amplitude from the plots of x1 (t) and x2 (t), and write those values for Ai and ti directly on the plots. Then calculate (by hand) the phases of the two signals, x1 (t) and x2 (t), by converting each time-shift ti to phase. Note: when doing computations, express phase angles in radians, not degrees! (b) Measure the amplitude and time-shift of x3 (t) directly from the plot and then calculate the phase φ3 by hand. In your report, show how the amplitude and time-shift were measured, and how the phase was calculated. (c) Now use the phasor addition theorem. Carry out a phasor addition of complex amplitudes for x1 (t) and x2 (t) to determine the complex amplitude for x3 (t). Use the complex amplitude for x3 (t) to verify that your previous calculations of A3 and φ3 were correct.

3

Usually we say time-delay or time-shift instead of the “time location of a positive peak.”

3.3

Complex Amplitude

(a) Write one line of MATLAB code that will generate values of the sinusoid x1 (t) above by using the complex-amplitude representation: x1 (t) =

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.