Lab Manual EKT230/4
Signals & Systems
LABORATORY 1
REVIEW ON MATLAB AND INTRODUCTION ON
SIGNALS AND SYSTEMS
1.0
OBJECTIVES:
After completing this section you will be able to :
2.0
1.1
Generate basic signals.
1.2
Differentiate type of signaling generated.
TOOLS
The MATLAB Signal Processing Toolbox.
3.0
M-FILES
It is useful for a large number of commands. We can write and save our commands in
script files called M-Files. When an M-File is run, MATLAB sequentially executes the
commands found in the file. The advantage of having M-File is that commands are saved
and can be easily modified without retyping the entire list of commands.
Example 3.0.1
Start by creating an M-File file:
Type this text in new M-File
t = linspace(1,3,200)
%---- to create 200 points between 1 to 3
x1 = t. ^ 2;
%---- signal x1,
x2 = sin ( 10.*t);
%---- signal x2,
x = x1.*x2;
%---- Product of signals.
1
Lab Manual EKT230/4
Signals & Systems
Then, Save As ( to (C:) Directory ) as Revp1.m (as File name)
2
Lab Manual EKT230/4
Signals & Systems
Example 3.0.2
Consider the signal,
x(t) = t2 sin (10t), 0 ≤ t ≤ 3
___________
(i)
We would like to plot this signal. To generate the signal in (i), two intermediate signals are
defined.
x1(t) = t2 , and x2(t) = sin (10t)
___________
(ii)
Then the signal in (i) is the product of the signals in (ii).
Solution to the above example;
clear
% generate signal;
type Revp1 .m
plot (t,x)
xlabel (‘time’)
ylabel (‘x’)
title (‘Product of Function’)
% recall from m.files
% Plot Signal
% Label x-axis
% Label y-axis
% Puts a title on the plot
3
Lab Manual EKT230/4
3.1
Signals & Systems
OVERLAY PLOTS
There are three different ways of generating overlay plots in MATLAB:
the plot, hold, and line commands
Method 1: Using the Plot command
For example, If we have three sets of data, ( x1, y1), ( x 2, y 2), and ( x3, y3) ,
the command plot ( x1, y1, x 2, y 2, '' , x3, y3, ' o' ) ;
Plots ( x1, y1) , with a solid line, ( x 2, y 2) , with a dotted line, and ( x3, y3) as
uncorrected points marked by small circles ‘o’, all on the same graph.
Consider the three signals below and using plot command to generate overlay plots.
3
y1 sin t ,
y2 t
and
y3 t
t
t5
3!
5!
Plot 100 points vector, sets the x-axis from 0 to 5 and y-axis from -1 to 5.
Example 3.1.1
>> clear
>> t = linspace (0, 2.*pi, 100);
>> y1 = sin (t);
% generate vector t
y2 = t;
>> y3 = t-(t.^3)./6 + (t.^5)/120;
>> plot (t, y1, t, y2, ‘--‘, t, y3, ‘o’)
>> axis ( [0 5 -1 5] )
% Zoom in new axis limits
>> xlabel (‘t’)
>> ylabel (‘Approximations of sin (t)’)
>> title (‘Fun with sin (t)’)
>> text (3.5,0, ‘sin (t)’)
>> gtext (‘Linear approximation’)
>> gtext (‘First 3 terms’)
>> gtext (‘in Taylor Series’)
“gtext” writes the specified string at a location clicked with the mouse in the graphics
window. So, after hitting return at the end of gtext command, go to the graphic window
and click a location.
4
Lab Manual EKT230/4
Signals & Systems
Example 3.1.2
f ( x) e x 10 sin( x) ,
x = 0:0.1:20;
0 ≤ x ≤ 20 , using plot command
% create vector x
y = exp(-0.1.*x).*sin(x);
% calculate y
plot (x,y)
% plot x vs. y
xlabel (‘Time (t) in seconds’) % label x-axis
ylabel (‘The Response Amplitude in mm’)
title (‘A Simple 2-D Plot’)
% label y-axis
% put a title
Example 3.1.3
f ( x) e x 10 sin( x) ,
0 ≤ x ≤ 20 , using fplot
fplot (‘function’,[Xmin Xmax])
fplot (‘exp(-0.1*x).*sin(x)’,[0,20])
xlabel (‘x’),ylabel(‘f(x)=e^{x/10}sin(x)’)
title (‘A function plotted with fplot’)
Example 3.1.4
In this example, the magnitude of “F(Z)” is manipulated by MATLAB program.
F (Z) =
2( Z 4)
Z 1
along the path Z = x + j2
; -6 ≤ x ≤ 4. Create 100 points between -6 to 4.
Solution Example 3.1.4
>> clear
>> x = linspace (-6 , 4,100) ;
% Create a 100 point independent variable
>> Z = x + 2i ;
% now the range of Z has been defined
>> F = 2*(Z+4)./(Z-1);
% Calculate the function for each value of Z
>> plot (x, 180*angle (F)/pi)
% plot phase in degrees
>> grid
>> xlabel (‘x’)
>> ylabel (‘phase in degrees’)
5
Lab Manual EKT230/4
3.2
Signals & Systems
INTRODUCTION ON SIGNALS
A signal is formally defined as a function of one or more variables that conveys
information on the nature of a physical phenomenon.
The function which is chosen to describe a signal is called the representation of
the signal.
A signal that depends on the discrete variable n and that model a physical
variable that evolves in discrete time is called a discrete-time signal.
A signal that depends on the continuous variable t and that model a physical
variable that evolves in continuous time is called a continuous-time signal.
A system is formally defined as an entity that manipulates one or more signals to
accomplish a function, thereby yielding new signals.
The interaction between a system and its associated signal is illustrated
schematically in figure below;
Input signal
x (t)
y (t)Output Signal
H
If the input signal and output signals of a system are continuous time signal, then
the system is called a continuous-time system.
If the input signal and output signals of a system are discrete-time signals, then
the system is called a discrete-time system.
3.2.1
PERIODIC SIGNALS
Periodic signals can be generated by square waves and triangular waves.
To
generate a square waves signals, use the basic command:
A*square(w0*t + rho);
A is an amplitude, w0 is a fundamental frequency measured rad/sec and rho is a duty
cycle for which the signal is positive.
Example 3.2.1.1
Use the following set of commands for generating:
(i) Square waves
A = 1 and
Period, T = 0.2s
* f = 1/T ;
= 2πf = 2/T
>> A = 1;
% Amplitude
>> w0 = 10*pi;
% Fundamental frequency
>> rho = 0.1;
% Duty cycle
>> t = 0: .001 : 1;
% To create 1000 time vector points
>> sq = A*square(w0*t + rho);
6
Lab Manual EKT230/4
Signals & Systems
>> plot (t,sq)
>> axis ( [ 0 1 -1.1 1.1 ] ) % Sets graph axes: axis([xstart xend ystart yend])
Explanation: The plot command is used to view the square waves : the command
plot draws lines connecting the successive values of the signal and thus gives
the appearance of a continuous-time signal.
(ii) Triangular waves
A*sawtooth (w0*t,w);
>> A = 1;
>> w0 = 10*pi;
>> w = 0.5;
>> t = 0: .001 : 1;
>> tri = A*sawtooth(w0*t,w);
>> plot (t,tri)
Explanation: The plot command is used to view the triangular waves : the
command plot draws lines connecting the successive values of the signal and
thus gives the appearance of a continuous-time signal.
To visualize a discrete-time signal, used stem command .Specifically, stem (n,x)
depicts the data contained in vector x as a discrete-time signal at the time values
defined by n. The vector n and x must have compatible dimensions.
Example 3.2.1.2
The discrete-time square wave is generated by using the following commands;
>> A = 1;
>> omega = pi/4;
>> n = -10: 10;
% Starting point from -10 to 10
>> x = A*square(omega*n);
>> stem (n,x)
3.2.2
EXPONENTIAL SIGNALS
Exponential signal is written as x(t) = Beat , where both B and a are parameters.
The parameter B is the amplitude of the exponential signal measured at time t = 0.
Depending on whether the other parameter a is positive or negative, its identify
two special cases:
Decaying exponential, for it which a < 0,
B*exp (-a*t);
Growing exponential, for it which a > 0,
B*exp (a*t);
7
Lab Manual EKT230/4
Signals & Systems
Example 3.2.2.1
>> B = 5;
>> a = 6;
>> t = 0: .001: 1;
>> x = B*exp (-a*t);
% Decaying exponential
>> plot (t,x)
Explanation: The plot command is used to view the decaying exponential signal.
3.3.3
SINUSOIDAL SIGNALS
A*cos (w0*t + phi) ;
A*sin (w0*t + phi);
for continuous
(replace ‘t’ with ‘n’ for discrete)
These two commands are basically to generate the sinusoidal signals. A cosine
signal of amplitude A, frequency w0 (measured in radians per second), and phase
angle phi (in radians) is obtained by using the command.
Example 3.3.3.1
% generate of a sinusoidal sequence for discrete signal
>> n = 0:40;
>> f = 0.1;
>> phase = 0;
>> A=1.5;
>> arg = (2*pi*f*n) – phase;
>> x = A*cos(arg);
>> clf;
% clear old graph
>> stem (n,x);
% plot the generated sequence
>> axis ([0 40 -2 2]);
>> grid;
>> title (‘Sinusoidal Sequence’);
>> xlabel (‘Time Index n ‘);
>> ylabel (‘Amplitude’);
>> axis;
8
Lab Manual EKT230/4
3.3.4
Signals & Systems
STEP, IMPULSE, AND RAMP FUNCTIONS
3.3.4.1 Step Function
A unit-amplitude step function is generated by unity
u = [zeros (1, 50), ones (1, 50)];
3.3.4.2 Discrete-time Impulse Function
Delta = [Zeros (1, 49), 1, zeros (1, 49)];
3.3.4.3 Ramp Function
To generate a ramp sequence, we simply write
ramp = 0: .1: 10
Example 3.3.4.1
Try these commands and observe the output
x(t) =
0≤ ׀t ≤ ׀0.5
A,
׀t > ׀0.5
0
>> t = -1: 1/500 : 1
% time running from 1 second to 1 second
>> u1 =[zeros(1,250), ones(1,751)]; % beginning at t = -0.5 second
>> u2 =[zeros(1,751),ones(1,250)]; % begin at t = 0.5
>> u = u1 – u2;
% produce a rectangular pulse of unit amplitude and unit
duration centered on the origin.
>> plot(t,u)
Example 3.3.4.2
Try this command and generate the signal as shown in Figure 1 below;
>> dt = 0.05;
% time increment for plotting
>> t1 = [-1 : dt : -dt];
% first interval
>> x1 = ones (size (t1));
% signal on first interval
>> t2 = [0: dt : 1];
% second interval
>> x2 = 1-t2;
% signal on 2nd interval
>> t3 = [1+dt : dt : 2];
% third signal
>> x3 = 2*ones(size(t3));
% signal on 3rd interval
>> t4 = [ 2+dt: dt: 4];
% fourth interval
>> x4 = (t4-3);
% signal on 4th interval
>> t = [ t1, t2, t3, t4]; % total time interval
>> x = [ x1, x2, x3, x4];
% total signal
>> plot (t,x)
9
Lab Manual EKT230/4
Signals & Systems
Figure 1
3.3
COMMANDS RELATED SIGNALS TO SYSTEMS
The following commands are organized by topics in signals and systems. Each of
these commands has a number of options that extend its usefulness.
3.4
PLOTTING
Plotting is a basic skill in MATLAB that will be used frequently. Basically, a signal
can be represented by a vector that represents values of the signal at specified
point in time.
3.4.1
Simple plotting commands
The simple 2D plotting commands include
plot
Plot in linear coordinates as a continuous function
stem
Plot in linear coordinates as discrete samples
loglog
Logarithmic x and y axes
semilogx
Linear y and logarithmic x axes
semilogy
Linear x and logarithmic y axes
bar
Bar graph
errorbar
Error bar graph
hist
Histogram
10
Lab Manual EKT230/4
3.4.2
Signals & Systems
Customization of plots
There are many commands used to customize plots by annotations, titles,
axes labels, etc.
A few of the most frequently used commands are
xlabels
Labels x-axis
ylabel
Labels y-axis
title
Puts a title on the plot
grid
Adds a grid to the plot
gtext
Allows positioning of text with the mouse
text
Allows placing text at specified coordinates of the plot
axis
Allows changing the x and y axes
figure
Create a figure for plotting
figure (n)
Make figure number n the current figure
hold on
Allows multiple plots to be superimposed on the same axes
hold off
Release hold on current plot
close (n)
Close figure number n
subplot (a,b,c) Create an a x b matrix of plots with c the current figure
orient
3.5
Specify orientation of a figure
Polynomials
Polynomials arise frequently in systems theory. MATLAB represents polynomials
as row vectors of polynomial coefficients. For example, the polynomial s2 + 4s – 5
is represented in MATLAB by the polynomial >> p = [1 4
-5]. The following is a
list of the more important commands for manipulating polynomials.
roots(p)
Express the roots of polynomial p as a column vector.
polyval(p,x)
Evaluate the polynomial p at the values contained in the vector x.
conv(p1,p2)
Compute the product of the polynomials p1 and p2
deconv(p1,p2)
Compute the quotient of p1 divided by p2
poly2str(p,’s’)
Display the polynomial as an equation in s
( asn+bsn-1+csn2+……+……)
poly(r)
Compute the polynomial given a column vector of roots r
11
Lab Manual EKT230/4
Signals & Systems
TASKS OF THE DAY
Q 1.1 Plot the following signals on the same graph
(i) x(t) = cos (10 πt + β sin (πt)),
β = 3, 8 0 ≤ t ≤ 1 for 200 points vectors
(ii) x(t) = cos (10 πt + A ( t/4) ) ,
A = 3, 8
* using subplot command.
Q 1.2 Consider the signal
x(t) = A sin (t) + B sin (wt + θ )
set A = 0.9 ; B = 2.5 ; 0 ≤ t ≤ 1 for 100 points vectors
(i) Write a M-File to plot this signal.
(ii) Investigate the waveforms obtained by varying the phase as 0 ≤ θ ≤ 2π.
Q 1.3 This exercise examines the properties of the exponential and sinusoidal signals in
both continuous and discrete forms.
(a) The Continuous Signal, x(t) = 2eat
(i)
For values of ‘a’ equal to 0.5,1.0 and 1.5, plot the corresponding
signals all on the same graph using a timescale -3 to +3.
(ii)
Repeat (i) for values of ‘a’ equal to -0.5,-1.0 and -1.5, again using
the time scale -3 to +3.
(b) The Discrete Signal, x(n) = 2eanT with T = 0.25
(i)
For values of ‘a’ equal to 0.5, 1.0 and 1.5, plot the corresponding
signals using the command ‘stem’ over a range of ‘n’ from n = -12
to n = +12. Use ‘subplot’ to show the three plots on one screen
and for comparison purposes to use the same vertical scales by
use of ‘axis’.
12
Lab Manual EKT230/4
Signals & Systems
Q 1.4
Figure 2
Consider the signal in Figure 2:
(a)
Find representation for this signal.
(b)
Plot this signal using MATLAB.
13
© Copyright 2026 Paperzz