Professional Documents
Culture Documents
Experiment #3
Experiment #3
3
COMPLEX NUMBERS
OBJECTIVE:
INTRODUCTION:
As you work through the problems and experiments in this course, you will be using MATLAB -
a powerful computing environment for numeric computation and visualization - quite frequently.
MATLAB is designed for ease of use and behaves as a high-level programming language that is
tailored for signal processing, communication, and control tasks. It is used by professionals in
industry and academia worldwide in research, development, and design. An open source
program having very similar capabilities and commands is also available called Octave.
MATLAB, short for MATrix LABoratory, works on matrices of numbers. We focus mostly on
one-dimensional matrices called vectors that contain signal samples, or on multiple-dimensional
matrices containing several signals or the parameters of a system. For example, a vector could
contain just a list of values from a mathematical function that you wish to plot. We will first
focus on familiarizing you with the matrix notation in MATLAB, and get you used to working
with vectors and matrices in arithmetic operations. This introduction has three parts: reading,
reading while doing, and doing guided by knowing expected results. Since the main difficulties
in learning MATLAB are in learning the syntax and (in some cases) learning to program, we
hope that this format will remove some of the trauma. Solutions to the questions in the “Quiz”
section should be handed in as part of your Lab 1 report. This introduction is not intended to
present you with everything you need to know about MATLAB; it is merely to bring you to a
point where you can do the following labs in the course. Use the on-line help, and references for
additional information. You should follow this text with MATLAB running, and work through
the examples and questions. MATLAB is available on PCs, DEC workstations, Sun
workstations, and many other platforms. MATLAB runs under Microsoft Windows, X Windows,
or Mac OS. All versions of MATLAB are compatible in file storage format and M-file format, so
data stored on one system can be transferred to another without loss. Each MATLAB session has
at least two windows: a text window, where commands are typed and data is displayed, and a
graphics window, where graphics appear. Octave has a virtually identical user interface to
MATLAB. If you plan to do work at home on labs and assignments and do not have a license of
MATLAB, it is recommended that you repeat some or all of the activities below using Octave on
your home computer.
In the following text, information that you enter will be preceded by the MATLAB
prompt; information not preceded by a prompt is printed by MATLAB as a computation
1
result or other information.
Part a: You can find the Cartesian form by typing the expression, using standard symbols
for arithmetic operations.
As you can see, pi has been changed. If you clear your definition, the old one reappears:
2
Other variables can be set in the same way:
plot (x, y) generates a plot where the values of the vector x indicate points along the
horizontal axis corresponding to the values in the vector y that are to be plotted on the
vertical axis. Vectors x and y must have the same number of elements.
Since complex values have two components corresponding to a+jb, MATLAB provides
the real and imag functions to separate the real and imaginary parts of an imaginary
number:
real and imag break z into real and imaginary parts in the variables zr and zi,
respectively.
Note that typing a semicolon at the end of the command line prevents MATLAB from
echoing the result back to your screen. This will be important when you create large
matrices and vectors. In this example, the value of z was not printed as it was above.
To plot a complex number, we can either plot the real parts vs. the imaginary parts or let
MATLAB do it for us. Here, we supply zr and zi to the plot function:
3
The ‘x’ parameter to the plot function tells MATLAB to generate an x shape for each
data point instead of a ‘connected-dot’ display. Since we only plotted one data point, this
is extremely useful. In general, you should always label axes on your plot and include a
title. help plot shows you the other characters that can be used as well as the different
colors that can be used on the plot.
since the MATLAB default for plotting complex numbers is to plot the real parts on the
horizontal axis and the imaginary parts on the vertical axis.
If you wish to have several plots shown at once on different sets of axes, use subplot -
see the on-line help - or open new figures by typing figure and creating a whole new
plotting window.
4
Here the semicolon at the end is especially important, unless you really want to see and
wait for all 1000 values to be echoed back on your screen.
Next, construct a vector containing values of this function for each time value in t:
It should be pointed out that transcendental functions (e.g. sin, cos, exp) in MATLAB
work on a point-by-point basis; in the above command, the function exp computes a
vector where each element is the exponential of its corresponding element in j*3*pi*t
(1001 total elements).
PROCEDURE :
r1 =
-2
>> r2
r2 =
>> r3
r3 =
-2.0000 + 3.0000i
>> r4
5
r4 =
-2.0000 - 3.0000i
6
Real part f(t)
7
Magnitude of f(t)
Phase of f(t)
8
CONCLUSION:
In retrospect, this experiment provided me with the knowledge in using plots and subplots. Generally
speaking, using the PLOT command is more than enough, but sometimes when you need to have more than
one plot, that is when SUBPLOT command comes in handy. The POLY and ROOTS have inverse effects and
has a self-explanatory definition. Both are needed in order to define a function from roots or from the polynomial
itself. In plotting the real and imaginary part of a function, the commands REAL and IMAG are needed to identify
the value of a specific function and can be used directly in plotting. Meanwhile in complex valued functions, the
commands ABS and ANGLE are used for plotting the magnitude and phase respectively. This experiment
allowed me to understand the basic functions of the said commands.