0% found this document useful (0 votes)
55 views3 pages

Lab-02 Complex Numbers (DSP)

The document discusses representing and visualizing complex numbers in MATLAB. It provides tasks to initialize complex numbers, extract their components, plot them in the complex plane, and visualize the special complex number e^jθ. Learners are asked to complete tasks like initializing complex numbers, plotting them, and representing e^jθ in polar and Cartesian forms.

Uploaded by

Taha Mushtaq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views3 pages

Lab-02 Complex Numbers (DSP)

The document discusses representing and visualizing complex numbers in MATLAB. It provides tasks to initialize complex numbers, extract their components, plot them in the complex plane, and visualize the special complex number e^jθ. Learners are asked to complete tasks like initializing complex numbers, plotting them, and representing e^jθ in polar and Cartesian forms.

Uploaded by

Taha Mushtaq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

UNIVERSITY OF ENGINEERING AND TECHNNOLOGY, TAXILA

DEPARTMENT OF ELECTRICAL ENGINEERING

DIGITAL SIGNAL PROCESSING LAB

Lab-02: Complex Numbers

OBJECTIVE:
To understand the complex numbers and visualize them in a complex plane.

INTRODUCTION:
Complex numbers: a combination of real and imaginary numbers, though they seem mysterious
and unreal, play a pivotal role in signal processing and circuit analysis in electrical engineering. A
complex number 𝑧 can be represented using the Cartesian form 𝑧 = 𝑎 + 𝑗𝑏 or the polar form
𝑧 = 𝑟𝑒 𝑗𝜃 . Conversion from one form to the other can be done through the following set of
equations.

𝑎 = 𝑟 𝑐𝑜𝑠𝜃 𝑟 = |𝑧| = √𝑎2 + 𝑏 2


𝑏
𝑏 = 𝑟 𝑠𝑖𝑛𝜃 𝜃 =< 𝑧 = 𝑡𝑎𝑛−1 (𝑎)
The complex number 𝑧 = 𝑐𝑜𝑠𝜃 + 𝑗𝑠𝑖𝑛𝜃 is of such fundamental importance that we give it a
special symbol 𝑒 𝑗𝜃 , i.e., 𝑒 𝑗𝜃 = 𝑐𝑜𝑠𝜃 + 𝑗𝑠𝑖𝑛𝜃. This special complex number 𝑒 𝑗𝜃 is the part of the
basis functions of Laplace, Z and Fourier Transforms.
LEARNING TASKS:
1. Initialize a complex number 𝑧 of your choice in MATLAB using Cartesian form, i.e., 𝑧 =
𝑎 + 𝑏𝐢. (For better understanding of tasks, do not set 𝑎 or 𝑏 equal to 0).
a. A complex number can be initialized by directly writing the syntax or using the
command complex. What is the difference between two?
b. Extract the real part of your complex number using the command real.
c. Extract the imaginary part of your complex number using the command imag.
d. Use the conj command to generate the conjugate of the complex number.
e. Find the absolute value and angle of the complex number using the abs and angle
commands. Write your complex number as 𝑟𝑒 𝑗𝜃 using the exp command.
f. What does cart2pol and pol2cart commands do? Check their syntax carefully
and verify your results.
g. Plot the Argand diagram using the plot (real(𝑧), imag(𝑧)) command. Can you
see the complex number? If not what could be the reason for it?
h. Repeat part-g with grid on, labels and titles properly mentioned. Use a circle marker
of red color in your plot. Origin (0,0) should be shown on your plot.

2. Write a code that takes any real and imaginary part of the complex number from the user
using the input command and then displays the complex number and its conjugate,
absolute value and angle. You will not use built-in functions for finding these values and
no hard coding is allowed. The output after taking the inputs should be displayed like this:

Semester: Fall-2023 Lab Course Instructor: Dr. Junaid Mir


Session: 2K20 Designed by: Dr. Junaid Mir and Prof. Dr. Obaid Ullah
UNIVERSITY OF ENGINEERING AND TECHNNOLOGY, TAXILA
DEPARTMENT OF ELECTRICAL ENGINEERING

The entered complex number is = XXXX


The conjugate of complex number is = XXXX
The absolute value of complex number is = XXXX
The angle of complex number is = XXXX

