You are on page 1of 46

Digital Signal Processing

CSE - 610
Lecture # 2: Discrete Time Signals and Systems

Dr. Muhammad Shehzad Hanif


shehzad.hanif@uet.edu.pk

Department of Mechatronics and Control Engineering


University of Engineering and Technology, Lahore
Discrete Time Signal
 A sequence of numbers x in which nth number in the
sequence is denoted by x[n]
x   x[n] ,   n  
where n is an integer

Discrete time signal x[n]

 NOTE: x[n] is defined only for integer values of n. Moreover, it is not


2 correct to think that x[n] is zero for non-integer values of n
Basic Types of Discrete Time Signals
 The unit impulse sequence and unit step
sequence
Unit impulse sequence or an impulse

0 n0
 [ n]  
1 n0
Unit step sequence

1 n0
u[n]  
0 n0

3
Basic Types of Discrete Time Signals
 Sinusoidal and exponential sequence

Sinusoidal sequence

x[n]  cos(0 n)

Exponential sequence

x[n]  a n x[n]  (0.9)n

4
Basic Operations
 Ideal delay: A sequence y[n] is said to be a
delayed or shifted version of a sequence x[n] if
y[n]  x[n  n0 ]
where n0 is an integer

x[n] y[n] = x[n-2]

NOTE: if n0 is negative, the sequence will be shifted to left by n0 samples


5 corresponding to time advance
Basic Operations
 Sum, difference

y[n]  x1[n]  x2 [n]

 Multiplication

y[n]  x1[n]x2 [n]

6
x[n] via Impulse Functions

7
x[n]   x[k ] [n  k ]
k 
Unit Step and Impulse Functions
Unit step sequence

u[n]   [n]   [n  1]   [n  2] 

   [n  k ]
k 0

Impulse sequence

 [n]  u[n]  u[n 1]

8
Combining Basic Sequences

 An
n0
x[n]  
0 n0
x[n]  A u[n]
n

9
Periodic and Aperiodic Discrete Time
Signals
 In discrete time, a periodic sequence is a
sequence for which
x[n]  x[n  N ] for all n
where the period N is necessarily an integer

 Period of a discrete time sinusoid


A cos(0 n   )  A cos(0 (n  N )   )
 A cos(0 n  0 N   )
which requires that 0N = 2pk, where k is an
integer
10
Period of a discrete time sinusoid:
Example
 What is the period N of the following signal?
p
x1[n]  cos( n)
4
 Solution:
0 N  2p k
p
N  2p k  N  8k
4
k 1 N  8
3p
 Similarly x2 [n]  cos( n) has a period (N) of 16
8
3p 16
N  2p k  N  k ; N is integer for k  3
8 3
11
 N  16
Period of a discrete time sinusoid:
Example

 What is the period N of the following signal?

x3[n]  cos(n)

 Solution:
There is no integer N such that x3[n+N] = x3[n]

12
Frequency of Discrete Time Signals
 Consider the discrete time sinusoid

A cos(0 n   )

13
Discrete Time System

where T{.} is an operator that maps an input


sequence x[n] to an output sequence y[n]

Example:
Ideal delay system y[n]  x[n  n0 ]
M2
1
Moving average system y[n]  
M1  M 2  1 k  M1
x[n  k ]
14
Discrete Time System
 Linear system
A system (or process) is linear if it obeys the
principle of superposition

 Principle of superposition
If the input of a system contains the sum of
multiple signals then the output of the system is
the sum of the system responses to each
separate signal
T {ax1[n]  bx2 [n]}  aT {x1[n]}  bT {x2 [n]}
 ay1[n]  by2 [n]
15
Discrete Time System : Example

 Accumulator system: The output at time n is the sum


of present and all previous input samples
n
y[n]   x[k ]
k 
 Is accumulator system linear?

16
Is accumulator system linear?
n
y1[n]   x [k ]
k 
1

n
y2 [ n ]   x [k ]
k 
2

When input is x3[n]  ax1[n]  bx2 [n], the superposition requires the
output y3[n]  ay1[n]  by2 [n] for all possible values of a and b.
 
y3 [n]   x [k ]   ax [k ]  bx [k ]
k 
3
k 
1 2

 
 a  x1[k ]  b  x2 [k ]
k  k 

17  ay1[n]  by2 [n] Hence, system is linear


Discrete Time System : Example

y[n]  x [n] 2
( i.e.T {.}  (.) )
2

T {x1[n]  x2 [n]}  x [n]  x2 [n]  2 x1[n]x2 [n]


1
2 2

 x [n]  x2 [n]
1
2 2

Hence, the system is non-linear

18
MATLAB Example: Linearity

19 Linearity
Discrete Time System

 A time invariant system has properties invariant with


time
T{x[n  k ]}  y[n  k ]

 Linear Time Invariant (LTI) system is a system that is


both linear and time invariant (sometime referred to
as Linear Shift Invariant (LSI) system)

20
Discrete Time System: Example
 Is accumulator system time-invariant?

Let x1[n]  x[n  n0 ]


n
y1[n]   x [k ]
k 
1

n
  x[k  n ]
k 
0

Let k1  k  n0
n  n0
y1[n]   x[k ]  y[n  n ]
k1 
1 0

21 Exercise: Example 2.9 The compressor system


