You are on page 1of 46

Discrete-time Signals

Lecture 2
Analog (Continuous-time) Signals
Denoted by x
a
(t)
t represents time
Digital (Discrete-time) Signals
Denoted by x(n)
n is an integer represents discrete instances
in time (sampled from an analog signal)
x(n) = { x(n) } = { , x(-1), x(0), x(1), }
Up-arrow indicates the sample at n = 0
Discrete-time signals
In MATLAB
We can present a finite-duration sequence by a row
vector
For example, x(n) = {2,1,-1, 0, 1, 4, 3, 7}
>> n=[ - 3, - 2, - 1, 0, 1, 2, 3, 4] ;
>> x = [ 2, 1, - 1 0, 1, 4, 3, 7] ;
>> st em( n, x) ;
Sequence operations
Basic Sequence
Unit Sample Sequence
Where n
1
<=n
0
<=n
2
f unct i on [ x, n] = i mseq( n0, n1, n2)
n = [ n1: n2] ;
x = [ ( n- n0) == 0] ;
{ } ,... 0 , 0 , 1 , 0 , 0 ...,
0 , 0
0 , 1
) (

=

=
=
n
n
n

=
=
0 , 0
0 , 1
) (
0
n
n
n n [x,n] = imseq(0,-5,5)
Unit Step Sequence
Unit Step Sequence
Where n
1
<=n
0
<=n
2
f unct i on [ x, n] = st epseq( n0, n1, n2)
n = [ n1: n2] ;
x = [ ( n- n0) >= 0] ;
{ } ,... 1 , 1 , 1 , 0 , 0 ...,
0 , 0
0 , 1
) (

=

<

=
n
n
n u

<

=
0 , 0
0 , 1
) (
0
n
n
n n u [x,n] = stepseq(0,-5,5)
Exercise
Plot the following sequences
x
1
(n) = 3(n+2) + 2(n) (n-3) + 5(n-7), -5 <= n <= 15
x
2
(n) = 10u(n) - 5u(n-5) 10u(n-10) + 5u(n-15)
Exponential Sequence
Real-valued exponential sequence
For example, x(n) = (0.9)
n
, 0 <= n <= 10
>> n = [ 0: 10] ;
>> x = ( 0. 9) . ^n;
= a n a n x
n
; , ) (
Combining Basic Sequence
Complex Exponential Sequence
Complex-valued exponential sequence
For example, x(n) = exp[(2+j3)n], 0<=n<=10
>> n = [ 0: 10] ;
>> x=exp( ( 2+3j ) *n) ;
n e n x
n
j
=
+
, ) (
) (
0

Sinusoidal Sequence
Sinusoidal sequence
For example, x(n) = 3(cos(0.1n+ /3)+2sin(0.5n),
0 <= n <= 10
>> n = [ 0: 10] ;
>> x=3*cos( 0. 1*pi *n*pi / 3) + 2*si n( 0. 5*pi *n) ;
n n A n x + = ), cos( ) (
0

Random sequence
For example, 0 <= n <= 10
>> n = [ 0: 10] ;
>> x = r and( 1, 11) ;
Periodic Sequence
A sequence x(n) is periodic if x(n) = x(n+N), n
>> x=3*cos( 0. 1*pi *n*pi / 3) ;
>> xt i l d = x' * ones( 1, 11) ;
>> xt i l d = xt i l d( : ) ;
>> xt i l d = xt i l d' ;
Signal Addition
{ } { } { } ) ( ) ( ) ( ) (
2 1 2 1
n x n x n x n x + = +
f unct i on [ y, n] = si gadd( x1, n1, x2, n2)
n = mi n( mi n( n1) , mi n( n2) ) : max( max( n1) , max( n2) ) ;
y1= zer os( 1, l engt h( n) ) ;
y2= y1;
y1( f i nd( ( n>=mi n( n1) ) &( n<=max( n1) ) ==1) ) =x1;
y2( f i nd( ( n>=mi n( n2) ) &( n<=max( n2) ) ==1) ) =x2;
y = y1 + y2;
Signal multiplication
{ }{ } { } ) ( ) ( ) ( . ) (
2 1 2 1
n x n x n x n x =
f unct i on [ y, n] = si gmul t ( x1, n1, x2, n2)
n = mi n( mi n( n1) , mi n( n2) ) : max( max( n1) , max( n2) ) ;
y1= zer os( 1, l engt h( n) ) ;
y2= y1;
y1( f i nd( ( n>=mi n( n1) ) &( n<=max( n1) ) ==1) ) =x1;
y2( f i nd( ( n>=mi n( n2) ) &( n<=max( n2) ) ==1) ) =x2;
y = y1 . * y2;
Scaling
)} ( { )} ( { n x n x =
Shifting
)} ( { ) ( k n x n y =
)} ( { ) ( m x k m y = +
Let m = n-k;
f unct i on [ y, n] = si gshi f t ( x, m, k)
n = m+k;
y = x;
Folding
)} ( { ) ( n x n y =
f unct i on [ y, n] = si gf ol d( x, n)
y = f l i pl r ( x) ;
n = - f l i pl r ( n) ;
Sample Summation

=
+ + =
2
1
2 1
) ( ... ) ( ) (
n
n n
n x n x n x
Sum( x( n1: n2) )
Sample Products

=
2
1
) ( ... ) ( ) (
2 1
n
n
n x n x n x
pr od( x( n1: n2) )
Signal Energy



= =
2
| ) ( | ) ( * ) ( n x n x n x
x

>>Ex = sum( x. *conj ( x) ) ; %one appr oach


>>Ex = sum( abs( x) . ^2) ; %anot her appr oach
Signal Power

=
1
0
2
| ) ( |
1
N
x
n x
N
P
Power of a periodic sequence x(n) with fundamental period N
Example
x(n) = 2(n+2) (-4), -5 <= n <= 5
>>n = [ - 5: 5] ;
>>x = 2*i mpseq( - 2, - 5, 5) - i mpseq( 4, - 5, 5) ;
>>st em( n, x) ; t i t l e( ' Sequence i n Exampl e 2. 1a' )
>>xl abel ( ' n' ) ; yl abel ( ' x( n) ' ) ; axi s( [ - 5, 5, - 2, 3] )
Example
x(n) = n[u(n)-u(n-10)]+10e
-0.3(n-10)
[u(n-10)-u(n-20)],
0 <= n <= 20
>>n = [ 0: 20] ;
>>x1 = n. *( st epseq( 0, 0, 20) - st epseq( 10, 0, 20) ) ;
>>x2 = 10*exp( - 0. 3*( n- 10) ) . *( st epseq( 10, 0, 20) - st epseq( 20, 0, 20) ) ;
>>x = x1+x2;
>>subpl ot ( 2, 2, 2) ; st em( n, x) ;
>>t i t l e( ' Sequence i n Exampl e 2. 1b' )
>>xl abel ( ' n' ) ; yl abel ( ' x( n) ' ) ; axi s( [ 0, 20, - 1, 11] )
Example
x(n) =cos(0.04n)+0.2w(n), 0 <= n <= 50
>>n = [ 0: 50] ;
>>x = cos( 0. 04*pi *n) +0. 2*r andn( si ze( n) ) ;
>>st em( n, x) ; t i t l e( ' Sequence i n Exampl e 2. 1c' )
>>xl abel ( ' n' ) ; yl abel ( ' x( n) ' ) ; axi s( [ 0, 50, - 1. 4, 1. 4] )
Example
,-10 <= n <= 9
>> n=[ - 10: 9] ;
>> x=[ 5, 4, 3, 2, 1] ;
>> xt i l de=x' * ones( 1, 4) ;
>> xt i l de=( xt i l de( : ) ) ' ;
>> st em( n, xt i l de) ; t i t l e( ' Sequence i n Exampl e 2. 1d' )
>> xl abel ( ' n' ) ; yl abel ( ' xt i l de( n) ' ) ; axi s( [ - 10, 9, - 1, 6] )
,...} 1 , 2 , 3 , 4 , 5 , 1 , 2 , 3 , 4 , 5 , 1 , 2 , 3 , 4 , 5 {..., ) (

= n x
Example
Plot x
1
(n) = 2x(n-5)-3x(n+4)
>> n = - 2: 10; x = [ 1: 7, 6: - 1: 1] ;
>> [ x11, n11] = si gshi f t ( x, n, 5) ;
>> [ x12, n12] = si gshi f t ( x, n, - 4) ;
>> [ x1, n1] = si gadd( 2*x11, n11, - 3*x12, n12) ;
>> st em( n1, x1) ;
>> t i t l e( ' Sequence i n Exampl e 2. 2a' )
>> xl abel ( ' n' ) ; yl abel ( ' x1( n) ' ) ;
} 1 , 2 , 3 , 4 , 5 , 6 , 7 , 6 , 5 , 4 , 3 , 2 , 1 { ) (

= n x
Exercise
Let
plot the samples
} 7 , 4 , 5 , 1 , 3 , 4 , 2 { ) ( =

n x
) ( ) 4 ( 3 ) 3 ( 2 ) (
3
n x n x n x n x + + =
) ( 2 ) 5 ( 5 ) 4 ( 4 ) (
4
n x n x n x n x + + + + =
Example
Plot x
2
(n) = x(n)x(n-2)
>> n = - 2: 10; x = [ 1: 7, 6: - 1: 1] ;
>> [ x21, n21] = si gf ol d( x, n) ;
>> [ x21, n21] = si gshi f t ( x21, n21, 3) ;
>> [ x22, n22] = si gshi f t ( x, n, 2) ;
>> [ x22, n22] = si gmul t ( x, n, x22, n22) ;
>> [ x2, n2] = si gadd( x21, n21, x22, n22) ;
>> subpl ot ( 2, 1, 2) ; st em( n2, x2) ;
>> t i t l e( ' Sequence i n Exampl e 2. 2b' )
>> xl abel ( ' n' ) ; yl abel ( ' x2( n) ' ) ;
} 1 , 2 , 3 , 4 , 5 , 6 , 7 , 6 , 5 , 4 , 3 , 2 , 1 { ) (

= n x
Example
>>n = [ - 10: 1: 10] ;
>>al pha = - 0. 1+0. 3j ;
>>x = exp( al pha*n) ;
>>subpl ot ( 2, 2, 1) ;
>>st em( n, r eal ( x) ) ;
>>t i t l e( ' r eal par t ' ) ;
>>xl abel ( ' n' )
>>subpl ot ( 2, 2, 2) ;
>>st em( n, i mag( x) ) ;
>>t i t l e( ' i magi nar y par t ' ) ;
>>xl abel ( ' n' )
>>subpl ot ( 2, 2, 3) ;
>>st em( n, abs( x) ) ;
>>t i t l e( ' magni t ude par t ' ) ;
>>xl abel ( ' n' )
>>subpl ot ( 2, 2, 4) ;
>>st em( n, ( 180/ pi ) *angl e( x) ) ;
>>t i t l e( ' phase par t ' ) ;
>>xl abel ( ' n' )
10 10 , ) (
) 3 . 0 1 . 0 (
=
+
n e n x
n j
Unit sample synthesis
any arbitrary sequence x(n) can be
synthesized as a weighted sum of delayed
and scaled unit sample sequences such as

=
=
k
k n k x n x ) ( ) ( ) (
Even and odd synthesis
A real value sequence x
e
(n) is called even (symmetric) if
A real value sequence x
e
(n) is called even (asymmetric) if
Any arbitrary real-valued sequence x(n) can be composited
into its even and odd components
Even and odd parts are given by
) ( ) ( n x n x
e e
=
) ( ) ( n x n x
o o
=
) ( ) ( ) ( n x n x n x
o e
+ =
)] ( ) ( [
2
1
) ( n x n x n x
e
+ =
)] ( ) ( [
2
1
) ( n x n x n x
o
=
evenodd function
f unct i on [ xe, xo, m] = evenodd( x, n)
i f any( i mag( x) ~= 0)
er r or ( ' x i s not a r eal sequence' )
end
m= - f l i pl r ( n) ;
m1 = mi n( [ m, n] ) ; m2 = max( [ m, n] ) ; m= m1: m2;
nm= n( 1) - m( 1) ; n1 = 1: l engt h( n) ;
x1 = zer os( 1, l engt h( m) ) ;
x1( n1+nm) = x; x = x1;
xe = 0. 5*( x + f l i pl r ( x) ) ;
xo = 0. 5*( x - f l i pl r ( x) ) ;
Example
>>n = [ 0: 10] ;
>>x = st epseq( 0, 0, 10) - st epseq( 10, 0, 10) ;
>>[ xe, xo, m] = evenodd( x, n) ;
>>subpl ot ( 1, 1, 1)
>>subpl ot ( 2, 2, 1) ; st em( n, x) ;
>>t i t l e( ' Rect angul ar pul se' )
>>xl abel ( ' n' ) ; yl abel ( ' x( n) ' ) ;
>>axi s( [ - 10, 10, 0, 1. 2] )
>>subpl ot ( 2, 2, 2) ; st em( m, xe) ;
>>t i t l e( ' Even Par t ' )
>>xl abel ( ' n' ) ; yl abel ( ' xe( n) ' ) ;
>>axi s( [ - 10, 10, 0, 1. 2] )
>>subpl ot ( 2, 2, 4) ; st em( m, xo) ;
>>t i t l e( ' Odd Par t ' )
>>xl abel ( ' n' ) ; yl abel ( ' xe( n) ' ) ;
>>axi s( [ - 10, 10, - 0. 6, 0. 6] )
x(n) = u(n)-u(n-10)
Decompose x(n) into even and odd component
The geometric series
A one-side exponential sequence of the form
{
n
, n >= 0}is called a geometric series
The series converges for || < 1 while the sum of its
components converges to
Sum of any finite number of the terms of the series:
1
1
1
0
<

= n
n

=
,
1
1
1
0
N
N
n
n
Correlations of sequences
A measure of the degree to which two sequences are
similar
Given two real valued sequences x(n) and y(n) of finite
energy
Crosscorrealtion of x(n) and y(n):
The case when y(n) = x(n) is called autocorrelation

=
=
n
xy
l n y n x l r ) ( ) ( ) (

=
=
n
xx
l n x n x l r ) ( ) ( ) (
Exercise
Generate and plot the following sequences using MATLAB
x
1
(n) = 3(n+2) + 2(n) (n-3) + 5(n-7), -5 <= n <= 15
x
2
(n) = 10u(n) - 5u(n-5) 10u(n-10) + 5u(n-15)
x
3
(n) = 2sin(0.01n)cos(0.5n), -200 <= n <= 200
x
4
(n) = e
0.01n
2sin(0.01n), 0 <= n <= 100
Exercise
Generate and plot the following periodic sequences using MATLAB
Let
Generate and plot the samples
periodic
n x ,...} 2 , 1 , 0 , 1 , 2 {..., ) (
1

=
periodic
n
n u n u e n x ) 20 ( ) ( [ ) (
1 . 0
2
=
} 7 , 4 , 5 , 1 , 3 , 4 , 2 { ) ( =

n x
) ( ) 4 ( 3 ) 3 ( 2 ) (
3
n x n x n x n x + + =
) ( 2 ) 5 ( 5 ) 4 ( 4 ) (
4
n x n x n x n x + + + + =
10 10 ), 2 ( ) 1 . 0 cos( ) ( 2 ) (
5 . 0
5
+ + = n n x n n x e n x
n

Exercise
Using evenodd function, decompose the following sequences
into their even and odd components
} 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 { ) (
1

= n x
)] 10 ( ) 5 ( [ ) (
1 . 0
2
+ = n u n u e n x
n
20 20 ), 4 / 2 . 0 cos( ) (
3
+ = n n n x

You might also like