ECE2026 Lab00 2015F
ECE2026 Lab00 2015F
ECE2026 Lab00 2015F
PRINTING BUDGET: For the printers in the ECE labs, you have a quota. Please limit your printing to
essential items for the labs. If you need to print lecture slides and other large documents, use the central (OIT)
printing facilities.
1
1. Introduction
The objective of this lab is to help you regain your familiarity with MATLAB, a programming tool most
suitable for signal processing studies. All labs of ECE2026 will involve use of MATLAB in some form.
2. Pre-Lab
Please read through the information below prior to attending your lab.
2.1 Overview
MATLAB will be used extensively in all the labs. The primary goal of this lab is to familiarize a student with
using MATLAB. Please read Appendix B: Programming in MATLAB for an overview. Here are three specific
goals for this lab:
1. Learn basic MATLAB commands and syntax, including the help system.
2. Write and edit your own script files in MATLAB, and run them as commands.
3. Learn a little about advanced programming techniques for MATLAB, i.e., vectorization.
2
ans ^ 0.8118 %<--- "ans" holds the last result
g. Do variable name assignment in MATLAB. Try the following:
x = sin( 2*pi/5 );
cos( pi/4 ); %<--- assigned to what?
y = sqrt( 2.2 - x*x )
ans %<--- what value is contained in ans?
h. Complex numbers are natural in MATLAB. The basic operations are supported. Try the following:
z = -4 + 3i, w = 3 - 4j
real(z), imag(z)
abs([z,w]) %<-- Vector (or Matrix) constructor
conj(z+w)
angle(z)
exp( -j*pi )
exp(j*[ pi/2, 0, -pi/2 ])
3. Exercise
3.1 Logging into ITS (Intelligent Tutoring System)
Exercises on ITS will be integrated into homework assignments and grades this semester. The first thing
you need to do in this lab is to try to log into ITS at http://its.vip.gatech.edu . Spend some time
to familiarize yourself with ITS and its capabilities.
b. Extracting and/or inserting numbers in a vector is very easy to do. Consider the following definition of
xx:
xx = [ zeros(1,5), linspace(0,1,6), ones(1,5) ]
xx(5:8)
size(xx)
length(xx)
xx(3:2:length(xx))
Explain the results echoed from each of the last four lines of the above code.
c. Observe the result of the following two assignments:
3
yy = xx; yy(4:2:8) = exp(0.5)*(1:2:5)
Now write a statement that will take the vector xx defined in part (b) and replace the even indexed
elements (i.e., xx(2), xx(4), etc) with the constant e. Use a vector replacement, not a loop.
Record this statement on the Verification Sheet.
c. Plotting is easy in MATLAB for both real and complex numbers. (See Appendix A of the textbook).
The basic plot command will plot a vector y versus a vector x. Try the following:
x = [-2.8 -1.2 0 1.2 2.8 ];
y = x.*x - 1.8*x;
plot( x, y )
z = x + y*sqrt(-1); % a complex number consists of two parts
plot( z ) % complex values: plot real vs. imaginary
Use help arith to learn how the operation xx.*xx works when xx is a vector; compare array
multiplication (dot-star) to matrix multiplication.
d. Learn more about arithmetic in vector and matrix forms. Try the following:
x = -3:2:3;
y = x.*x + (x*x)*x;
plot( x, y )
The apostrophe means transpose of a vector, i.e., turning a row vector into a column vector and vice
versa. It of course also works for a matrix. (Note that there are more than one apostrophe-looking
symbol; make sure which one works in MATLAB.)
4
e. Use the built-in MATLAB editor to create a script file called mylab0.m containing the following
lines:
tt = -0.3 : 0.004 : 0.8;
xx = 3.* cos( 2*pi*3*tt + 1.);
plot( tt, xx, 'b-', tt, xx, 'r--' ), grid on %<--- plot a
%sinusoid
axis([tt(1) tt(end) -3 3]); %what does this do?
title('TEST PLOT of a SINUSOID')
xlabel('TIME (sec)')
Mark the value of xx on your plot when it intersects with the time axis at 0 sec.
Note: Do not save this file or any of your MATLAB files to the local hard disk. Your computer account
contains a private networked directory where you can store your own files. Use the MATLAB
command addpath() to allow MATLAB to see your personal directory (usually the Z: drive).
From the plot which should look smooth, find the values of tt at which the wave attains a peak value.
Which of these locations (values of tt) is the closest to the origin and what is the peak value? Give
your answers on the Verification Sheet.
f. Run your script from MATLAB. To run the file mylab0 that you created previously, try
Mylab0 %<---will run the commands in the file
type mylab0 %<---will type out the contents of mylab0.m
% to the screen
5
Lab #0
ECE-2026 Fall-2015
LAB SHEET
Turn this page in to your grading TA at the beginning of Lab 1
y =
Peak value = tt =
Question 1-1:
Find the sum of all even-indexed output values generated by mylab0.m.