Sei sulla pagina 1di 8

Signals, Spectra and Signal Processing (EC413L1)

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.

Part 1 Discrete-time Signals


A discrete-time signal is a row vector whose elements are the samples taken from a continuous-time
signal. It is of the general form

x(n) = L x( 3 ) x( 2) x ( 1) x(0 ) x(1) x(2 ) x(3)L

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

you issue the command


>> n =[-3:4]; x = [2 1 -1 0 1 4 3 7];
and use the stem function to plot the discrete-time signal, as shown below
>> stem(n,x);grid on;title('Discrete-time signal x(n)')
Discrete-time signal x(n)
7
6
5
4
3
2
1
0
-1
-3

-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

Part 2 Elementary discrete time signals


The unit sample sequence is defined as
1 n = 0

(n) =
= L 0 0 1 0 0 L

0 n 0

and its delayed version is


1 n = n 0
(n n 0 ) =
0 n n 0

A unit sample sequence defined for 3 n 3 is shown below


Unit sample sequence
1
0.8
0.6
0.4
0.2
0
-3

-2

-1

If this sequence is delayed by two samples, the plot becomes


Unit sample sequence delayed by two samples
1
0.8
0.6
0.4
0.2
0
-3

-2

-1

Q2.1 Show how these plots are generated.

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

b. The same unit sample sequence in (a) delayed by five samples


c.

The same unit sample sequence in (a) delayed by three samples

d. The same unit sample sequence in (a) advanced by five samples


e. The same unit sample sequence in (a) advanced by three samples.
The unit step sequence is defined as
1 n 0

u(n) =
= L 0 0 1 1 1L
0
n
<
0

and its delayed version


1 n n 0
u(n n 0 ) =
0 n < 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

Unit step sequence delayed by two samples

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.

g. The same unit step sequence in (a) delayed by five samples


h. The same unit step sequence in (a) delayed by three samples
i.

The same unit step sequence in (a) advanced by five samples

j.

The same unit step sequence in (a) advanced by three samples.

The real-valued exponential sequence is defined as


x(n) = a n where a is a real number.

In MATLAB, use the array operator .^ to exponentiate.


Q2.5 Define the following in MATLAB for 0 n 10 . Plot the results on the space provided.
a. x (n) = (0.9)n

b. x (n) = (1)n

Exponential sequence a = 0.9

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

Q2.6 Comment on the plots in relation to the value of a.

A complex-valued exponential sequence is defined as


x(n) = e ( + j0 )n

Use the MATLAB function exp() to define such signal.


Q2.7 Use the script
>> n =[0:10]; x=exp((2+3i)*n);
and plot the real, imaginary, magnitude and phase of this signal. Plot them on the spaces
provided below. Comment on the outcome of the plots.

Real part

Imaginary part

20

20

15

15

10

10

10

Magnitude
20

15

15

10

10

10

10

Phase

20

10

A sinusoidal sequence has the general form


x (n) = A cos(0 n + ) = A cos(2f 0 n + )
where 0 the angular frequency, f0 the discrete-time frequency and the phase

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

the resulting waveform below.


Discrete Sinusoid
10

-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

A random signal whose length is 101 and is uniformly distributed over -5 to 5


Q2.9 Find out how to generate a random signal uniformly distributed over a given interval (a,b)
and use it to generate a random signal whose length is 101 and is uniformly distributed over
(-5, 5).

Potrebbero piacerti anche