0% found this document useful (0 votes)
0 views9 pages

lab2 dsp

The document outlines Lab 02 for the EE-330 Digital Signal Processing course, focusing on complex exponentials and sinusoids. It includes objectives, lab instructions, and specific tasks for students to complete using MATLAB, such as generating sinusoids and synthesizing waveforms. The lab emphasizes understanding complex numbers, phasor addition, and practical coding skills in MATLAB for signal processing applications.

Uploaded by

Saad Kashif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
0 views9 pages

lab2 dsp

The document outlines Lab 02 for the EE-330 Digital Signal Processing course, focusing on complex exponentials and sinusoids. It includes objectives, lab instructions, and specific tasks for students to complete using MATLAB, such as generating sinusoids and synthesizing waveforms. The lab emphasizes understanding complex numbers, phasor addition, and practical coding skills in MATLAB for signal processing applications.

Uploaded by

Saad Kashif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 9

Department of Electrical Engineering

2 Faculty Member: Dr. Nauman Anwar Baig


3 Date:4 4-2-2025

5 Semester: 6 6th 7 Section:


8 BEE-14-A

EE-330 Digital Signal Processing


Lab 02: Complex Exponentials and Sinusoids
PLO4 PLO4 PLO5 PLO8 PLO9
CLO4 CLO4 CLO5 CLO6 CLO7

Viva / Analysis Modern Ethics Individual


Student Name Reg. No Quiz / of Data Tool and
Demo in Report Usage Teamwork

5 Marks 5 Marks 5 Marks 5 Marks 5 Marks

Muhammad Saad Kashif 403474

Abdullah Munir 413132

Wassi Haider Kabir 410398

Hamza Irshad Bhatti 415468


Lab 02: Complex Exponentials and Sinusoids

Objectives
The goal of this Part is to gain familiarity with complex numbers and their use in representing sinusoidal
signals such as 𝑥ሺ𝑡ሻ = 𝐴𝑐𝑜𝑠ሺ𝜔𝑡 + ∅ሻ as complex exponentials 𝑧ሺ𝑡ሻ = 𝐴𝑒 𝑗𝜃 𝑒 𝑗𝜔𝑡 . The key is to use the
appropriate complex amplitude together with the real part operator as follows:

𝑥ሺ𝑡ሻ = 𝐴𝑐𝑜𝑠ሺ𝜔𝑡 + ∅ሻ = 𝑅𝑒𝑎𝑙{𝐴𝑒 𝑗𝜃 𝑒 𝑗𝜔𝑡 }


✓ How to work with Complex Numbers in MATLAB
✓ Familiarization with Matalb Function and commands for Complex Exponentials
✓ Sinusoid Addition Using Complex Exponentials

Lab Instructions
✓ The students should perform and demonstrate each lab task separately for step-wise evaluation
✓ Each group shall submit one lab report on LMS within 5 days after lab is conducted. Lab report
submitted via email will not be graded.
✓ Students are however encouraged to practice on their own in spare time for enhancing their
skills.

Lab Report Instructions


All questions should be answered precisely to get maximum credit. Lab report must ensure following
items:
✓ Lab objectives
✓ MATLAB codes
✓ Results (graphs/tables) duly commented and discussed
✓ Conclusion
Lab 02 - Complex Exponentials and Sinusoids

1. 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.

Complex Numbers in MATLAB


Here are some of MATLAB’s built-in 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 𝑒 𝑗𝜃

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.

Sinusoid Addition Using Complex Exponentials


Recall that sinusoids may be expressed as the real part of a complex exponential:

𝑥ሺ𝑡ሻ = 𝐴𝑐𝑜𝑠ሺ2𝜋𝑓𝑜 𝑡 + ∅ሻ = 𝑅𝑒𝑎𝑙{𝐴𝑒 𝑗𝜃 𝑒 2𝑗𝜋𝑓0𝑡 } (1)

The Phasor Addition Rule shows how to add several sinusoids:

