Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

B ILKENT U NIVERSITY E LECTRICAL AND E LECTRONICS E NGINEERING D EPARTMENT

EEE - 321: Signals and Systems


Lab Assignment 2

For Section-I report submission is due by 24.10.2017


For Section-II report submission is due by 26.10.2017

Please carefully study this assignment 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
M
A i e j ωi t .
X
x s (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 com-
putes 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,p throughout all your programs, in order to avoid programming bugs, reserve the letter
j for −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 length command of Matlab to determine its
length. Type help length in Matlab to learn how it works.

After writing your function, take t=[0:0.001:1], A=[2j 1+j 1-j -2j] and omega=[ π6 π4 − π6 π].
Using your function, compute xs (which is complex valued). Then, extract the real and
imaginary parts of xs. Plot the real and imaginary parts (versus t) separately. Also, extract
the magnitude and phase of xs and plot them separately. In all your plots, put the labels
and titles properly. Include your code and 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
∞ 2πkt
Xk e j
X
x(t ) = T (2)
k=−∞

where
T
1
Z
2 2πkt
Xk = x(t )e − j T dt (3)
T − T2

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
only add a finite number of them. In this respect, consider the signal x̃(t ) which is defined
as

K 2πkt
Xk e j
X
x̃(t ) = T (4)
k=−K

where K is a positive integer. Note that if K = ∞, we would have x̃(t ) = x(t ). When K is
finite, x̃(t ) is only an approximation to x(t ). Now, consider a bi-polar square pulse x(t ),
defined over its period as:
(
−1 −T /2 < t < 0,
x(t ) = (5)
1 0 < t < T /2.
(Recall that in the beginning we assumed that x(t ) is periodic with T . The above equation
describes only ONE period of x(t ). It does not specify x(t ) FOR ALL t. Do not get confused
on this point.)

For T = 10 sketch (with your hand) x(t ) over −2T < t < 2T . 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 value
of T by evaluating the integral in Eq. 3 with your hand. (Note that k indicates the coefficient
of the kth harmonic). Simplify your result as much as possible. Include your work to your
report.

Part 3
In this part, you will write a Matlab function which makes the Fourier Synthesis for the
signal given in Eq. 5. In other words, your code will compute x̃(t ) from the given parameters
K and T for a given time interval. Your function should look like

function [xt] = FSWave(t,K,T)

where

• t denotes the time grid over which x̃(t ) is computed.

• xt denotes the values of x̃(t ) computed over t.

• K and T denote the parameters K and T that appear in Eq. 4 and Eq. 5.

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. (Note that, within the code you need
to compute X k .) Include the code to your report.

3
• (1) Plot (stem) the magnitude of Fourier series coefficients of x̃(t ) for K = 10. Add
appropriate labels and title.

• (2) Plot the real part of x̃(t ) for −20 < t < 20 in Matlab for K = 10. Choose the time grid
array, t so that the continuous nature of x̃(t ) is exhibited in the plot. Add appropriate
labels and title to your plot.

• (3) Now generate an approximate signal x̃(t ) by using the Matlab function FSWave.
For this purpose try to approximate x(t ) from the Fourier series coefficients of x̃(t )
for k ∈ [−K , K ], where K = 5, at the values of t=[-20:0.001:20]. Describe clearly what
the corresponding input parameters of your Matlab function should be. Plot the real
part of x̃(t ) with the proper labels and title. Also, compute the approximation error
in Matlab, that is given as:

1 T ∆t TX
/∆t
Z
|x̃(t ) − x(t )|2 dt ≈ |x̃(i ∆t ) − x(i ∆t )|2 (6)
T 0 T i =0

where ∆t = 0.001, the time interval between successive entries of t .

• (4) Repeat item 3 for K = 20.

• (5) Repeat item 3 for K = 50.

• (6) Repeat item 3 for K = 500.

• (7) Now, discuss the approximations x(t )s for different values of K . In your argu-
ments, utilize the plots that you generated and the approximation error you com-
puted. Also, discuss the Gibbs phenomena that you observed in the plots.

• (8) Can you ignore the imaginary part when compared to the real part of Fourier Se-
ries synthesized x(t )? Actually, since x(t ) in Eq. 5 is a real valued signal, we would
expect the imaginary part to be zero. But then, why do you think that the imaginary
part is not perfectly zero?

Part 4
In this part, you will make small changes in the function FSWave of Part 3, and you will
observe the resulting changes. For this part keep T = 10, K = 20 and t=[–30:0.001:30].

• (a) Let y(t ) = x(−t ), where x(t ) is as given in Eq. 5. In terms of fourier series coeffi-
cients X k you evaluated in Eq. 3 for x(t ) now compute Yk ’s, where Yk are the Fourier
series coefficients of y(t ).

Consider the following equation:


K 2πkt
Yk e j
X
y(t ) = T (7)
k=−K

4
• b) What is the required change in your FSWave function to compute y(t ) from X k s.
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.

• c) Now let y(t ) = x(t − 10). Repeat items (a) and (b)

• d) Suppose y(t ) = d dx(tt ) . First, plot y(t ) by hand and then, repeat items (a) and (b).

You might also like