Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Name:
Date:
Section:
Rating:
Exercises #02
Generation of Sequence
Introduction:
The purpose of this exercise is to familiarize you with the basic commands in MATLAB for signal
generation and for plotting the generated signal. MATLAB has been designed to operate on data stored
as vectors or matrices. For our purposes, sequences will be stored as vectors. Therefore, all signals are
limited to being causal and of finite length.
with the arrow indicates the sample at time index n = 0 which will serve as our reference. However in
MATLAB, we cannot have information about the sample position directly from this row vector. Therefore,
to completely define discrete-time signals in MATLAB, we need to define two row vectors, one for x(n)
and another one for n. For example, to define the sequence
x(n) = 2 1 1 0 1 4 3 7
-2
-1
How should the following signals be defined? Plot them on the spaces provided below
b. x 2 (n ) = 1 3 0 0 1 5 2 7
a. x 1(n ) = 1 3 7 4 2 0 5
10
10
-5
-5
-10
-10
-5
10
c. x 3 (n) = 1 3 0 5 3 2 1
-10
-10
10
-5
-5
-5
10
d. x 4 (n) = 1 0 3 1 2
10
-10
-10
-5
10
-10
-10
-5
10
(n) =
= L 0 0 1 0 0 L
0 n 0
-2
-1
-2
-1
Tip: A shortcut to define a matrix whose elements are zeroes or ones only, you can use the command
zeros(m,n) and ones(m,n) where m-by-n is the size of the matrix containing zeros or ones as
elements, respectively. For example to define a row vector of zeroes, use
>> zeros(1,10)
and it will generate a row vector of ten zeros. The command
>> ones(1,12)
will generate a row vector of twelve ones. Try issuing the command
>> [zeros(1,3) 1 zeros(1,3)]
and observe the results.
Q2.2 Define the following unit sample sequences and plot the results in MATLAB
a. A unit sample sequence of length 10 from 0 n 9
u(n) =
= L 0 0 1 1 1L
0
n
<
0
Q2.3 Generate a length-7 unit step sequence and its delayed version of two samples. Plot the
sequence on the spaces provided below
Unit step sequence
0.8
0.8
0.6
0.6
0.4
0.4
0.2
0.2
0
-3
-2
-1
0
-3
-2
-1
Q2.4 Define the following unit step sequences and plot the results in MATLAB
A unit step sequence of length 10 from 0 n 9
f.
j.
b. x (n) = (1)n
Exponential sequence a = 1
20
20
15
15
10
10
10
10
c. x(n) = (1.9 )n
Exponential sequence a = 1.9
20
15
10
10
Real part
Imaginary part
20
20
15
15
10
10
10
Magnitude
20
15
15
10
10
10
10
Phase
20
10
Q2.8 Use MATLAB to define the signal x (n) = 3 cos 0.1n + + 2 sin(0.5 n) for 0 n 10 and plot
3
-5
-10
10
A random sequence is the one which is cannot be defined by any mathematical relationship. We can
use a random sequence to represent noise interfering with our signal or entering our system. In MATLAB,
the function rand(1,N) generates a length N random sequence whose elements are uniformly
distributed between n = 0 and n = 1. The function randn(1,N) generates a length N Gaussian random
sequence with mean 0 and variance 1.
5
-5
-5