𝑥ሺ𝑡ሻ = ∑𝑁
𝑘=1 𝐴𝑘 𝑐𝑜𝑠ሺ2𝜋𝑓𝑜 𝑡 + ∅ሻ (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
𝑋𝑘 = 𝐴𝑘 𝑒 𝑗∅𝑘 (3)

Then the complex amplitude of the sum is


𝑋𝑠 = ∑𝑁
𝑘=1 𝑋𝑘= 𝐴𝑠 𝑒
𝑗∅𝑠
(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
𝑥ሺ𝑡ሻ = 𝐴𝑠 𝑐𝑜𝑠ሺ2𝜋𝑓𝑜 𝑡 + ∅𝑠 ሻ (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.

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.

fk = k f0 (HARMONIC FREQUENCIES),

Then the sum of N cosine waves given by (2) becomes:

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.

Sinusoids in MatLab
Following is a MatLab function to create a sinusoid with frequency ff and duration dur.

The corrected function 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);

2. Lab Tasks:
Complex Exponentials
In the previous lab, you learned how to write M-files. In this section, you will write functions that can
generate sinusoids or sums of sinusoids.

2.1. 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?
### ANSWER STARTS HERE ###
Code:
function [tt, xx] = goodcos(A, w, phi, dur)
fs=20;
tt = 0:1/(fs*w/(2*pi)):dur;
xx = A*cos(w*tt + phi);
end

[tt, xx] = goodcos(95, 200, pi/5, 0.025);

plot(tt ,xx, 'b');


title('goodcos1')
xlabel('time t')
ylabel('x(t)')
Output:

Expected Time Period = 31.45ms


### ANSWER ENDS HERE ###
2.2. Lab Task 2:
Sum of Sinusoids
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 expressions are equivalent if we define the complex amplitudes 𝑋𝑘 = 𝐴𝑘 𝑒 𝑗∅𝑘

𝑥ሺ𝑡ሻ = 𝑅𝑒𝑎𝑙{∑𝑁
𝑘=1 𝑋𝑘 𝑒
𝑗2𝜋𝑓𝑘 𝑡
} (7)
.
𝑁
𝑥ሺ𝑡ሻ = ∑𝑘=1 𝐴𝑘 𝑐𝑜𝑠ሺ2𝜋𝑓𝑘 𝑡 + ∅𝑘 ሻ (8)

Write a function to synthesize a waveform in form of (7) or (8). The function must take as input a set of
amplitudes, a set of frequencies, a set of phase angles, sampling frequency, the start time and the total
duration. The function should compute the sum and output the time vector and the output of the sum. You
must call this function in a separate main function and then plot the resulting output. Although for loops
are inefficient, you will have to write one in this task. The start of the function looks like below:

function [xx,tt] = syn_sin(fk, Xk, fs, dur, tstart)

You should provide error checking to ensure that the lengths of fk, Xk and phi_k are the same. See help
error. Finally, notice that the input fs define the number of samples per second for the cosine generation;
in other words, we are no longer constrained to using 20 samples per period.

### ANSWER STARTS HERE ###


Code:
function [xyz, tt] = syn_sin(fk, Xk, fs, dur, tstart)

tt = tstart:1/fs:dur;
xyz = zeros(size(tt));
for i = 1:length(Xk)
xyz = xyz + Xk(i) * exp(1i * 2 * pi * fk(i) * tt);
end
end

### ANSWER ENDS HERE ###

2.3. Lab Task 3:


Test the function you created in task 2
In order to use this M-file to synthesize harmonic waveforms, you must choose the entries in the
frequency vector to be integer multiples of some desired fundamental frequency. Try the following test
and plot the result:

[xx0,tt0] = syn_sin([0,100,250], [15,14*exp(-j*pi/3),8*j], [0 0 0], 10000, 0.1, 0);


%-Period = ?
Measure the period of xx0 by hand. Then compare the period of xx0 to the periods of the three sinusoids
that make up xx0?

### ANSWER STARTS HERE ###


Code:
[xx,tt] = syn_sin([0,100,250], [15,14*exp(-j*pi/3),8*j], 10000, 0.1, 0);

plot(tt,xx, 'b-')
xlabel('time')
ylabel('x(t)')
title('added sinosoids')
Output:

Time period: 2.857ms


### ANSWER ENDS HERE ###
2.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.

(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).

### ANSWER STARTS HERE ###


(a)
Code:
[xx,tt] = syn_sin([0.5, 0.5 , 0.5], [2,2, (1-j)], [0,-1.25,0], 10000, 4.5, -0.5);

plot(tt,xx, 'b-')
xlabel('time')
ylabel('x(t)')
title('added sinosoids')

Output:

### ANSWER ENDS HERE ###


Conclusion:
In this lab we learnt about complex exponentials and learnt how to make m-file(function file) in
MatLab .

You might also like