Sei sulla pagina 1di 4

The Hong Kong Polytechnic University

Department of Electronic and Information Engineering


Subject: Linear Systems
LS001: Fundamentals of Signals
In this experiment, you will learn how to represent, manipulate, and analyze basic signals in
MATLAB. The objectives of this laboratory are
(1) to study how to construct signals in MATLAB,
(2) to study the MATLAB function required for generating and plotting discrete time sinusoidal
signals, and
(3) to use ezplot to plot and analyze continuous-time signals.

1. Basic Signal Representations
(a) Use MATLAB to create the following discrete-time signal
| |


=
otherwise , 0
3 3 , 2 n n
n x
>> n=[-3:3];
>> x=2*n;
Note:
(i) All vectors represented in MATLAB are indexed starting with 1, and
(ii) The semicolons at the end of each command will suppress unnecessary echoing.
Use stem(n,x) to plot this signal.
(b) If you want to plot a signal over the range 6 n 6, you can extend the index vector n as
follows:
>> n = [-6:6]
then either add additional elements to x for these new samples:
>> x = [0 0 0 x 0 0 0];
or use the function zeros
>> x = [zeros(1,3) x zeros(1,3)];
(c) Suppose you want to define x
1
[n] to be the discrete-time unit impulse function and x
2
[n] to be a
time-advanced version of x
1
[n], i.e., x
1
[n]=[n] and x
2
[n]=[n+2]. The signal can be created as
follows:
>> nx1 = [0:10];
>> x1 = [1 zeros(1,10)];
>> nx2 = [-5:5];
>> x2 = [zeros(1,3) 1 zeros(1,7)];
Plot these two signals using stem(nx1, x1) and stem(nx2, x2).
(d) In MATLAB, continuous-time signals can be represented by (1) using the Symbolic Math
Toolbox, or (2) using vectors with closely spaced samples of the signals in time. To create vectors
with closely spared time indices:
(i) use the colon operator with the optional step argument, or
(ii) use the linspace function.

Try the following commands to create a vector of an interval of 5 t 5 in steps of 0.1 seconds:
>> t = [-5:0.1:5];
>> t = linspace(-5,5,101);
KML/LS001: Signals
1
(e) Use the following commands to plot the signal x = sin(t/4) for 5 t 5
>> t = [-5:0.1:5];
>> x = sin(pi*t/4);
>> plot(t,x);
What is the difference between stem and plot?
(f) Try the following commands:
>> n = [0:32];
>> x = exp(j*(pi/8)*n);
What are the functions of the commands?
To plot complex signals, the MATLAB functions real, imag, abs, and angle can be used. Use
stem to plot each of the functions of the complex signal x.
Note: angle is the phase of a complex number in radians.
(g) If two vectors have the same time origins and the same number of elements, term-by-term
operations can be performed. Investigate the following commands and the corresponding results:
>> x1 = sin((pi/4)*[0:15]);
>> x2 = cos((pi/7)*[0:15]);
>> y1 = x1 + x2;
>> y2 = x1.*x2;
>> y3 = x1./x2;
>> y4 = 2*x1;
>> y5 = x1.^3;
What happens if we type the command below?
>> x1*x2
(h) MATLAB also includes several commands to help label plots appropriately. Try the following
commands:
>> n = [0:32];
>> x = exp(j*(pi/8)*n);
>> stem (n, angle(x));
>> title (Phase of exp(j*(pi/8)*n))
>> xlabel (n(samples));
>> ylabel (Phase of x[n] (radius));
>> print
Note: the print command allows you to print out the current plot.
(i) There are two types of M-files: functions and command scripts.
(1) A command script is a text file of MATLAB commands whose filename ends in .m. If you
type the name of this file, the commands contained in the file will be executed. Create a
command script for the commands in the previous step
n = [0:32];
x = exp(j*(pi/8)*n);
stem (n, angle(x));
title (Phase of exp(j*(pi/8)*n))
xlabel (n(samples));
ylabel (Phase of x[n] (radius));
(2) A M-file implementing a function is a text file with a title ending in .m whose first word is a
function.
a. Try the following function:
function [y,z] = foo(x)
y = 2*x;
z = (5/9)*(x-32);
KML/LS001: Signals
2
b. Run the function as follows:
>> [y,z] = foo (-40)

