Professional Documents
Culture Documents
Handout - 1 Discrete-Time Signals
Handout - 1 Discrete-Time Signals
Using Matlab
Discrete-Time Signals
Overview
• Types of Signals
• Some Fundamental Sequences
• Representation of Discrete-Time Signals
• Classification of Discrete-Time Signals
• Basic Operations on Signals
2
Types of Signals
Signals
Continues-Time Discrete-Time
3
Types of Signals
1. Continuous-time signals
1 1
0.8 0.8
0.6 0.6
Amplitude
Amplitude
0.4 0.4
0.2 0.2
0 0
-0.2 -0.2
-0.4 -0.4
-0.02 -0.01 0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 -0.02 -0.01 0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08
Time, sec Time, sec
4
Types of Signals
2. Discrete-time signals
1 1
0.8 0.8
0.6 0.6
Amplitude
Amplitude
0.4 0.4
0.2 0.2
0 0
-0.2 -0.2
-0.4 -0.4
-2 -1 0 1 2 3 4 5 6 7 8 -2 -1 0 1 2 3 4 5 6 7 8
Sample number Sample number
1 1
0.5 0.5
0 0
-0.5 -0.5
-1 -1
0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0 0.002 0.004 0.006 0.008 0.01 0.012 0.014
0.8
1 𝑛=0 0.6
𝛿 𝑛 =ቊ
0 𝑛≠0 0.4
0.2
-0.2
-3 -2 -1 0 1 2 3 4 5 6 7
MATLAB:
function [x,n] = impseq(n0,n1,n2)
% Generates x(n) = delta(n-n0); n1 <= n,n0 <= n2
% ----------------------------------------------
% [x,n] = impseq(n0,n1,n2)
%
n = [n1:n2];
x = [(n-n0) == 0];
7
Some Fundamental Sequences
Unit step sequence:
1.2
1 𝑛≥0 1
𝑢 𝑛 =ቊ 0.8
0 𝑛<0 0.6
∞ 𝑛 0.4
0.2
-0.2
𝑘=0 𝑙=−∞ -3 -2 -1 0 1 2 3 4 5 6 7
𝛿 𝑛 = 𝑢 𝑛 − 𝑢[𝑛 − 1]
MATLAB:
function [x,n] = stepseq(n0,n1,n2)
% Generates x(n) = u(n-n0); n1 <= n,n0 <= n2
% ------------------------------------------
% [x,n] = stepseq(n0,n1,n2)
%
n = [n1:n2];
x = [(n-n0) >= 0];
8
Some Fundamental Sequences
Unit ramp sequence:
8
𝑛 𝑛≥0
𝑟𝑛 =ቊ 6
0 𝑛<0
4
∞ 𝑛
2
𝑟 𝑛 = 𝑢 𝑛 − 𝑘 = 𝑢[𝑙 − 1] 0
𝑘=1 𝑙=−∞ -3 -2 -1 0 1 2 3 4 5 6 7
𝑢 𝑛 = 𝑟 𝑛 + 1 − 𝑟[𝑛]
MATLAB:
function [x,n] = rampseq (n0,n1,n2)
% Generates x(n) = r(n-n0); n1 <= n,n0 <= n2
% ------------------------------------------
% [x,n] = rampseq(n0,n1,n2)
%
n = [n1:n2];
x = max(0, n-n0);
9
Some Fundamental Sequences
Real-valued exponential sequence:
1
𝑥 𝑛 = 𝑎𝑛 0.8
0.6
MATLAB: 0.4
n = 0:10; 0.2
x = (0.7).^n; 0
0 1 2 3 4 5 6 7 8 9 10
stem(n,x)
10
Some Fundamental Sequences
Complex-valued exponential sequence:
1 1
0.5 0.5
0 0
-0.5 -0.5
0 2 4 6 8 10 12 14 16 18 20 0 2 4 6 8 10 12 14 16 18 20
0.5
𝑥[𝑛] = cos(𝜔0 𝑛 + 𝜃) 0
-0.5
MATLAB:
-1
n = 0:10; 0 1 2 3 4 5 6 7 8 9 10
x = cos(0.1*pi*n+pi/3); stem(n, x)
Random sequence: 2
MATLAB: -2
N = 11; -4
0 1 2 3 4 5 6 7 8 9 10
n = 0:N-1; 1
stem(n, x) 0.4
stem(n, y) 0.2
0
0 1 2 3 4 5 6 7 8 9 10
12
Representation of Discrete-Time Signals
Discrete-time signal 𝑥[𝑛] may be represented using one of the
following ways:
(Note that the sample index 𝑛 is dimension-less. Just a counter!)
1. Mathematical Representation:
𝑥[𝑛] = 𝑛2 , −1 ≤ 𝑛 ≤ 2 (𝑛 = −1, 0, 1, 2)
4. Tabular Representation:
𝑛 -2 -1 0 1 2 3
𝑥[𝑛] 0 1 4 3 -5 -1
14
Representation of Discrete-Time Signals
5. In terms of unit sample and unit step sequences:
A signal 𝑥[𝑛] can be expressed as a sum of weighted and shifted
unit samples as follows:
Or 𝑥[𝑛] = 𝑥 𝑘 𝛿[𝑛 − 𝑘]
𝑘=−∞
Example:
𝑥[𝑛] = −2 , 3 , 1 , 2
2 1.5
1 1
x[n]
x[n]
0 0.5
-1 0
-2 -0.5
-3 -1
-3 -2 -1 0 1 2 3 -4 -3 -2 -1 0 1 2 3 4 5 6
n n
(a) (b)
16
Representation of Discrete-Time Signals
Exercise:
Express the following sequences in terms of unit-sample, unit-step
and unit-ramp sequences.
(a) (b)
a) 𝑥 𝑛 = 𝑢 𝑛 + 2 + 𝛿 𝑛 + 𝛿 𝑛 − 1
b) 𝑥 𝑛 = 𝑟 𝑛 − 5 − 2𝑟 𝑛 − 10 + 𝑟 𝑛 − 15
17
Classification of Discrete-Time Signals
Finite-length and infinite-length sequences
• Finite-length sequence is defined only for a finite time interval:
𝑁1 ≤ 𝑛 ≤ 𝑁2 with 𝑁1 ≤ 𝑁2 .
• Length (or duration) of this finite-length sequence is
𝑁 = 𝑁2 − 𝑁1 + 1.
Examples:
• 𝑥[𝑛] = 𝑛2 ; −3 ≤ 𝑛 ≤ 4
is a finite-length sequence of length
𝑁 = 4 − −3 + 1 = 8.
• 𝑥[𝑛] = cos(0.4𝑛)
is an infinite-length sequence.
18
Classification of Discrete-Time Signals
Right-sided and left-sided sequences
• A right-sided sequence is any infinite-length sequence that is
equal to zero for 𝑛 ≤ 𝑛0 .
• A left-sided sequence is any infinite-length sequence that is
equal to zero for 𝑛 > 𝑛0 .
1.2
Examples: 0.8
0.6
0.2
is a right-sided sequence. 0
-0.2
-3 -2 -1 0 1 2 3 4 5 6 7
1.2
1 𝑛 ≤ 𝑛0 1
0 𝑛 > 𝑛0 0.6
0.4
-0.2
-3 -2 -1 0 1 2 3 4 5 6 7
19
Classification of Discrete-Time Signals
Periodic and aperiodic sequences
• A periodic continuous-time signal is not necessarily to be
periodic when discretized.
• A sequence, 𝑥[𝑛], is said to be periodic if, for some positive real
integer 𝑁,
𝑥[𝑛] = 𝑥[𝑛 ± 𝑘𝑁]; 𝑘 = 1, 2, ⋯
• 𝑁 is called the fundamental period of 𝑥[𝑛].
Examples:
• 𝑥[𝑛] = 𝑒 𝑗𝜋𝑛/8 is a periodic sequence of period 𝑁 = 16.
• 𝑥[𝑛] = cos(𝑛2 ) is an aperiodic (nonperiodic) sequence.
𝑎𝑛 𝑛 ≥ 0
• 𝑥[𝑛] = 𝑎𝑛 𝑢(𝑛) =ቊ is an aperiodic sequence.
0 𝑛<0
20
Classification of Discrete-Time Signals
Periodic and aperiodic sequences
• A sinusoidal sequence 𝑥[𝑛] = cos(𝜔0 𝑛 + 𝜃) or
𝑥[𝑛] = 𝑒 𝑗(𝜔0 𝑛+𝜃) is periodic only if
𝑇𝑠 𝐹0 𝜔0 𝑟
= = =
𝑇0 𝐹𝑠 2𝜋 𝑁
where 𝑟/𝑁 is a rational number (i.e., both 𝑟 and 𝑁 are integers).
𝑁 is the fundamental period of this signal.
• The sum of periodic sequences is also periodic with a period of
the lowest common multiple (LCM) of the individual periods.
Examples:
• 𝑥[𝑛] = cos(3𝜋𝑛) is a periodic sequence (𝑁 = 2).
• 𝑥[𝑛] = cos(3𝑛) is a nonperiodic sequence.
21
Classification of Discrete-Time Signals
Energy and power sequences
• The total energy of a sequence, 𝑥[𝑛], is defined by
∞
2
𝐸𝑥 = 𝑥[𝑛]
𝑛=−∞
Example 1: 0.8
0.6
0.4
1, for 0 ≤ 𝑛 ≤ 5
• 𝑥[𝑛] = ቊ
0.2
0, elsewhere 0
-0.2
-3 -2 -1 0 1 2 3 4 5 6 7
∞ 5
2
𝐸𝑥 = 𝑥[𝑛] = (1)2 = 6 (Finite)
𝑛=−∞ 𝑛=0
5
1 6
𝑃𝑥 = lim (1)2 = lim =0 (Zero)
𝐾→∞ 2𝐾 + 1 𝐾→∞ (2𝐾 + 1)
𝑛=0
24
Classification of Discrete-Time Signals
Energy and power sequences (cont.)
1.2
Example 2: 1
0.8
0.6
0.4
1, for 𝑛 ≥ 0
• 𝑥[𝑛] = 𝑢[𝑛] = ቊ 0.2
0, otherwise 0
-0.2
-3 -2 -1 0 1 2 3 4 5 6 7
∞ ∞ ∞
2 = 𝑢2 [𝑛] = (1)2 = ∞
𝐸𝑥 = 𝑥[𝑛] (Infinite)
𝑛=−∞ 𝑛=−∞ 𝑛=0
𝐾
1 2
𝐾+1 1 + 1/𝐾 1
𝑃𝑥 = lim 𝑢 [𝑛] = lim = lim =
𝐾→∞ 2𝐾 + 1 𝐾→∞ 2𝐾 + 1 𝐾→∞ 2 + 1/𝐾 2
𝑛=−𝐾
(Finite)
Thus, this is a power signal.
25
Classification of Discrete-Time Signals
Energy and power sequences (cont.)
7
Example 3: 6
3
𝑛, for 𝑛 ≥ 0
• 𝑥[𝑛] = 𝑟[𝑛] = ቊ 2
0, for 𝑛 < 0 1
0
-3 -2 -1 0 1 2 3 4 5 6 7
∞ ∞
2 = 𝑛2 = ∞
𝐸𝑥 = 𝑥[𝑛] (Infinite)
𝑛=−∞ 𝑛=0
𝐾
1 2
𝐾(𝐾 + 1)(2𝐾 + 1)
𝑃𝑥 = lim 𝑛 = lim =∞ (Infinite)
𝐾→∞ 2𝐾 + 1 𝐾→∞ 6(2𝐾 + 1)
𝑛=0
MATLAB:
function [y, n] = sigshift(x, m, n0)
% implements y(n) = x(n-n0)
% -------------------------
% [y,n] = sigshift(x,m,n0)
%
n = m + n0;
y = x;
27
Basic Operations on Signals
Example:
28
Basic Operations on Signals
2. Folding (Reversal or reflection)
• If 𝑦[𝑛] = 𝑥[−𝑛], then 𝑥[𝑛] is flipped around 𝑛 = 0.
MATLAB:
function [y, n] = sigfold(x, n)
% implements y(n) = x(-n)
% -----------------------
% [y,n] = sigfold(x,n)
%
y = fliplr(x);
n = -fliplr(n);
29
Basic Operations on Signals
Example:
30
Basic Operations on Signals
3. Amplitude Scaling
• If 𝑦[𝑛] = 𝐴𝑥[𝑛], then 𝑥[𝑛] is
multiplied by a scalar 𝐴.
4. Time Scaling
• For a positive integer 𝑀,
• 𝑦[𝑛] = 𝑥[𝑀𝑛] is 𝑥[𝑛] down-sampled by a factor of 𝑀
(compression).
• 𝑦[𝑛] = 𝑥[𝑛Τ𝑀] is 𝑥[𝑛] up-sampled by a factor of 𝑀
(expansion).
31
Basic Operations on Signals
Example:
32
Basic Operations on Signals
5. Addition
• The signal 𝑦[𝑛] = 𝑥[𝑛] + 𝑤[𝑛] is formed by the point-wise
addition of the signal values.
• The two signals must have
the same length.
6. Multiplication
• The signal 𝑦[𝑛] = 𝑥[𝑛] ∙ 𝑤[𝑛] is formed by the point-wise
multiplication of the signal values.
34
Basic Operations on Signals
6. Multiplication
MATLAB:
function [y,n] = sigmult(x1,n1,x2,n2)
% implements y(n) = x1(n)*x2(n)
% -----------------------------
% [y,n] = sigmult(x1,n1,x2,n2)
% y = product sequence over n, which includes n1 and n2
% x1 = first sequence over n1
% x2 = second sequence over n2 (n2 can be different from n1)
%
n = min(min(n1),min(n2)):max(max(n1),max(n2)); % duration of y(n)
y1 = zeros(1,length(n)); y2 = y1; % initialization
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; % x1 with duration of y
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; % x2 with duration of y
y = y1 .* y2; % sequence multiplication
35
Basic Operations on Signals
Example:
Draw a block diagram showing how to perform the following
operations. This is called the difference equation of a discrete-time
system.
𝑦 𝑛 = 2𝑥 𝑛 + 0.3𝑥 𝑛 − 1 − 0.7𝑥[𝑛 − 2] − 0.5𝑦[𝑛 − 1] + 0.1𝑦[𝑛 − 2]
Solution:
2
𝑥[𝑛] + 𝑦[𝑛]
z-1 z-1
0.3 −0.5
𝑥[𝑛 − 1] 𝑦[𝑛 − 1]
z-1 z-1
−0.7 0.1
𝑥[𝑛 − 2] 𝑦[𝑛 − 2]
36
Matlab Commands
abs Absolute value and complex magnitude
angle Phase angle
clc Clear Command Window
clear Remove items from workspace, freeing up system memory
conj Complex conjugate
cos Cosine of argument in radians
exp Exponential
find Find indices and values of nonzero elements
fliplr Flip matrix left to right
flipud Flip matrix up to down
imag Imaginary part of complex number
length Length of vector or largest array dimension
max Largest elements in array
mean Average or mean value of array
37
Matlab Commands
min Smallest elements in array
ones Create array of all ones
pi Ratio of circle's circumference to its diameter (≅ 3.14)
plot 2-D line plot
prod Product of array elements
rand Uniformly distributed pseudorandom numbers
randn Normally distributed pseudorandom numbers
real Real part of complex number
sin Sine of argument in radians
size Array dimensions
stem Plot discrete sequence data
sum Sum of array elements
zeros Create array of all zeros
38
Useful Links
Discrete time signals representations and operations
https://www.youtube.com/watch?v=pkaOj4kg-1k
https://www.youtube.com/watch?v=3Qzpj6UUxhE
https://www.youtube.com/watch?v=17bnT1NHKbs
https://www.youtube.com/watch?v=QafVncdLd-g
39