3. The code below plots 4 random complex numbers in a complex plane where real and
imaginary numbers could be any integer value in the (-10,10) range.
clc % clears command window
clear all % clear workspace
close all % closes all previously opened figures
for i = 1:4
z = complex(randi([-10,10]),randi([-10,10])); % ???
plot(real(z),imag(z),'Color','r','Marker','o','MarkerSize',5,'LineWidth',3);
text(real(z),imag(z),num2str(z),'FontSize',20); % ???
hold on
end
% The below mentioned commands are used to improve the visual appearance of
% the figure for better understanding.
grid on;
axis square; % ???
box on; % ???
title('Argand Diagram')
axis([-10.5 10.5 -10.5 10.5]) % ???
xline(0,'b','Imaginary Axis','LineWidth',2,'LabelHorizontalAlignment','right')
% ???
yline(0,'k','Real Axis','LineWidth',2,'LabelVerticalAlignment','top') % ????
xticks(-10:10) % ???
yticks(-10:10) % ???
a = gca;
a.XRuler.TickLabelGapOffset = -220; % ???
a.YRuler.TickLabelGapOffset = -220; % ???
set(gcf,'units','normalized','outerposition',[0 0 1 1]) % ???

a. Copy the code in a new m-file and run the code. Run the code 2-3 times to
understand the representation of a complex number in a complex plane.
b. Explain different commands used in the code by writing comments.
c. Modify the code to generate 4 random complex numbers in 4 different quadrants.

4. Initialize the special complex number 𝑒 𝑗𝜃 in cartesian form, i.e., 𝑧 = 𝑐𝑜𝑠𝜃 + 𝑗𝑠𝑖𝑛𝜃. Use
the linspace command to produce sufficient points for 𝜃 in range [0, 2𝜋].
a. Visualize 𝑒 𝑗𝜃 and 𝑒 −𝑗𝜃 using the plot3 command. Are these 2D signals or 3D?
What is the difference between both in terms of visualization?
b. Copy the complete code below in your m-file and run the code for better
visualization of part-a. Use Rotate 3D button from the Tools menu to view all three
X-Y, X-Z and Y-Z 2D planes. Identify the functions in 2D planes and save them to
include in your report.
c. Modify the code to include one more cycle of 𝑒 𝑗𝜃 . Make sure to modify the z-axis
as well for proper visualization.

Semester: Fall-2023 Lab Course Instructor: Dr. Junaid Mir


Session: 2K20 Designed by: Dr. Junaid Mir and Prof. Dr. Obaid Ullah
UNIVERSITY OF ENGINEERING AND TECHNNOLOGY, TAXILA
DEPARTMENT OF ELECTRICAL ENGINEERING
clc; clear all; close all
theta = linspace(0,4*pi,1000);
z = cos(theta)+1j*sin(theta);
plot3(theta,real(z),imag(z),'LineWidth',2,'Color','k');
% The below mentioned commands are used to improve the visual appearance of
% the figure for better understanding.
grid on; box on; axis square;
title('Plot of e^{j\theta} ','FontSize',25)
xlabel('\theta','FontSize',20)
ylabel('\Re (e^{j\theta})','FontSize',20)
zlabel('\Im (e^{j\theta})','FontSize',20)
xticks([0, pi/2, pi, 3*pi/2, 2*pi, 5*pi/2, 3*pi, 7*pi/2, 4*pi])
xticklabels({'0','\pi/2','\pi','3\pi/2','2\pi','5\pi/2','3\pi','7\pi/2','4\pi'})
ax = gca;
ax.XAxis.FontSize = 12;
ax.YAxis.FontSize = 12;
ax.ZAxis.FontSize = 12;
set(gcf,'units','normalized','outerposition',[0 0 1 1])

5. The code below uses the exp command to initialize the special complex number 𝑒 𝑗𝜃 in
polar form, i.e., 𝑧 = 𝑟𝑒 𝑗𝜃 , where 𝑟 = 1.
clc; clear all; close all
theta = 0;
r = 1;
z1 = r*exp(1j*theta);
plot(real(z1), imag(z1), 'ro','LineWidth',3);
% The below mentioned commands are used to improve the visual appearance of
% the figure for better understanding.
title('Plotting e^{j\theta} in polar representation')
grid on; axis square;
xlabel('\Re (e^{j\theta})','FontSize',20)
ylabel('\Im (e^{j\theta})','FontSize',20)
axis([-1.1 1.1 -1.1 1.1])
yline(0,'LineWidth',2)
xline(0,'LineWidth',2)
ax = gca;
ax.XAxis.FontSize = 12;
ax.YAxis.FontSize = 12;
set(gcf,'units','normalized','outerposition',[0 0 1 1])

a. Copy code in a new m-file and run the code. Visualize the value of 𝑒 𝑗𝜃 for 𝜃 = 0.
b. Update the code to display values of 𝑒 𝑗𝜃 for 𝜃 = 0𝑜 , 90𝑜 , 180𝑜 , 270𝑜 in a single
figure.
c. Update the code to display all values of 𝑒 𝑗𝜃 in a single figure for 𝜃 in range [0, 360]
with ∆𝜃 = 2.

Semester: Fall-2023 Lab Course Instructor: Dr. Junaid Mir


Session: 2K20 Designed by: Dr. Junaid Mir and Prof. Dr. Obaid Ullah

You might also like