Linear Time Invariant system
 Let h[n] be the system response to an impulse
x[n]=[n]
 Due to time invariance property, the response to [n-k]
would be h[n-k]
y[n]  T {x[n]}
  
 T   x[k ] [n  k ]
 k  

  x[k ]T  [n  k ]
k 

22
  x[k ]h[n  k ]  x[n]  h[n]
k 
Convolution sum
Convolution
 The sequence h[n] is commonly referred to as
impulse response of the system

 The order of convolution is unimportant


 
x[n]  h[n]   x[k ]h[n  k ]   h[k ]x[n  k ]
k  k 

 h[n]  x[n]
23
Properties of Convolution
 Associativity x[n] {h1[n]  h2 [n]}
 {x[n]  h1[n]}  h2 [n]

 Distributivity x[n] {h1[n]  h2 [n]}


 x[n]  h1[n]  x[n]  h2 [n]

24
Convolution: Example
 Convolution of two rectangles

y[n]  x[n]  x[n]

25 ConvRects
Convolution: Example

26
Convolution: Example
Convolution of two sequences
x[n] = […, 0, 1, 2, 3, 0, …], h[n] = […, 0, 2, 1, 0.5, 0, …]

27
Convolution: Example

28
Convolution: Example
h[n]  u[n]  u[n  N ]
x[n]  a u[n]
n

y[n]  x[n]* h[n]  ?

29 Example 2.13: Convolution Sum


30
Introduction to MATLAB
Simple Arithmetic
 Enter formula at the command prompt
>> 5 + 8 – 3 (Press “Enter” after 3)
ans =
10
>> ans/2
ans =
5
 Or define variable
>> a = 8
a =
8
>> b = 4
b =
4
>> c = b/a
c =
2
32
Built-in Variables

 pi (= p) and ans are build in variables

>> pi
ans =
3.1416

>> sin(ans/4)
ans =
0.7071

Note: All angles are measured in RADIANS

33
Built-in Functions

Some useful mathematical functions are built-in.


For example: sin, cos, ln, log10

>> log(200)
ans =
5.2983

>> log10(1000)
ans =
10

>> cos(pi/6)
ans =
0.866

34
Lookfor Function
 Syntax:
lookfor string

Searches first line of function description for string

 Example:

>> lookfor cosine

Results in

ACOS Inverse cosine, result in radians.


ACOSD Inverse cosine, result in degrees.
ACOSH Inverse hyperbolic cosine.
COS Cosine of argument in radians.
COSD Cosine of argument in degrees.
COSH Hyperbolic cosine.
35
Help
Example:

>> help log

LOG Natural logarithm.


LOG(X) is the natural logarithm of the elements of X.
Complex results are produced if X is not positive.

See also log1p, log2, log10, exp, logm, reallog.

Overloaded functions or methods (ones with the same


name in other directories)
help gf/log.m

Reference page in Help browser


doc log

36
Matrices and Vectors

 All variables in MATLAB are matrices


 A MATLAB vector is a matrix with one row
or one column
 A MATLAB vector is a matrix with one row
and one column

37
Matrices and Vectors
 For manual entry, the elements in a vector are enclosed in
square brackets.
 When creating a row matrix, separate elements by space
>> a = [1 2 4]
a =
1 2 4

 When creating a column matrix, separate elements by semi colon


>> b = [1;2;4]
b =
1
2
4
 For matrices, columns are separated by spaces and rows are rows
are separated by semi-colon
>> c = [1 2 4; 5 6 7; 8 9 0]
c =
1 2 4
5 6 7
8 9 0
38
Signal Representation

39 SumOfSines.m
Signal Representation:
Weighted Sum of Sines
>> figure; plot(x); xlabel('n'); ylabel('Amplitude')

40
Vectorization

41 SumOfSinesV.m
M-File Programming
function x = SOS(N, a, w, phi)
% SOS weighted sum of sines
% Classical implementation of function SOS
% Inputs
% N = Number of samples
% a = weight vector for different sine waves
% w = frequency vector for different sine waves
% phi = phase vector for different sine waves
% Output
% x = weighted sum of sines

x = zeros(1,N);

for n = 0:N-1
for k = 1:3
x(n+1) = x(n+1) + a(k)*sin(w(k)*n + phi(k));
end
end

42
M-File Programming

43
M-File Programming
function x = SOSV(N, a, w, phi)
% SOS weighted sum of sines
% Vector implementation of function SOS
% Inputs
% N = Number of samples
% a = weight vector for different sine waves
% w = frequency vector for different sine waves
% phi = phase vector for different sine waves
% Output
% x = weighted sum of sines

n = 0:N-1;
x = sin(n'*w + phi(ones(1,N),:))*a';

44
Time Comparison

 Use tic and toc

>> tic; for i = 1:1000; x = SOS(N,a,w,phi); end; toc


Elapsed time is 0.129610 seconds.

>> tic; for i = 1:1000; x = SOSV(N,a,w,phi); end; toc


Elapsed time is 0.085793 seconds.

 Gain in speed is nearly 1.5 times

45
References

 Chapter # 2, Discrete-Time Signal Processing


by Alan V. Oppenheim, Ronald W. Schafer &
John R. Buck. 2nd Edition, Pearson Education -
Prentice Hall, 1999

46

You might also like