DSP Lab2
DSP Lab2
1
Lab2
Complex Exponentials and Sinusoids
Objectives:
The goal of this Part is to:
Introduction
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 adding sinusoids.
Lab Tasks
Lab Task 1: M-file to generate a Sinusoid.
Write a function that will generate a single sinusoid,𝑥(𝑡) = 𝐴𝑐𝑜𝑠(𝜔𝑡 + ∅) 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 20 values of the sinusoid per
period. Call this function one_cos(). Hint: use goodcos() from previous Lab as a starting point.
Demonstrate that your one_cos() function works by plotting the output for the following
parameters: A = 95, ω = 200 rad/sec, ɸ = π/5 radians, and dur=0.025 seconds. Be prepared to
explain to the lab instructor features on the plot that indicates how the plot has the correct period
and phase. What is the expected period in millisecond?
Code:
function main()
amplitude=95;
2
w = 200;
phase = pi/5;
d = 0.025;
[x,t]=one_cos(amplitude, w, phase, d);
plot(t,x,'b')
title('one_cos function')
end
Output:
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)
3
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 constrained to using 20 samples per period.
Code:
x_t = 0;
for k = 1:length(fk)
x_t = x_t + real(Xk(k) * exp(2 * pi * 1i * fk(k) * t));
end
end
Measure the period of xx0 by hand. Then compare the period of xx0 to the periods of the three sinusoids
that make up xx0?
Code:
t = 0:0.0001:0.1;
a = 10*cos(2*pi*0*t + 0) + 14*cos(2*pi*100*t + (-pi/3)) + 8*cos(2*pi*250*t + (pi/2));
plot(a);
title('Sum of Three Sinusoids');
xlabel('t(s)');
ylabel('x(t)');
Output:
4
Lab Task 4: Representation of Sinusoids with Complex Exponentials
(a) Generate the signal
and make a plot versus t. Use the syn_sin function and take a range for t that will cover three periods
starting at t = −0.5 secs. Include the MATLAB code with your report.
Code:
t=-0.5:0.1:2;
y = (2*exp(1j*pi*t))+(2*exp(1j*pi*(t-1.25)))+((1-1j)*exp(1j*pi*t));
x=real(y);
plot(x);
5
(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.
(c) Use the phasor addition theorem and MATLAB to determine the magnitude and phase of x(t).
Code:
x1 = real(2*exp(1j*0));
x2 = real(2*exp(1j*0));
x3 = real(1.41421*exp(-1j*pi/4));
x4 = x1 + x2 + x3;
magx4 = abs(x4)
thetax4 = angle(x4)
thetarad = thetax4 * 180/pi
6
Conclusion:
From this lab, we learnt about complex numbers and their representation. We worked with
MATLAB and learnt about its function and commands. Moreover, it cleared our concept of
complex exponential and sinusoidal functions through visual representation.