2. Discrete-Time Sinusoidal Signals
Discrete-time complex exponentials, i.e e
+iw
, play an important role in the analysis of discrete-time
signals and systems. Using the complex exponential signals, the discrete-time sine and cosine signals
can be built as follows.
( ) ( )
n i n i n i n i
e e
i
n e e n



+ = + =
2
1
) sin( and
2
1
) cos( .
(a) Consider the signal
| | |
.
|

\
|
=
N
Mn
n x
M
2
sin , where N = 12.
For M = 4, 5, 7,10, and 15, plot x
M
[n] on the interval 0 n 2N-1. Use stem to create the plots
with appropriate labels.
(i) What is the fundamental period of each signal?
(ii) How can the fundamental period be determined from arbitrary integer values of M and N?
(b) Consider the signal
| | ( n n x
k k
) sin = , where
5
2 k
k

= .
For x
k
[n] given by k = 1, 2, 4, and 6, use stem to plot each signal on the interval 0 n 9. All of
the signals should be plotted with separate axes in the same figure using subplot.
(i) How many unique signals have you plotted?
(ii) If two signals are identical, explain how different values of
k
can yield the same signal.
(c) Plot each of the following signals on the interval 0 n 31, where N =6:

| | | |
| | | | .
4
cos
4
sin ,
2
5
sin 3
2
cos
,
3
cos
2
cos 2 ,
3
cos 2
2
cos
4 3
2 1
|
.
|

\
|
|
.
|

\
|
= |
.
|

\
|
+ |
.
|

\
|
=
|
.
|

\
|
+ |
.
|

\
|
= |
.
|

\
|
+ |
.
|

\
|
=
n n
n x
N
n
N
n
n x
N
n
N
n
n x
N
n
N
n
n x



(i) Determine whether or not each of the signals is periodic.
(ii) If a signal is not periodic, explain why.
(iii) If a signal is periodic, what is the fundamental period and how can you determine the
fundamental period without using MATLAB?
(iv) Is the addition of two periodic signals necessarily periodic? Explain your answer.
(d) Define a vector nx to be the time indices 10 n 10 and the vector x to be the values of the
signal x[n] as follows:
| |

=
=
=
=
=
otherwise. , 0
, 4 , 3
, 3 , 1
, 2 , 1
, 0 , 2
n
n
n
n
n x
(i) Plot this discrete-time sequence using stem.

KML/LS001: Signals
3
(ii) Define vectors y1 through y5 to represent the following discrete-time signals:
y
1
[n] = x[n2], y
2
[n] = x[n+1], y
3
[n] = x[n],
y
4
[n] = x[n+1], y
5
[n] = x[2n].
(iii) Plot the signals using stem. Based on your plots, state how each signal is related to the
original x[n].
3. Continuous-time Complex Exponential Signals
In this part, the symbolic Math Toolbox will be used, which provides functions to represent,
manipulate, and analyze continuous-time signal and system symbolically rather than numerically. The
complex exponentials, e
st
where s is a complex scalar, are particularly useful for analyzing signals and
systems, as they form the building blocks for a large class of signals. For examples,
( ) ( ) ( ) ( )
t i t i t i t i
e e
i
t e e t



= + =
2
1
sin and
2
1
cos .
These signals can be plotted using ezplot, which is a plotting routine of the Symbolic Math Toolbox
(a) Consider the continuous-time sinusoid
( )
|
.
|

\
|
=
T
t
t x
2
sin .
As ezplot can accept one variable, we set the fundamental period T = 5. This can be done using
the following command:
>> ezplot(sin(2*pi*t/5), [0, 10])
For T = 4, 8, and 16, use ezplot to plot the following signal on the intervals 0 t 32. What is the
fundamental period of x(t) in terms of T?
( )
|
.
|

\
|
|
.
|

\
|
=
T
t
T
t
t x
2
sin
2
cos
(b) Consider the following ramp-shaped pulse signal:
f(t) = t(u(t) u(t2)), where u(t) is the unit step signal.
Create the following unit step function Heaviside using M-file
function f = Heaviside(t)
f = (t >= 0);
Type the following command:
>> Heaviside ([1:0.2:1])
(i) What are the answers? Explain your results.
(ii) Use ezplot to plot f(t) for 10 < t < 10.
(c) Discuss how the signals below are related to f(t):
g
1
(t) = f(t), g
2
(t) = f(t+1), g
3
(t) = f(t3),
g
4
(t) = f(t+1), g
5
(t) = f(2t+1).
Plot each of the signals using ezplot.




END
KML/LS001: Signals
4

Potrebbero piacerti anche