EXPERIMENT 1
INTRODUCTION ON SIGNALS AND SYSTEMS
1.0
OBJECTIVES:
After completing this section you will be able to :
2.0
1.1
1.2
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:
x1 = t. ^ 2;
x2 = sin ( 10.*t);
x = x1.*x2;
ENT 281
ENT 281
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)
ENT 281
3.1
OVERLAY PLOTS
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;
Example 3.1.2
ENT 281
f ( x ) e x 10 sin( x ) ,
x = 0:0.1:20;
% create vector x
y = exp(0.1.*x).*sin(x);
% calculate y
plot (x,y)
% plot x vs. y
% label y-axis
% put a title
Example 3.1.3
f ( x ) e x 10 sin( x ) ,
fplot (exp(0.1.*x).*sin(x),[0,20])
0 x 20 , using fplot
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
>> Z = x + 2i ;
>> F = 2*(Z+4)./(Z-1);
>> grid
>> xlabel (x)
>> ylabel (phase in degrees)
3.2
INTRODUCTION TO SIGNALS
ENT 281
x (t)
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.1)
(3.2)
To explore even and odd signals in continuous time, let us create one
even and one odd signal. The even one will be a cosine and the odd will be a
sine, both will have frequency of 1 Hz, defined over a time axis extending from
-1 to 1 with a sampling interval of 0.01s, each totaling 201 points or samples.
ENT 281
f=1;
t=-1:0.01:1;
xe=cos(2*pi*f*t);
xo=sin(2*pi*f*t);
We can now see what happens to our functions under time reversal. We
first examine the even one, and then the odd one.
subplot(2,2,1);plot(t,xe);
subplot(2,2,2);plot(-t,xe);
subplot(2,2,3);plot(t,xo);
subplot(2,2,4);plot(-t,xo);
What do you observe? How do you interpret the pictures you got?
3.2.2 PERIODIC SIGNALS
Periodic signals can be generated by square waves and triangular waves.
To
Period, T = 0.2s
* f = 1/T ;
= 2f = 2/T
>> A = 1;
% Amplitude
>> w0 = 10*pi;
% Fundamental frequency
% Duty cycle
>> t = 0: .001 : 1;
ENT 281
>> x = A*square(omega*n);
>> stem (n,x)
3.2.3 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:
B*exp (-a*t);
B*exp (a*t);
Example
>> B = 5;
>> a = 6;
>> t = 0: .001: 1;
>> x = B*exp (-a*t);
% Decaying exponential
ENT 281
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
% 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;
3.2.5
Step Function
A unit-amplitude step function is generated by unity
u = [zeros (1, 50), ones (1, 50)];
Discrete-time Impulse Function
Delta = [Zeros (1, 49), 1, zeros (1, 49)];
Ramp Function
To generate a ramp sequence, we simply write
ramp = 0: .1: 10
ENT 281
Example
Try these commands and observe the output
x(t) =
A,
0 t0.5
t0.5 <
% begin at t = 0.5
>> u = u1 u2;
>> plot(t,u)
Example
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)
Figure 1
10
ENT 281
3.3
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
3.4.2
plot
stem
loglog
semilogx
semilogy
bar
Bar graph
errorbar
hist
Histogram
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
grid
gtext
text
axis
figure
figure (n)
hold on
hold off
close (n)
11
ENT 281
String modifiers can be used to change color, data point, and line styles.
Colors
Point style
Line style
b blue
. point
- solid
g green
o circle
: dotted
r red
x x-mark
-. dashdot
c cyan
+ plus
-- dashed
m magenta * star
y yellow
s square
k black
d diamond
(none) no line
v triangle (down)
^ triangle (up)
< triangle (left)
> triangle (right)
p pentagram
h hexagram
3.5
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
polyval(p,x)
conv(p1,p2)
deconv(p1,p2)
poly2str(p,s)
poly(r)
12
ENT 281
Plot the following signal on the same graph and determine whether its odd or
even signal. -2 t 2
* use subplot command
(i) x(t)=4t
(ii) x(t)=5cos(3t)
(iii) x(t)=5sin(3t)
2.
Plot the following signals on the same graph and identify whether its periodic or
non periodic signal.
(i) x(t) = cos (10 t + 8 sin (t)),
4.
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)
(ii)
Repeat (i) for values of a equal to -0.5,-1.0 and -1.5, again using
the time scale -3 to +3.
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. Plot the three signal in one graph.
13
ENT 281
5.
Figure 2
Consider the signal in Figure 2:
(a)
(b)
14