Starting from:

$30

Lab #2:  Introduction  to Complex  Exponentials    

ECES-352

Lab    #2:        Introduction    to    Complex    Exponentials    
Pre-Lab:    You    should    read    the    Pre-Lab    section    of    the    lab    and    go    over    all    exercises    in    
this    section    before    going    to    your    assigned    lab    session.    
Verification:    The    Warm-up    section    of    each    lab    must    be    completed    during    your    
assigned    Lab    time,    and    the    steps    marked    Instructor    Verification    must    also    be    signed    
off    during    the    lab    time.    The    laboratory    instructor    must    verify    the    appropriate    steps    
by    signing    on    the    Instructor    Verification    line.    When    you    have    completed    a    step    that    
requires    verification,    simply    raise    your    hand    and    demonstrate    the    step    to    the    
instructor.    Turn    in    the    completed    verification    sheet    to    your    instructor    when    you    
leave    the    lab.
Lab    Report:    It    is    only    necessary    to    turn    in    Section    5 as    this    week’s    lab    report    with    
graphs    and    explanations.        You    are    asked    to    label    the    axes    of    your    plots    and    include    a    
title    for    every    plot.    In    order    to    keep    track    of    plots,    include    your    plot    inlined    within    
your    report.    
Forgeries    and    plagiarism    are    a    violation    of    the    honor    code    and    will    be    referred    to    
the    Dean    of    Students    for    disciplinary    action.    You    are    allowed    to    discuss    lab    exercises    
with    other    students    and    you    are    allowed    to    consult    old    lab    reports    but    the    submitted    
work    should    be    original    and    it    should    be    your    own    work.        In    particular,    any    MATLAB    
code    that    you    submit    should    be    your    own,    the    words    in    your    report    should    be    your    
own,    and    any    plots    that    you    submit    should    be    your    own.    
Due    Date:    The    Verification    part    is    due    today,    and    the    lab    report    is due    
at    the    start    of    your    next lab.
1 Introduction
The goal of this laboratory is to gain familiarity with complex numbers and their use in representing sinusoidal signals such as x(t) = A cos(ωt + φ) as complex exponentials z(t) = Aejφejωt
. The key is to use
the complex amplitude and then the real part operator applied to Euler’s formula:
x(t) = A cos(ωt + φ) = !e{Aejφejωt
}
2 Overview
Manipulating sinusoidal functions using complex exponentials turns trigonometric problems into simple
arithmetic and algebra. In this lab, we first review the complex exponential signal and the phasor addition
property needed for adding cosine waves. Then we will use MATLAB to make plots of phasor diagrams that
show the vector addition needed when combining sinusoids.
2.1 Complex Numbers in MATLAB
MATLAB can be used to compute complex-valued formulas and also to display the results as vector or
“phasor” diagrams. For this purpose several new MATLAB functions have been written and are available
on the DSP First CD-ROM. Make sure that this toolbox has been installed1 by doing help on the new
♥❦❤$
CD-ROM
DSP
First
MATLAB
Toolbox
M-files: zvect, zcat, ucplot, zcoords, and zprint. Each of these functions can plot (or print)
several complex numbers at once, when the input is formed into a vector of complex numbers. For example,
try the following function call and observe that it will plot five vectors all on one graph:
zvect( [ 1+j, j, 3-4*j, exp(j*pi), exp(2j*pi/3) ] )
Here are some of MATLAB’s complex number operators:
conj Complex conjugate
abs Magnitude
angle Angle (or phase) in radians
real Real part
imag Imaginary part
i,j pre-defined as √−1
x = 3 + 4i i suffix defines imaginary constant (same for j suffix)
exp(j*theta) Function for the complex exponential ejθ
Each of these functions takes a vector (or matrix) as its input argument and operates on each element of the
vector. Notice that the function names mag() and phase() do not exist in MATLAB.
2
Finally, there is a complex numbers drill program called:
♥❦❤$
CD-ROM
Z Drill
zdrill
which uses a GUI to generate complex number problems and check your answers. Please spend some time
with this drill since it is very useful in helping you to get a feel for complex arithmetic.
When unsure about a command, use help.
1
Correct installation means that the dspfirst directory will be on the MATLAB path. Try help path if you need more
information. 2
In the latest release of MATLAB a function called phase() is defined in a rarely used toolbox; it does more or less the same
thing as angle() but also attempts to add multiples of 2π when processing a vector.
2
2.2 Sinusoid Addition Using Complex Exponentials
Recall that sinusoids may be expressed as the real part of a complex exponential:
x(t) = A cos (2πf0t + φ) = !e
!
Aejφej2πf0t
"
(1)
The Phasor Addition Rule presented in Section 2.6.2 of the text (page 33) shows how to add several sinusoids:
x(t) = #
N
k=1
Ak cos(2πf0t + φk) (2)
assuming that each sinusoid in the sum has the same frequency, f0. This sum is difficult to simplify using
trigonometric identities, but it reduces to an algebraic sum of complex numbers when solved using complex
exponentials. If we represent each sinusoid with its complex amplitude
Xk = Akejφk (3)
Then the complex amplitude of the sum is
Xs = #
N
k=1
Xk = Asejφs (4)
Based on this complex number manipulation, the Phasor Addition Rule implies that the amplitude and phase
of x(t) in equation (2) are As and φs, so
x(t) = As cos(2πf0t + φs) (5)
We see that the sum signal x(t) in (2) and (5) is a single sinusoid that still has the same frequency, f0, and
it is periodic with period T0 = 1/f0.
2.3 Harmonic Sinusoids
There is an important extension where x(t) is the sum of N cosine waves whose frequencies (fk) are
different. If we concentrate on the case where the (fk) are all multiples of one basic frequency f0, i.e.,
fk = kf0 (HARMONIC FREQUENCIES)
then the sum of N cosine waves given by (2) becomes
xh(t) = #
N
k=1
Ak cos(2πkf0t + φk) = !e
$#
N
k=1
Xk ej2πkf0t
%
(6)
This particular signal xh(t) has the property that it is also periodic with period T0 = 1/f0, because each of
the cosines in the sum repeats with period T0. The frequency f0 is called the fundamental frequency, and
T0 is called the fundamental period. (Unlike the single frequency case, there is no phasor addition theorem
here to combine the harmonic sinusoids.)
3 Pre-Lab
You need to do all exercises in this section to be able to solve the on-line pre-lab exercise.
3
3.1 Complex Numbers
This section will test your understanding of complex numbers. Use z1 = 3ej3π/4 and z2 = −2 + 2√2j for
all parts of this section.
(a) Enter the complex numbers z1 and z2 in MATLAB and plot them with zvect(), and print them with
zprint().
When unsure about a command, use help.
Whenever you make a plot with zvect() or zcat(), it is helpful to provide axes for reference. An
x-y axis and the unit circle can be superimposed on your zvect() plot by doing the following:
hold on, zcoords, ucplot, hold off
(b) Compute the conjugate z∗ and the inverse 1/z for both z1 and z2 and plot the results. In MATLAB,
see help conj. Display the results numerically with zprint.
(c) The function zcat() can be used to plot vectors in a “head-to-tail” format. Execute the statement
zcat([1+j,-2+j,1-2j]); to see how zcat() works when its input is a vector of complex
numbers.
(d) Compute z1 + z2 and plot the sum using zvect(). Then use zcat() to plot z1 and z2 as 2 vectors
head-to-tail, thus illustrating the vector sum. Use hold on to put all 3 vectors on the same plot.
If you want to see the numerical value of the sum, use zprint() to display it.
(e) Compute z1z2 and z2/z1 and plot the answers using zvect() to show how the angles of z1 and z2
determine the angles of the product and quotient. Use zprint() to display the results numerically.
(f) Make a 2 × 2 subplot that displays four plots in one window: similar to the four operations done
previously: (i) z1, z2, and the sum z1 + z2 on a single plot; (ii) z2 and z∗
2 on the same plot; (iii) z1 and
1/z1 on the same plot; and (iv) z1z2. Add a unit circle and x-y axis to each plot for reference.
3.2 Z-Drill
Work a few problems on the complex number drill program. To start the program simply type zdrill.
Use the buttons on the graphical user interface (GUI) to produce different problems.
3.3 Vectorization
The power of MATLAB comes from its matrix-vector syntax. In most cases, loops can be replaced with
vector operations because functions such as exp() and cos() are defined for vector inputs, e.g.,
cos(vv) = [cos(vv(1)), cos(vv(2)), cos(vv(3)), ... cos(vv(N))]
where vv is an N-element row vector. Vectorization can be used to simplify your code. If you have the
following code that plots a certain signal,
M = 200;
for n=1:M
x(i) = i;
y(i) = cos( 0.001*pi*x(i)*x(i) );
end
plot( x, y, ’ro-’ )
then you can replace the for loop and get the same result with 3 lines of code:
4
M = 200;
y = cos( 0.001*pi*(1:M).*(1:M) );
plot( 1:M, y, ’ro-’ )
Use this vectorization idea to write 2 or 3 lines of code that will perform the same task as the following MATLAB
script without using a for loop. (Note: there is a difference between the two operations xx*xx and xx.*xx when
xx is a vector.)
%--- make a plot of a strange signal
N = 300;
for k=1:N
xk(k) = k/60;
rk(k) = sqrt( xk(k)*xk(k) + 2.5 );
sig(k) = exp(j*2*pi*rk(k));
end
plot( xk, real(sig), ’mo-’ )
3.4 Functions
Functions are a special type of M-file that can accept inputs (matrices and vectors) and also return outputs. The
keyword function must appear as the first word in the ASCII file that defines the function, and the first line of the
M-file defines how the function will pass input and output arguments. The file extension must be lower case “m” as in
my func.m. See Section B.5 in Appendix B for more discussion.
The following function has a few mistakes. Try to find these mistakes before looking at the correctedd one, which
is given elsewhere in this lab assignment. Note: There are at least three errors):
matlab mfile [xx,tt] = badcos(ff,dur)
%BADCOS Function to generate a cosine wave
% usage:
% xx = badcos(ff,dur)
% ff = desired frequency
% dur = duration of the waveform in seconds
%
tt = 0:1/100*ff:dur; %-- gives 100 samples per period
badcos = cos(2*pi*freeq*tt);
4 Warm-Up: Complex Exponentials
In the Pre-Lab part of this lab, you learned how to write a function that performs a certain task. Write a function that
will generate a single sinusoid, x(t) = A cos(ωt + φ), by using four input arguments: amplitude (A), frequency (ω),
phase (φ) and duration (dur). The function should return two outputs: the values of the sinusoidal signal (x) and
corresponding times (t) at which the sinusoid values are known. Make sure that the function generates 25 values of
the sinusoid per period. Call this function mycos(). Hint: You may want to use badcos() from the Pre-Lab part
as a starting point.
Demonstrate that your mycos() function works by plotting the output for the following parameters: A = 8, ω = 75π
rad/sec, φ = −π/3 radians, and dur = 0.05 seconds. Be prepared to explain to the lab instructor features on the
plot that indicate how the plot has the correct period and phase. What is the expected period in millisec?
Instructor Verification (separate page)
4.1 Sinusoidal Synthesis with an M-file: Different Frequencies
Since we will generate many functions that are a “sum of sinusoids,” it will be convenient to have a function for
this operation. To be general, we will allow the frequency of each component (fk) to be different. The following
5
expressions are equivalent if we define the complex amplitude Xk as Xk = Akejφk .
x(t) = !e
$#
N
k=1
Xkej2πfkt
%
(7)
x(t) = #
N
k=1
Ak cos(2πfkt + φk) (8)
4.1.1 Write the Function M-file
Write an M-file called syn sin.m that will synthesize a waveform in the form of (7). Although for loops are rather
inefficient in MATLAB, you must write the function with one loop in this lab. The first few statements of the M-file are
the comment lines—they should look like:
function [xx,tt] = syn_sin(fk, Xk, fs, dur, tstart)
%SYN_SIN Function to synthesize a sum of cosine waves
% usage:
% [xx,tt] = syn_sin(fk, Xk, fs, dur, tstart)
% fk = vector of frequencies
% (these could be negative or positive)
% Xk = vector of complex amplitudes: Amp*eˆ(j*phase)
% fs = the number of samples per second for the time axis
% dur = total time duration of the signal
% tstart = starting time (default is zero, if you make this input optional)
% xx = vector of sinusoidal values
% tt = vector of times, for the time axis
%
% Note: fk and Xk must be the same length.
% Xk(1) corresponds to frequency fk(1),
% Xk(2) corresponds to frequency fk(2), etc.
The MATLAB syntax length(fk) returns the number of elements in the vector fk, so we do not need a separate
input argument for the number of frequencies. On the other hand, the programmer (that’s you) should provide error
checking to make sure that the lengths of fk and Xk are the same. See help error. Finally, notice that the input
fs defines the number of samples per second for the cosine generation; in other words, we are no longer using 25
samples per period.
4.1.2 Default Inputs
You can make the last input argument(s) take on default values if you use the nargin operator in MATLAB. For
example, tstart can be made optional by including the following line of code:
if nargin<5, tstart=0, end %--default value is zero
4.1.3 Testing with Sounds
Summation: Use your syn sin() function to generate the sum of three sinusoids with frequencies that correspond
to notes in a piano chord: f1 = 440 Hz, f2 = 555 Hz, and f3 = 660 Hz. If these 3 tones are played at the same time,
the result should be close to an A-major chord. Make all the amplitudes equal, pick the phases to be 1
2π, and make the
signal one second long. Use a sampling rate of 11000 samples per sec. Play the signal with soundsc() to verify
that it makes a pleasant sounding chord. Demonstrate your work to one of the TAs.
Instructor Verification (separate page)
6
4.2 Representation of Sinusoids with Complex Exponentials
In MATLAB consult help on exp, real and imag. Be aware that you can also use the DSP First function zprint
to print the polar and rectangular forms of any vector of complex numbers.
(a) Generate the signal x(t) = !e{2ej25πt − 2ej25π(t − 0.02) + (1 + j)ej25πt
} and make a plot versus t. Use
the syn sin function and take a range for t that will cover four periods.
(b) From the plot of x(t) versus t, measure the frequency, phase and amplitude of the sinusoidal signal by hand.
Show annotations on the plots to indicate how these measurements were made and what the values are. Compare
to the calculation in part (c).
(c) Use the phasor addition theorem and MATLAB to determine the magnitude and phase of x(t).
Demonstrate your work to one of the TAs.
Instructor Verification (separate page)
Answer: The corrected function in 3.4 should look something like:
function [xx,tt] = goodcos(ff,dur)
tt = 0:1/(100*ff):dur; %-- gives 100 samples per period
xx = cos(2*pi*ff*tt);
Notice the word “function” in the first line. Also, “freeq” has not been defined before being used. Finally, the
function has “xx” as an output and hence “xx” should appear in the left-hand side of at least one assignment line within
the function body. The function name is not used to hold values produced in the function. Also, we need to make sure
that the frequency is in the denominator of the time increment, 1/(100 ∗ ff).
5 Multipath Fading
In a mobile radio system (e.g., cell phones or AM radio), there is one type of degradation that is a common problem.
This is the case of multipath fading caused by reflections of the radio waves, which interfere destructively at some
locations. Consider the scenario diagrammed in Fig. 1 where a vehicle traveling on the roadway receives signals from
two sources: directly from the transmitter and reflections from another object such as a large building. This multipath
problem can be modeled easily with sinusoids. The total received signal at the vehicle is the sum of two signals which
are themselves delayed versions of the transmitted signal, s(t).
(a) The amount of the delay (in seconds) can be computed for both propagation paths. First of all, consider the
direct path. The time delay is the distance divided by the speed of light (2.9×108 m/s in dirty Atlanta air). Write
a mathematical expression for the time delay in terms of the vehicle position xv and the transmitter location
(0, dt). Call this delay time t1 and express it as a function of xv, i.e., t1(xv).
(b) Now write a mathematical formula for the time delay of the signal that travels the reflected path from the
transmitter at (0, dt) to the reflector at (dxr, dyr) and then to the vehicle at (xv, 0). Call this delay time t2 and
make sure that you also express it as a function of xv, i.e., t2(xv). In this case, you must add together two
delays: transmitter to reflector and then reflector to vehicle.
(c) The received signal at the vehicle, rv(t), is the sum of the two delayed copies of the transmitter signal
rv(t) = s(t − t1) − 0.8s(t − t2)
where s(·) is the transmitted signal, the amplitde of 0.8 for the reflected wave accounts for the fact that the
building is not a perfect reflector, and the minus sign accounts for fact that the reflection reverses the phase of
the reflected signal.3
Assume that the source signal s(t) is a zero-phase unit-amplitude sinusoid at f0 = 133 MHz; and also assume
that the transmitter is located at (0, 1700) meters and the reflector at (150, 800) meters. Then the received
3
For simplicity we are ignoring propagation losses: When a radio signal propagates over a distance R, its amplitude will be
reduced by an amount that is inversely proportional to R2.
7
VEHICLE
TRANSMITTER
REFLECTOR
Strength = 100%
Phase Shift = 180o
(0,dt
)
y
x
xv
Velocity of
Propagation = c
(velocity of light)
DIRECT PATH
REFLECTED PATH
(dxr,dyr)
Figure 1: Scenario for multipath in mobile radio. A vehicle traveling on the roadway (to the right) receives
signals from two sources: the transmitter and a reflector located at (dxr, dyr). Note: The figure illustrates a
reflector strength of 100%. For the reflector we are considering, the strength is only 80%.
signal is the sum of two sinusoids. Make a plot of the received signal, rv(t), when the vehicle position is
xv = 0 meters. Plot 3 periods of rv(t) and then measure its maximum amplitude.
(d) Our aim in the rest of this lab is to make a plot of signal strength versus vehicle position (xv). One approach
would be to repeat the process in part (c) for every position, i.e., generate the resultant sinusoid and measure its
amplitude. However, that would be a huge waste of computation. Instead, the complex amplitude approach in
part (d) is a much more efficient method.
Derive a mathematical expression for complex amplitudes of each delayed sinusoid as a function of position xv.
Then write a MATLAB program that will generate the time delays, form the complex amplitudes, and then add
the complex amplitudes. Have the MATLAB program loop through the entire set of vehicle positions specified
in part (f) below. Include this MATLAB code in your report and explain how it works.
Vectorization: It is likely that your previous programming skills would lead you to write a loop to do this
implementation. The loop would run over all possible values of xv, and would add the two complex amplitudes
calculated at each xv.
However, there is a much more efficient way in MATLAB, if you think in terms of vectors (which are really lists
of numbers). In the vector strategy, you would make a vector containing all the vehicle positions; then do the
distance and time delay calculations to generate a vector of time delays; next, a vector of complex amplitudes
would be formed. In each of these calculations, only one line of code is needed and no loops. You need two
vectors of complex amplitudes (one for the direct path and the other for the reflected path), so the whole process
is done twice and then you can perform a vector add of the two complex amplitudes.
(e) Utilize the MATLAB program from the previous part to generate a plot of signal strength versus vehicle position,
xv, over the interval from 0 meters to +400 meters.4 Assume that signal strength is defined to be the peak value
of the received sinusoid, rv(t). State how you get the peak value from the complex amplitude.
(f) Explain your results from the previous part. In particular, what are the largest and smallest values of received
signal strength? Why do we get those values? Are there vehicle positions where we get complete signal
cancellation? If so, determine those vehicle positions.
4
MATLAB works on vectors so you will have to produce a vector of positions starting at 0 and ending at +400 with a spacing
that is small enough to capture all the variations in signal strength.
8
Lab #2
ECE6???
F6????
INSTRUCTOR VERIFICATION SHEET
Turn this page in to your TA before the end of your lab period.
Name: Date of Lab:
Part 4 Demonstrate that your mycos function is correct by plotting a sinusoidal signal with the given parameters.
Use the space below to calculate the period of the sinusoid.
Verified: Date/Time:
Part 4.1.3 Show that your syn sin.m function is working correctly by generating the “pleasant sounding chord” and
plotting the result.
Verified: Date/Time:
Part 4.2 Show your work and explain your work, and have your TA sign below. below.
Verified: Date/Time:
9

More products