Unformatted text preview:

ECE2610: Introduction to Signals and Systems Lab 1: Introduction to MATLAB UCCS Student Name 8/4/2010ECE2610 Lab 1: Introduction to MATLAB Student Name - 1 - 08/04/10 Introduction The purpose of this lab is to provide an introduction to MATLAB. The exercises in the first two sections of the lab step through the basics of working in the MATLAB environment, including use of the help system, basic command syntax, complex numbers, array indexing, plotting, and the use of vectorization to avoid inefficient loops. The first two sections of the lab exercise are not covered in this report. The third section of the lab involves the use of MATLAB for the manipulation of sinusoids, and is the topic of this lab report. Manipulating Sinusoids with MATLAB Three sinusoidal signals have been generated in MATLAB. The signals have a frequency of 4KHz, and have been generated over a duration of two periods. The first two signals, and , are described by the following expressions (1) (2) The amplitudes and time shifts are functions of your age and date of birth as described below. (3) The time shifts are defined as (4) where is my birth month, is my birth day, and is the period of the 4KHz sinusoidal signals. The third sinusoid, , is simply the sum of and . (5) The time vector, , used to generate the signals has been generated with the following lines of MATLAB code. f = 4e3; % sinusoid freq T = 1/f; % period (250 usec) tstep = T/25; % time step t = -T:tstep:T; % time vectorECE2610 Lab 1: Introduction to MATLAB Student Name - 2 - 08/04/10 The time vector, , ranges from – , or one period prior to , to , or one period after . The time step variable, , controls the number of samples that are generated per period of the signal, in this case 25 points per period. The signals defined by equations (1), (2), and (5) are plotted in Figure 1. Figure 1. Plots of the three sinusoidal signals generated in MATLAB. Theoretical Calculations The amplitudes and time shifts of the three sinusoids have been measured and annotated on the plot shown in Figure 2. The time shift values, , can be used to calculate the phase of each signal as follows. (6) (7) Rewriting the expressions for and using the phase values calculated in (6) and (7) yields (8) (9)ECE2610 Lab 1: Introduction to MATLAB Student Name - 3 - 08/04/10 Figure 2. The three sinusoids with the amplitude and time shift of each annotated on the plot. Also shown in Figure 2 are the amplitude and time shift values for . These values were measured directly from the Figure 2 plot as and , respectively. The time shift value can be used to calculate the phase of as follows. (10) As an alternative to measuring the amplitude and phase of graphically, the phasor addition theorem can be used to calculate these values. Expressed in complex exponential form, the first two sinusoids are (11) (12) The third sinusoid, , can then be expressed as the sum of (11) and (12). (13)ECE2610 Lab 1: Introduction to MATLAB Student Name - 4 - 08/04/10 Substituting in values for , , , and , and solving for and yields (14) The calculated amplitude and phase values of and given in (14) agree very closely with the values obtained through graphical measurement. The phase values differ slightly due to the difficulty of identifying the exact time of the signal peak from the graph. Representation of Sinusoids with Complex Exponentials Signals can alternatively be generated in MATLAB by using the complex amplitude representation. For example, the expression for given in (11) can be used to generate the signal in MATLAB as shown in the following code segment. A1 = 36; % amplitude phi1 = -1.975; % phase in radians x1 = real(A1*exp(1j*phi1).*exp(1j*2*pi*4000*t)); The signal resulting from these lines of code is plotted in Figure 3. Comparing Figure 3 to the top strip in Figure 1 clearly shows that generated using the complex amplitude representation is equivalent to generated using the real-valued cosine function. Figure 3. Sinusoidal signal, , generated using the complex amplitude representation. Conclusion This lab exercise has provided an introduction to the fundamentals of MATLAB. The third section of this lab, which has been detailed in this report, explored the use of MATLAB to generate sinusoidal signals. Three sinusoidal signals have been generated in MATLAB, the third of which was a sum of the other two. The phasor addition theorem has been employed to calculate the resulting amplitude and phase of theECE2610 Lab 1: Introduction to MATLAB Student Name - 5 - 08/04/10 summed signal. Additionally, it has been demonstrated that sinusoids can be equivalently generated in MATLAB using the complex exponential representation for those signals.ECE2610 Lab 1: Introduction to MATLAB Student Name - 6 - 08/04/10 Appendix A: MATLAB Code % lab1_3.m % ECE2610 % Lab 1 % Kyle Webb % 8/4/10 clear all f = 4e3; % sinusoid freq T = 1/f; % period (250 usec) tstep = T/25; % time step t = -T:tstep:T; % time vector A1 = 36; % amplitude of x1 (age) A2 = 1.2*A1; % amplitude of x2 M = 7; % birth month D = 17; % day of birth tm1 = (37.2/M)*T; % time shift for x1 tm2 = -(41.3/D)*T; % time shift for x2 % generate the sinusoidal signals x1 = A1*cos(2*pi*f*(t-tm1)); x2 = A2*cos(2*pi*f*(t-tm2)); x3 = x1 + x2; A1t = A1*ones(1,length(t)); A2t = A2*ones(1,length(t)); % calculate time shifts for x1 and x2 by subtracting excess periods % from tm1 and tm2 ts1 = tm1-5*T; ts2 = tm2+2*T; % calculate phase (in radians) from the time shifts phi1 = -ts1/T*2*pi; phi2 = -ts2/T*2*pi; % and in degrees phi1_deg = phi1*180/pi; phi2_deg = phi2*180/pi; % calculate the amplitude and


View Full Document

UCCS ECE 2610 - Introduction to MATLAB

Download Introduction to MATLAB
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to MATLAB and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to MATLAB 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?