SIGNALS AND SYSTEM LAB #1
TOPIC: Introduction to MATLAB and Signal Plotting
Shien-Ming Wu School of Intelligent Engineering, SCUT
Spring 2025
SYLLABUS:
MATLAB Basics: Variables, vectors, matrices, and arithmetic operations.
Signal Generation: Impulse, step, ramp, exponential, and sinusoidal signals.
Plotting Techniques: 2D and 3D plots for signal visualization.
OBJECTIVES:
Introduction to MATLAB.
(i) To define and use variables and functions in MATLAB.
(ii) To define and use vectors, matrices and polynomials in MATLAB.
(iii) To study various MATLAB arithmetic operators and mathematic function.
(iv)To create and use m-files.
(v) Plot the basic signals (Impulse, Step function and Ramp function)
(vi)To create 2-D and 3-D plots.
SOFTWARE USED:
MATLAB 2021b
THEORY:
MATLAB is a programming language developed by Math Works. It started out as
a matrix programming language where linear algebra programming was simple.
MATLAB (matrix laboratory) is a fourth-generation high-level programming language
and interactive environment for numerical
computation, visualization and
programming.
MATLAB is developed by Math Works. It allows matrix manipulations; plotting
of functions and data; implementation of algorithms; creation of user interfaces;
interfacing with programs written in other languages, including C, C++, Java, and
FORTRAN; analyze data; develop algorithms; and create models and applications.
It has numerous built-in commands and math functions that help you in
mathematical calculations, generating plots, and performing numerical methods.
Impulse Function
The impulse function is defined as:
+∞
∫
πΏ(π‘)dπ‘ = 1
(1.1)
−∞
and πΏ(π‘) = 0 when π‘ ≠ 0.
That is the impulse function has zero amplitude everywhere expect at t = 0.
Step Function
The unit step function is defined as:
1,
π’(π‘) = {
0,
π‘≥0
π‘<0
(1.2)
INTRODUCTION TO MATLAB ENVIRONMENT:
•
Command Window:
Whenever MATLAB is invoked, the main window called command window is
activated. The command window displays the command prompt’>>’ and a cursor
where commands are entered and are executed instantaneously.
•
Command History Window:
Command history window consists of a list of all the commands that are entered at
the command window. These commands remain in the list until they are deleted.
Any command may be executed by selecting and double clicking it with the mouse.
•
Workspace:
A workspace is a collection of all the variables that have been generated so far in
the current MATLAB session and shows their data type and size. All the
commands executed from Command Window and all the script files executed from
the Command Window share common workspace, so they can share all the
variables.
•
Current Directory:
The Current Directory window contains all the files and folders present in the
Current Directory. To run any file, it must either be in the Current Directory or on
the search path.
•
Edit Window:
An Edit Window is used to create a new program file, or to modify existing files.
In this window, programs can be written, edited and saved. The programs written
using the MATLAB editor are automatically assigned an extension (.m) by the
editor and are known as M- files.
•
Figure Window:
A Figure Window is a separate window with default white background and is used
to display MATLAB graphics. The results of all the graphic commands executed
are displayed in the figure window.
BASIC OPERATIONS IN MATLAB
MATLAB allows two different types of arithmetic operations –
β’
Matrix arithmetic operations
β’
Array arithmetic operations
Matrix arithmetic operations are same as defined in linear algebra. Array
operations are executed element by element, both on one dimensional and multidimensional array. The matrix operators and arrays operators are differentiated by the
period (.) symbol. However, as the addition and subtraction operation is same for
matrices and arrays, the operator is same for both cases.
•
Representation of variables as matrices
In MATLAB environment, every variable is an array or matrix.
Variables can be defined in MATLAB in the following ways:
x = 3 %defining x and initializing it with a value
x = sqrt(16) %defining x and initializing it with an expression
The clear command deletes all (or the specified) variable(s) from the memory.
clear x %it will delete x, won't display anything
clear all%it will delete all variables in the workspace
A vector is a one-dimensional array of numbers. MATLAB allows creating two
types of vectors:
β’
Row vectors
β’
Column vectors
Row vectors are created by enclosing the set of elements in square brackets,
using space or comma to delimit the elements.
For example,
r = [7 8 9 10 11]
Column vectors are created by enclosing the set of elements in square brackets,
using semicolon(;) to delimit the elements.
For example,
r = [7;8;9;10;11]
A matrix is a two-dimensional array of numbers.
In MATLAB, a matrix is created by entering each row as a sequence of space or
comma separated elements, and end of a row is demarcated by a semicolon. For
example a 3-by-3 matrix is created as:
a = [1 3 5; 2 4 6; 7 8 10]
a = 3×3
1
3
5
2
4
6
7
8
10
You can also define each line with individual lines of code and separate them with
line breaks.
a = [1 3 5
246
7 8 10]
a = 3×3
1
3
5
2
4
6
7
8
10
Another way to create a matrix is to use functions such as ones, zeros, or rand.
For example, create a 5 × 1 column vector composed of zeros.
z = zeros(5,1)
z = 5×1
0
0
0
0
0
The following table gives brief description of the operators −
Operator
Description
Addition or unary plus. A+B adds the values stored in variables A and
+
B. A and B must have the same size, unless one is a scalar. A scalar can
be added to a matrix of any size.
Subtraction or unary minus. A-B subtracts the value of B from A. A
-
and B must have the same size, unless one is a scalar. A scalar can be
subtracted from a matrix of any size.
*
/
./
.\
.^
.'
•
Matrix multiplication. C = A*B is the linear algebraic product of the
matrices A and B.
Slash or matrix right division. B/A is roughly the same as B*inv(A).
More precisely, B/A = (A'\B')'.
Array right division. A./B is the matrix with elements A(i,j)/B(i,j). A
and B must have the same size, unless one of them is a scalar.
Array left division. A.\B is the matrix with elements B(i,j)/A(i,j). A and
B must have the same size, unless one of them is a scalar.
Array power. A. ^B is the matrix with elements A (i,j) to the B(i,j)
power. A and B must have the same size, unless one of them is a scalar.
Array transpose. A' is the array transpose of A. For complex matrices,
this does not involve conjugation.
Functions for Arithmetic Operations:
Apart from the above-mentioned arithmetic operators, MATLAB provides the
following commands/functions used for similar purpose
Function
Description
uplus(a)
Unary plus; increments by the amount a
plus (a,b)
Plus; returns a + b
uminus(a)
Unary minus; decrements by the amount
a
minus(a, b)
Minus; returns a - b
times(a, b)
Array multiply; returns a.*b
rdivide(a, b)
Right array division; returns a ./ b
ldivide(a, b)
Left array division; returns a.\ b
mrdivide(A, B)
mldivide(A, B)
Solve systems of linear equations xA =
B for x
Solve systems of linear equations Ax =
B for x
power(a, b)
Array power; returns a.^b
mpower(a, b)
Matrix power; returns a ^ b
•
The M Files
MATLAB allows writing two kinds of program files
β’
Scripts − script files are program files with .m extension. In these files, you
write series of commands, which you want to execute together. Scripts do not
accept inputs and do not return any outputs. They operate on data in the
workspace.
β’
Functions − functions files are also program files with .m extension.
Functions can accept inputs and return outputs. Internal variables are local to
the function.
You can use the MATLAB editor or any other text editor to create your .m files.
EXPERIMENT 1:
Matrices & Arrays
β’
A single arithmetic operator
MATLAB allows you to use a single arithmetic operator or function to handle all
values in a matrix.
a = [1 3 5; 2 4 6; 7 8 10]
a + 10
Results:
ans = 3×3
11
13
15
12
14
16
17
18
20
β’
Transpose a matrix
To transpose a matrix, use single quotes ('):
a'
Results:
ans = 3×3
1
2
7
3
4
8
5
6
10
β’
Matrix multiplication
You can use the * operator to perform standard matrix multiplication, which
calculates the inner product between rows and columns. For example, multiplying a
confirmation matrix by its inverse matrix can return the identity matrix:
p = a*inv(a)
Results:
p = 3×3
1.0000
0.0000
-0.0000
0
1.0000
-0.0000
0
0.0000
1.0000
Please note that p is not an integer matrix. MATLAB stores numbers as floatingpoint values, and arithmetic operations can distinguish subtle differences between
actual values and their floating-point representations. Use the format command to
display more decimal places:
format long
p = a*inv(a)
Results:
p = 3×3
0.999999999999996
0.000000000000007
-0.000000000000002
0
1.000000000000000
-0.000000000000003
0
0.000000000000014
0.999999999999995
β’
Concatenation
Concatenation is the process of joining arrays in order to form larger arrays. In
fact, the first array is constructed by concatenating its individual elements. Pairwise
square brackets [] are concatenated operators.
A = [a,a]
Results:
A = 3×6
1
3
5
1
3
5
2
4
6
2
4
6
7
8
10
7
8
10
Using commas to concatenate arrays next to each other is called horizontal
concatenation. Each array must have the same number of rows. Similarly, if each array
has the same number of columns, you can use a semicolon to concatenate vertically.
A = [a;a]
Results:
A = 6×3
1
3
5
2
4
6
7
8
10
1
3
5
2
4
6
7
8
10
β’
Complex number
Complex numbers contain real and imaginary parts, and the imaginary unit is the
square root of -1.
sqrt(-1)
Results:
ans =
0.0000 + 1.0000i
To represent the imaginary part of a complex number, use i or j.
c = [3+4i, 4+3j; -i, 10j]
Results:
c = 2×2 complex
3.0000 + 4.0000i
4.0000 + 3.0000i
0.0000 - 1.0000i
0.0000 +10.0000i
EXPERIMENT 2:
2D/3D Plots
β’
2-D plot
t=-2:0.01:10;
impulse = t==0;
unitstep = t>=0;
figure(1)
plot(t, impulse, "LineWidth",2, "Color","black")
ylim([-0.05,1.05])
title('Impulse function')
figure(2)
plot(t, unitstep, "LineWidth",2, "Color","black")
ylim([-0.05,1.05])
title('Unit step function')
ramp = t.*unitstep;
figure(3)
plot(t,ramp, "LineWidth",2, "Color","black")
ylim([-0.5,10.5])
xlabel('Time')
ylabel('Amplitude')
title('Ramp function')
Results:
Define x as a vector of linearly spaced values between 0 and 2π. Use an increment
of π/10 between the values. Define y as sine values of x.
clc
clear all
x=0:pi/100:2*pi;
y=sin(x);
plot(x,y,'LineWidth',2, 'Color','black');
title('sin(t)');
xlabel('Time');
ylabel('Amplitude');
Results:
β’
3-D plot
A three-dimensional plot may refer to a) A graph or plot embedded into a threedimensional space b) The plot of a function of two variables, embedded into a threedimensional space
clc
clear all
t=-4:0.01:4;
x=t.^2;
y=4*t;
plot3(x,y,t, 'LineWidth',2,'Color','black')
grid on
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
title('3D Plot')
Results:
PRECAUTIONS:
1) Program must be written carefully to avoid errors.
2) Programs can never be saved as standard function name.
3) Functions in MATLAB are case sensitive so commands must be written in proper
format.
EXPERIMENT 3
Advanced Task: MATLAB Thought Questions for Physics Applications
After completing Experiment 1 (Matrices & Arrays) and Experiment 2
(1D/2D/3D Plots), select one of the following problems to solve within 30 minutes. If
you finish early, try the bonus extension questions for further exploration. Each
problem is designed to reinforce MATLAB operations while introducing important
physical concepts.
β’ Problem 1: Damped Oscillations in Physics
Damped oscillations appear in many physical systems, such as mechanical vibrations,
RLC circuits, and quantum wavefunctions. The oscillatory behavior is modified by
a damping factor, which represents energy loss in the system.
The signal is given by:
π₯(π‘) = π΄π −πΌπ‘ π ππ(ππ‘)
where:
•
A is the amplitude
•
πΌ is the damping coefficient (higher values lead to faster decay),
•
ω is the angular frequency.
Task:
1. Define t in MATLAB from 0 to 10 with a step size of 0.01.
2. Plot π₯(π‘) for different values of α (0.1, 0.5, 1), keeping π΄ = 1 and π = 2π
3. Compare the decay rates and describe how damping affects oscillations.
Bonus Extension:
Energy Dissipation -- Compute and plot the envelope π΄π −πΌπ‘ , which represents the
energy loss over time. How does increasing α affect system stability?
β’ Problem 2: Electromagnetic Wave Polarization Matrix
In electromagnetic waves, polarization describes the orientation of the electric
field. The Jones matrix represents polarization states mathematically:
πΈπ₯
πΈ = [πΈ ]
π¦
A 2×2 matrix can describe transformations such as phase shifts or birefringence
(materials that affect different polarizations differently). The eigenvalues and
determinant of this matrix reveal important properties:
•
Eigenvalues correspond to characteristic polarization modes.
•
Determinant indicates if the transformation preserves signal strength
(determinant = 1) or alters it.
Task:
1. Define a 2×2 complex matrix πΈ representing an electric field transformation.
Example:
3 + 4π 2 − π
]
1 + 2π 4 + 3π
2. Compute its eigenvalues and eigenvectors using eig(E).
πΈ=[
3. Compute its determinant using det(E).
Bonus Extension:
Singular or Non-Singular? – Change elements in E and observe when det(E) = 0.
What does this imply for wave transmission?
β’ Problem 3: 3D Motion of a Charged Particle in a Magnetic Field
A charged particle moving in a uniform magnetic field undergoes helical motion
due to the Lorentz force. This motion is described by:
π₯(π‘) = π΄πππ (ππ‘)
π¦(π‘) = π΄π ππ(ππ‘)
π§(π‘) = π΅π‘
where:
•
A is the radius of the circular motion,
•
ω is the angular velocity (determined by charge and field strength),
•
B is the drift velocity along the z-axis.
Task:
1. Define t in MATLAB from 0 to 10 with a step size of 0.05.
2. Set π΄ = 2, π΅ = 0.5, and π = 1. Compute π₯(π‘), π¦(π‘) and π§(π‘).
3. Plot the 3D trajectory using plot3(x, y, z).
4. Modify B and observe how it affects the trajectory.
Bonus Extension
Effect of an Electric Field – Modify π₯(π‘) to simulate the influence of an electric field
along the π₯-direction. Does the trajectory change?
Each task should take less than 30 minutes, with bonus extensions adding extra
depth. These problems reinforce MATLAB matrix operations, plotting, and physics
simulations while staying within the content of the first two MATLAB lessons.
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )