Graded Lab 2 - Bilkent University

B ILKENT U NIVERSITY E LECTRICAL AND E LECTRONICS E NGINEERING D EPARTMENT
EEE - 321: Signals and Systems
Fall 2014/15
Graded Lab 2
Section 1: 24.10.2014
Section 2: 21.10.2014
Please carefully study this assigment before coming to the laboratory. You may begin
working on it or even complete it if you wish, but you do not have to. There will be short
quizzes both at the beginning and end of the lab session; these may contain conceptual,
analytical, and Matlab-based questions. Within one week, complete the assignment in the
form of a report and turn it in to the assistant. Some of the exercises will be performed
by hand and others by using Matlab. What you should include in your report is indicated
within the exercises.
Part 1
Consider a signal defined as
x s (t ) =
M
X
A i e j ωi t .
(1)
i =1
As you see, x s (t ) is obtained as the superposition of M complex exponentials, where A i and
ωi respectively denote the complex amplitude and angular frequency of the i th complex
exponential.
In this part, you will write a Matlab program (in the form of a Matlab function) that computes the values of x s (t ). Your function should look like
1
function [xs] = SUMCS(t,A,omega)
where
• t: 1 × N vector that contains the time instants over which x s (t ) is computed.
• A: 1 × M complex-valued vector. i th element is A i .
• omega: 1 × M vector. i th element is ωi .
While writing your function, make use of the exp function of Matlab. Use a single for
loop over the index i of Eq. 1. Do not use any for loop over the time points. Doing so will
result in significant loss of grade. Your program does not need to show any error message if
a wrong value is given for any of the inputs (for instance, if A is of size 1 × 5 but omega is of
size 1 × 7). Simply assume that you will always run your function with correct inputs. Also,
throughout
all your programs, in order to avoid programming bugs, reserve the letter j for
p
−1, i.e., do not use it as the counter of any for loop or so. Include your code to your report.
Hint: Given A (or omega), you can use the size command of Matlab to determine its size.
Type help size in Matlab to learn how it works.
π
3
After writing your function, take t=[0:0.001:1], A=[(−1) (2e j 3 ) (−0.5 + 3 j ) (2 j ) (1.8e j 7 )],
and omega=[( π7 ) (− π3 ) (2) (−π) (8π)]. Using your function, compute xs (which is complex
valued). Using the Matlab commands real and imag, extract the real and imaginary parts
of xs into arrays named xsR and xsI. Plot the real and imaginary parts (versus t) separately
using the command plot. Label the x axis as “t” and label the y axis as “xs(t)” using the
commands xlabel and ylabel. In all the plots you produce in this course, specify the labels
of the axes. Include your plots to your report.
Part 2
Consider a signal x(t ) which is periodic with T such that x(t ) = x(t + T ) for all t . In the
lectures, you learned that we can write
∞
X
x(t ) =
Xk e j
2πkt
T
x(t )e − j
2πkt
T
(2)
k=−∞
where
1
Xk =
T
Z
T
2
− T2
dt
(3)
Above, Eq.2 is called the Fourier series expansion of x(t ), and the expansion coefficients X k
can be computed according to Eq.3. As you see, in its Fourier series expansion, we write
2πkt
a signal x(t ) as the weighted superposition of complex sinusoidal signals e j T where the
weights are given by X k .
2
Note that Eq.2 contains an infinite number of complex sinusoids. In practical situations,
if we wish to use Eq.2 to compute x(t ), we can not add all the sinusoids, but instead we can
˜ ) which is defined
only add a finite number of them. In this respect, consider the signal x(t
as
˜ )=
x(t
K
X
Xk e j
2πkt
T
(4)
k=−K
˜ £) = x(t¢). When K is
where K is a positive integer. Note that if K = ∞, we would have x(t
˜ ) is only an approximation to x(t ). Now, suppose, within t ∈ − T2 , T2 , x(t ) is given
finite, x(t
as
x(t ) =
( 2t
eW
0
if − W2 < t < W2 ,
otherwise,
(5)
where
W <T
(6)
(Recall that in the beginning we assumed that x(t ) is periodic with T . The above equation
describes x(t ) in only ONE period. It does not specify x(t ) FOR ALL t. Do not get confused
on this point.)
Take T = 1, W = 0.4 and sketch (with your hand) x(t ) over −1.5T < t < 1.5T . Include this
sketch to your report. Clearly indicate the signal amplitudes on the sketch.
Determine the Fourier series expansion coefficients X k of x(t ) in Eq. 5 for generic values
of T and W by evaluating the integral in Eq. 3 with your hand. Put your result into the
following form:
e θ(k) − e −θ(k)
.
(7)
Xk = A
θ(k)
Find θ(k) and A in terms of k, W and T . Include your work to your report.
˜ )
Next, write a Matlab program (in the form of a Matlab function) which computes the x(t
given in Eq. 4. Your function should look like
function [xt] = FSWave(t,K,T,W)
where
˜ ) is computed.
• t denotes the time grid over which x(t
˜ ) computed over t.
• xt denotes the values of x(t
• K, T and W denote the parameters K , T and W that appear in Eq. 4 and Eq. 5.
3
While writing your code, use the function SUMCS that you developed in Part 2. Use only
a single for loop over the index parameter k of Eq. 4. Include the code to your report.
Let D denote your ID number, and let D 7 denote your ID number in modulo 7. That is
D ≡ D 7 mod7
with 0 ≤ D 7 ≤ 6. You can compute D 7 using the rem command of Matlab. To learn how rem
works, type help rem in Matlab command window.
Take T=2, W=0.8, K=30+D 7 and t=[-3:0.001:3]. Compute xt.
Again, using the real and imag commands of Matlab, extract the real and imaginary parts
of xt and plot them versus t. Include the plots to your report. Examine the maximum and
minimum values that you see on the plots. What are these values for real and imaginary
parts? What can you say when you compare them? Can you ignore the imaginary part
when compared to the real part? Actually, since x(t ) in Eq. 5 is a real valued signal, we
would expect the imaginary part to be zero. But then,
do you think that the imaginary
¢
¡π¢
¡ πwhy
part is not perfectly zero? (Hint: We know
¡ π ¢ that sin 6 is equal to 0.5. Then, sin 6 − 0.5
must be equal to 0. Try computing sin 6 − 0.5 in Matlab. What result do you get?)
Now, take T=2, W=1.2 and t=[-3:0.001:3] and produce five plots taking K=2+D 7 , K=6+D 7 ,
K=10+D 7 , K=50+D 7 , K=100+D 7 . Now you know that xt is essentially real valued you can
display only the real part of xt. Include all five plots to your report. What do you observe
˜ ) in approximating
as K gets larger? In particular, what can you say about the success of x(t
x(t )?
Part 3
In this part, you will make small changes in the function FSWave that you wrote in Part 2,
and you will observe the resulting changes.
In your code, make the appropriate change so that the complex sinusoids are superposed
with coefficients X −k instead of X k where X k is as you found in Part 2. That is, you will
compute a new signal y(t ) where
y(t ) =
K
X
Yk e j
2πkt
T
(8)
k=−K
where Yk = X −k . In your report, indicate the change you make to your code.
Take T=2, W=0.8, K=30+D 7 and t=[-3:0.001:3] as in the first plot of Part 2. Run your code,
and compute and plot y(t ) versus t (only the real part). Include the plot to your report.
What is the effect of the operation that we performed? Include the answer to your report.
4
2πkt 0
Now, let Yk = X k e − j T where t 0 is a new parameter. Repeat the above exercise with
t 0 = 0.4 and include your plot and the change in your code to your report. Try several different values for t 0 , but do not include the plots. What is the effect of the operation that we
performed? Include the answer to your report.
Finally, let Yk = 0.5X k+k0 + 0.5X k−k0 where k 0 is another new parameter of integer value.
Repeat the above exercise with k 0 = 10 and include your plot and the change in your code
to your report. Try several different values for k 0 , but do not include the plots. What is the
effect of the operation that we performed? Include the answer to your report.
5