Comsats: University Islamabad
Comsats: University Islamabad
Comsats: University Islamabad
Digital signal processing is concerned with the processing of a discrete-time signal, called the input signal,
to develop another discrete-time signal, called the output signal, with more desirable properties. In certain
applications, it may be necessary to extract some key properties of the original signal using specific digital
signal processing algorithms. It is also possible to investigate the properties of a discrete-time system by
observing the output signals for specific input signals. It is thus important to learn first how to generate in
the time domain some basic discrete-time signals in MATLAB and perform elementary operations on them,
which are the main objectives of this first exercise. A secondary objective is to learn the application of some
basic MATLAB commands and how to apply them in simple digital signal processing problems.
Background Review
R2.1 A discrete-time signal is represented as a sequence of numbers, called samples. A sample value of a
typical discrete-time signal or sequence {x[n]} is denoted as x[n] with the argument n being an integer in the
range −∞ and ∞. For convenience, the sequence {x[n]} is often denoted without the curly brackets.
R2.2 The discrete-time signal may be a finite length or an infinite length sequence. A finite length (also
called finite duration or finite extent) sequence is defined only for a finite time interval:
N1 ≤ n ≤ N2, (2.1)
where −∞ < N1 and N2 < ∞ with N2 ≥ N1. The length or duration N of the finite length sequence is
N = N2 − N1 + 1. (2.2)
R2.3 A sequence ˜x[n] satisfying
(2.3)
is called a periodic sequence with a period N where N is a positive integer and k is any integer.
(2.2)
(2.5)
1
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
(2.6)
The average power of a periodic sequence ˜x[n] with a period N is given by
(2.7)
R2.6 The unit sample sequence, often called the discrete-time impulse or the unit impulse, denoted by δ[n],
is defined by
(2.8)
The unit step sequence, denoted by μ[n], is defined by
(2.9)
R2.7 The exponential sequence is given by
(2.10)
Where A and α are real or complex numbers. By expressing
we can rewrite
(2.11)
R2.8 The real sinusoidal sequence with a constant amplitude is of the form
x[n] = Acos(ωon + φ), (2.12)
where A, ωo, and φ are real numbers. The parameters A, ω o, and φ in Eqs. (2.11) and (2.12) are called,
respectively, the amplitude, the angular frequency, and the initial phase of the sinusoidal sequence x[n].
fo = ωo/2π is the frequency.
R2.9 The complex exponential sequence of Eq. (2.11) with σo = 0 and the sinusoidal sequence of Eq. (2.12)
are periodic sequences if ω oN is an integer multiple of 2π, that is,
ωoN = 2πr, (2.13)
2
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
where N is a positive integer and r is any integer. The smallest possible N satisfying this
condition is the period of the sequence.
R2.10 The product of two sequences x[n] and h[n] of length N yields a sequence y[n], also of length N, as
given by
y[n] = x[n] · h[n]. (2.12)
The addition of two sequences x[n] and h[n] of length N yields a sequence y[n], also of length N, as given
by
y[n] = x[n] + h[n]. (2.15)
The multiplication of a sequence x[n] of length N by a scalar A results in a sequence y[n] of length N as
given by
y[n] = A · x[n]. (2.16)
The time-reversal of a sequence x[n] of infinite length results in a sequence y[n] of infinite length as defined
by
Y[n] = x[−n]. (2.17)
The delay of a sequence x[n] of infinite length by a positive integer M results in a sequence y[n] of infinite
length given by
y[n] = x[n −M]. (2.18)
If M is a negative integer, the operation indicated in Eq. (2.18) results in an advance of the sequence x[n]. A
sequence x[n] of length N can be appended by another sequence g[n] of length M resulting in a longer
sequence y[n] of length N +M given by
{y[n]} = {{x[n]} , {g[n]}} . (2.19)
MATLAB Commands Used
The MATLAB commands you will encounter in this exercise are as follows:
Operators and Special Characters
: . + - * / ; %
Elementary Matrices and Matrix Manipulation
i ones pi zeros
Elementary Functions
cos exp imag real
Two-Dimensional Graphics
axis grid legend plot
stairs stem title xlabel ylabel
3
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
4
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
5
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
% Program E2_3
% Generation of a real exponential sequence
clf;
n = 0:35; a = 1.2; K = 0.2;
x = K*a.^+n;
stem(n,x);
xlabel(’Time index n’);ylabel(’Amplitude’);
Questions:
Q2.6 Run Program E2_2 and generate the complex-valued exponential sequence.
Q2.7 Which parameter controls the rate of growth or decay of this sequence? Which parameter controls the
amplitude of this sequence?
Q2.8 What will happen if the parameter c is changed to (1/12)+(pi/6)*i?
Q2.9 What are the purposes of the operators real and imag?
Q2.10 What is the purpose of the command subplot?
Q2.11 Run Program E2_3 and generate the real-valued exponential sequence.
Q2.12 Which parameter controls the rate of growth or decay of this sequence? Which parameter controls the
amplitude of this sequence?
Q2.13 What is the difference between the arithmetic operators ^ and .^?
Q2.12 What will happen if the parameter a is less than 1? Run Program E2_3 again with the parameter a
changed to 0.9 and the parameter K changed to 20.
Q2.15 What is the length of this sequence and how can it be changed?
Q2.16 You can use the MATLAB command sum(s.*s) to compute the energy of a real sequence s[n] stored
as a vector s. Evaluate the energy of the real-valued exponential sequences x[n] generated in Questions Q2.11
and Q2.12.
Exercise 2.3 Sinusoidal Sequences
Another very useful class of discrete-time signals is the real sinusoidal sequence of the form of Eq. (2.12).
Such sinusoidal sequences can be generated in MATLAB using the trigonometric operators cos and sin.
Program E2_2 is a simple example that generates a sinusoidal signal.
% Program E2_2
% Generation of a sinusoidal sequence
n = 0:40;
f = 0.1;
6
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
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;
Questions:
Q2.17 Run Program E2_2 to generate the sinusoidal sequence and display it.
Q2.18 What is the frequency of this sequence and how can it be changed? Which parameter controls the
phase of this sequence? Which parameter controls the amplitude of this sequence? What is the period of this
sequence?
Q2.19 What is the length of this sequence and how can it be changed?
Q2.20 Compute the average power of the generated sinusoidal sequence.
Q2.21 What are the purposes of the axis and grid commands?
Q2.22 Modify Program E2_2 to generate a sinusoidal sequence of frequency 0.9 and display it. Compare this
new sequence with the one generated in Question Q2.17. Now, modify Program E2_2 to generate a sinusoidal
sequence of frequency 1.1 and display it. Compare this new sequence with the one generated in Question
Q2.17. Comment on your results.
Q2.23 Modify the above program to generate a sinusoidal sequence of length 50, frequency 0.08, amplitude
2.5, and phase shift 90 degrees and display it. What is the period of this sequence?
Q2.22 Replace the stem command in Program E2_2 with the plot command and run the program again. What
is the difference between the new plot and the one generated in Question Q2.17?
Q2.25 Replace the stem command in Program E2_2 with the stairs command and run the program again.
What is the difference between the new plot and those generated in Questions Q2.17 and Q2.22?
7
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
8
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
y[n] = 1
3 (x[n − 1] + x[n] + x[n + 1]). (2.21)
9
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
10
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
axis([0,100,-1.5,1.5]);
title(’Swept-Frequency Sinusoidal Signal’);
xlabel(’Time index n’);
ylabel(’Amplitude’);
grid; axis;
Questions:
Q2.36 Run Program E2_7 and generate the swept-frequency sinusoidal sequence x[n].
Q2.37 What are the minimum and maximum frequencies of this signal?
Q2.38 How can you modify the above program to generate a swept sinusoidal signal with a minimum
frequency of 0.1 and a maximum frequency of 0.3?
Workspace Information
The commands who and whos can be used to get information about the variables stored in the workspace
and their sizes created in running various MATLAB programs at any time.
Questions:
Q2.39 Type who in the Command window. What information is displayed in the Command window as a
result of this command?
Q2.20 Type whos in the Command window. What information is displayed in the Command window as a
result of this command?
Other Types of Signals
Exercise 2.7 Square wave and Sawtooth Signals
MATLAB functions square and sawtooth can be used to generate sequences of the types shown in Figures
2.1 and 2.2, respectively.
Q2.21 Write MATLAB programs to generate the square wave and the sawtooth wave sequences of the types
shown in Figures 2.1 and 2.2. Using these programs, generate and plot the sequences.
12