Sei sulla pagina 1di 59

ELEN E4810: Digital Signal Processing

Topic 2: Time domain


1. Discrete-time systems
2. Convolution
3. Linear Constant-Coefficient Difference
Equations (LCCDEs)
4. Correlation

Dan Ellis 2003-09-09 1


1. Discrete-time systems
 A system converts input to output:
x[n] DT System y[n] y[n] = f (x[n])

 E.g. Moving Average (MA):


1/M
x[n] 1 M 1
z-1 1/M y[n] = x[n k]
x[n-1] + y[n] M k=0
z-1 1/M
x[n-2] (M = 3)
Dan Ellis 2003-09-09 2
Moving Average (MA)
x[n] A
-1 1 2 3 4 5 6 7 8 9 n
1/M
x[n] x[n-1]
z-1 1/M
x[n-1] + y[n] -1 1 2 3 4 5 6 7 8 9 n
z-1 1/M x[n-2]
x[n-2]
-1 1 2 3 4 5 6 7 8 9 n

1 M 1 y[n]
y[n] = x[n k]
M k=0 -1 1 2 3 4 5 6 7 8 9 n
Dan Ellis 2003-09-09 3
MA Smoother
 MA smooths out rapid variations
(e.g. 12 month moving average)
 e.g. signal noise 1 4
x[n] = s[n] + d[n] y[n] = k=0 x[n k]
5 5-pt
5
s[n]
5
s[n] moving
4 x[n]
d[n]
4 y[n]
average
3 3

2 2

1 1

0 0

-1 -1
0 10 20 30 40 50 0 10 20 30 40 50

Dan Ellis 2003-09-09 4


Accumulator
 Output accumulates all past inputs:
n
y[n] = x[l]
l= x[n] + y[n]
n1
z-1
= x[l] + x[n] y[n-1]
l=
= y[n 1]+ x[n]

Dan Ellis 2003-09-09 5


Accumulator
x[n] A
-1 1 2 3 4 5 6 7 8 9 n
y[n-1]
x[n] + y[n]
z-1 -1 1 2 3 4 5 6 7 8 9 n
y[n-1]
y[n]

-1 1 2 3 4 5 6 7 8 9 n

Dan Ellis 2003-09-09 6


Classes of DT systems
 Linear systems obey superposition:
x[n] DT system y[n]

 if input x1[n] output y1[n], x2 y2 ...


 given a linear combination of inputs:
x[n] = x1[n] + x2 [n]
 then output y[ n] = y1[ n] + y2 [ n]
for all , , x1, x2
i.e. same linear combination of outputs
Dan Ellis 2003-09-09 7
Linearity: Example 1
n

 Accumulator: y[n] = x[l]


l=
x[n] = x1[n] + x 2 [n]
n
y[n] = (x1[l] + x 2[l])
l=
= (x1[l]) + (x 2 [l])
= x1[l] + x 2 [l]
= y1[n] + y2 [n] Linear

Dan Ellis 2003-09-09 8


Linearity Example 2:
 Energy 2
operator:
y[n] = x [n] x[n 1] x[n +1]

x[n] = x1[n] + x 2 [n]


2
y[n] = (x1[n] + x2 [n])
(x1[n 1] + x2 [n 1])
(x1[n +1] + x2 [n +1])
y1[n] + y2 [n] Nonlinear

Dan Ellis 2003-09-09 9


Linearity Example 3:
n

 Offset accumulator: y[n] = C + x[l]


n l=
y1[n] = C + x1[l]
l=
n
but y[n] = C + (x1[l] + x2 [l])
l=
y1[n] + y2 [n] Nonlinear

.. unless C = 0

Dan Ellis 2003-09-09 10


Property: Shift (time) invariance
 Time-shift of input
causes same shift in output
 i.e. if x1[n] y1[n]
then x[n] = x1[n n0 ]
y[n] = y1[n n0 ]
 i.e. process doesnt depend on absolute
value of n

Dan Ellis 2003-09-09 11


Shift-invariance counterexample
 Upsampler: x[n] L y[n]
x[n / L], n = 0, L, 2L,L
y[n] =
0, otherwise
y1[n] = x1[n / L] (n = r L)
x[n] = x1[n n0 ]
y[n] = x1[n / L n0 ]
n L n0 Not shift invariant
= x1 = y1[n L n0 ] y1[n n0 ]
L
Dan Ellis 2003-09-09 12
Another counterexample
y[n] = n x[n] scaling by time index

 Hence y1[n n0 ] = (n n0 ) x1[n n0 ]


 If x[n] = x1[n n0 ]
then y[n] = n x1[n n0 ]

 Not shift invariant - parameters depend


on n

Dan Ellis 2003-09-09 13


Linear Shift Invariant (LSI)
 Systems which are both linear and
shift invariant are easily manipulated
mathematically
 This is still a wide and useful class of
systems
 If discrete index corresponds to time,
called Linear Time Invariant (LTI)

Dan Ellis 2003-09-09 14


Causality
 If output depends only on past and
current inputs (not future), system is
called causal
 Formally, if x1[n] y1[n] & x2[n] y2[n]
Causal x1[n] = x 2 [n] n < N
y1[n] = y2 [n] n < N

Dan Ellis 2003-09-09 15


Causality example
1 M 1
 Moving average: y[n] = x[n k]
M k=0
y[n] depends on x[n-k], k 0 causal
 Centered moving average
1
y[n] =
M
( (M 1) /2
x[n]+ k=1 x[n k]+ x[n + k] )
.. looks forward in time noncausal
 Can sometimes make a non-causal
system causal by delaying its output
Dan Ellis 2003-09-09 16
Impulse response (IR)
1, n = 0 [n] 1
 Impulse [n] = n
0, n 0
-3 -2 -1 1 2 3 4 5 6 7

(unit sample sequence)


 Given a system: x[n] DT system y[n]

h[n]
if x[n] = [n] then y[n] =
impulse response
 LSI system completely specified by h[n]

Dan Ellis 2003-09-09 17


Impulse response example
1
 Simple system: x[n]
z-1 2
+ y[n]
z-1 3

x[n] 1
-3 -2 -1 1 2 3 4 5 6 7 n x[n] = [n] impulse

2
y[n] 1 3
-3 -2 -1 1 2 3 4 5 6 7 n y[n] = h[n] impulse response

Dan Ellis 2003-09-09 18


2. Convolution
 Impulse response: [n] LSI h[n]

 Shift invariance: [n-n0] LSI h[n-n0]

 + Linearity: [n-k] h[n-k]


+ [n-l] LSI + h[n-l]

 Can express any sequence with s:


x[n] = x[0][n] + x[1][n-1] + x[2][n-2]..
Dan Ellis 2003-09-09 19
Convolution sum

 Hence, since x[n] = x[k][n k]
k=

Convolution
 For LSI, y[n] = x[k]h[n k] sum
k=

written as y[n] = x[n] * h[n]


 Summation is symmetric in x and h
i.e. l = n k
x[n] * h[n] = x[n l]h[l] = h[n] * x[n]
l=

Dan Ellis 2003-09-09 20


Convolution properties
 LSI System output y[n] = input x[n]
convolved with impulse response h[n]
h[n] completely describes system
 Commutative: x[n] * h[n] = h[n] * x[n]
 Associative:
(x[n] * h[n]) * y[n] = x[n] * (h[n] * y[n])
 Distributive:
h[n] * (x[n] + y[n]) = h[n] * x[n] + h[n] * y[n]
Dan Ellis 2003-09-09 21
Interpreting convolution
 Passing a signal through a (LSI) system
is equivalent to convolving it with the
systems impulse response
x[n] h[n] y[n] = x[n] h[n]

y[n] = x[k]h[n k] = h[k]x[n k]
k= k=

x[n]={0 3 1 2 -1} h[n] = {3 2 1}

-3 -2 -1 1 2 3 5 6 7 n -3 -2 -1 1 2 3 4 5 6 7 n
Dan Ellis 2003-09-09 22
Convolution interpretation 1

y[n] = x[k]h[n k] x[k]
k= -3 -2 -1 1 2 3 5 6 7 k
 Time-reverse h, h[0-k]
shift by n, take inner
-3 -2 -1 1 2 3 4 5 6 7 k
product against
h[1-k]
fixed x
9 9
11 -3 -2 -1 1 2 3 4 5 6 7 k
y[n] h[2-k]
2
0 -1
-3 -2 -1 1 2 3 5 7 n -3 -2 -1 1 2 3 4 5 6 7
k

Dan Ellis 2003-09-09 23


Convolution

interpretation 2
y[n] = h[k]x[n k] x[n]
k= -3 -2 -1 1 2 3 5 6 7 n

h[k]
-3 -2 -1
x[n-1]
 Shifted xs
-3 -2 -1 1 2 3 4 6 7 n
weighted by

1 2 3 4 5 6 7
points in h x[n-2]

 Conversely, -3 -2 -1 1 2 3 4 5 7 n
11
weighted, 9 9
k

y[n]
delayed 0
2
-1

versions of h ... -3 -2 -1 1 2 3 5 7 n
Dan Ellis 2003-09-09 24
Matrix interpretation

y[n] = x[n k]h[k]
k=

y[0] x[0] x[1] x[2]


y[1] x[1] x[0] x[1]h[0]
y[2] = x[2] x[1] h[1]
x[0]
h[2]
... ... ... ...

 Diagonals in X matrix are equal

Dan Ellis 2003-09-09 25


Convolution notes
 Total nonzero length of convolving N
and M point sequences is N+M-1
 Adding the indices of the terms within
the summation gives n :

y[n] = h[k]x[n k] k + (n k ) = n
k=
i.e. summation indices move in opposite
senses

Dan Ellis 2003-09-09 26


Convolution in MATLAB
 The M-file conv implements the
convolution sum of two finite-length
sequences
 If a = [0 3 1 2 -1]
b = [3 2 1]
then conv(a,b) yields
[0 9 9 11 2 0 -1]
M

Dan Ellis 2003-09-09 27


Connected systems
 Cascade connection:
h1[n] h2[n] h1[n] * hh[n]= h2[n] [n]
1

Impulse response h[n] of the cascade of


two systems with impulse responses
h1[n] and h2[n] is h[n] = h1[n] * h 2[n]
 By commutativity,
h1[n] h2[n] h2[n] h1[n]

Dan Ellis 2003-09-09 28


Inverse systems
 [n] is identity for convolution
i.e. x[n] * [n] = x[n]
 Consider
x[n] h1[n] y[n] h2[n] z[n]

z[n] = h2 [n] * y[n] = h2 [n] * h1[n] * x[n]


= x[n] if h2 [n] * h1[n] = [n]
 h2[n] is the inverse system of h1[n]
Dan Ellis 2003-09-09 29
Inverse systems
 Use inverse system to recover input x[n]
from output y[n] (e.g. to undo effects of
transmission channel)
 Only sometimes possible - e.g. cannot
invert h1[n] = 0
 In general, attempt to solve
h2 [n] * h1[n] = [n]

Dan Ellis 2003-09-09 30


Inverse system example
 Accumulator:
Impulse response h1[n] = [n]
 Backwards difference
h2[n] = [n] [n 1]
.. has desired property:
[n] [n 1] = [n]
 Thus, backwards difference is inverse
system of accumulator.

Dan Ellis 2003-09-09 31


Parallel connection
h1[n]
+ h1[n] + hh[n]= h2[n] [n]
1
h2[n]

 Impulse response of two parallel


systems added together is:
h[n] = h1[n] + h2[n]

Dan Ellis 2003-09-09 32


3. Linear Constant-Coefficient
Difference Equation (LCCDE)
 General spec. of DT, LSI, finite-dim sys:
N M
 defined by {dk}, {pk}
d k y[n k] = pk x[n k]  order = max(N,M)
k=0 k=0

 Rearrange for y[n] in causal form:


N M
dk pk
y[n] = y[n k] + x[n k]
k=1 d 0 k=0 d 0

 WLOG, always have d0 = 1


Dan Ellis 2003-09-09 33
Solving LCCDEs
 Total solution
y[n] = yc [n] + y p [n]

Complementary Solution Particular Solution


N
for given forcing function
satisfies d k y[n k] = 0 x[n]
k=0

Dan Ellis 2003-09-09 34


Complementary Solution
 General form of unforced oscillation
i.e. systems natural modes
n
 Assume yc has form c y [n] =
N
dk nk
=0
k=0

nN
(d
0
N
+ d1 N 1
+K+ d N 1 + d N ) = 0
N
d k N k = 0 Characteristic polynomial
k=0 of system - depends only on {dk}

Dan Ellis 2003-09-09 35


Complementary Solution
N
 k = 0 factors into roots i , i.e.
d N k

k=0 ( 1 )( 2 )... = 0
 Each/any i satisfies eqn.
 Thus, complementary solution:
n n n
yc [n] = 1 1 + 2 2 + 3 3 + ...
Any linear combination will work
is are free to match initial conditions

Dan Ellis 2003-09-09 36


Complementary Solution
 Repeated roots in chr. poly:
L
( 1 ) ( 2 )... = 0
n n 2 n
yc [n] = 1 1 + 2 n 1 + 3 n 1
L1 n
+...+ L n 1 + ...

n
 Complex is sinusoidal yc [n] = i i

Dan Ellis 2003-09-09 37


Particular Solution
 Recall: Total solution y[n] = yc [n] + y p [n]
 Particular solution reflects input
 Modes usually decay away for large n
leaving just yp[n]
 Assume form of x[n], scaled by :
e.g. x[n] constant yp[n] =
x[n] = 0n yp[n] = 0n (0 i)
or = nL+1 0n (0 i)
Dan Ellis 2003-09-09 38
LCCDE example
y[n] + y[n 1] 6y[n 2] = x[n]
x[n] + y[n]

 Need input: x[n] = 8[n]


 Need initial conditions:
y[-1] = 1, y[-2] = -1

Dan Ellis 2003-09-09 39


LCCDE example
 Complementary solution:
y[n] + y[n 1] 6y[n 2] = 0; y[n] = n
n2
( 2
+ 6) = 0
( + 3)( 2) = 0 roots 1 = -3, 2 = 2
n n
yc [n] = 1 (3) + 2 (2)
 1, 2 are unknown at this point

Dan Ellis 2003-09-09 40


LCCDE example
 Particular solution:
 Input x[n] is constant = 8[n]
assume yp[n] = , substitute in:
y[n] + y[n 1] 6y[n 2] = x[n] (large n)
+ 6 = 8[n]
4 = 8 = 2

Dan Ellis 2003-09-09 41


LCCDE example
 Total solution y[n] = yc [n] + y p [n]
n n
= 1 (3) + 2 (2) +
 Solve for unknown is by substituting
initial conditions into DE at n = 0, 1, ...
y[n] + y[n 1] 6y[n 2] = x[n]
from ICs
 n = 0 y[0] + y[1] 6y[2] = x[0]
1 + 2 + +1+ 6 = 8
1 + 2 = 3
Dan Ellis 2003-09-09 42
LCCDE example
 n = 1 y[1] + y[0] 6y[1] = x[1]
1 (3) + 2 (2) + + 1 + 2 + 6 = 8
2 1 + 3 2 = 18
 solve: 1 = -1.8, 2 = 4.8
 Hence, system output:
n n
y[n] = 1.8(3) + 4.8(2) 2 n 0
 Dont find is by solving with ICs at
n = -1,-2 (ICs may not reflect natural modes)
Dan Ellis 2003-09-09 43
LCCDE solving summary
 Difference Equation (DE):
Ay[n] + By[n-1] + ... = Cx[n] + Dx[n-1] + ...
Initial Conditions (ICs): y[-1] = ...
 DE RHS = 0 with y[n]=n roots {i}
gives complementary soln yc [n] = i i
n

 Particular soln: yp[n] ~ x[n]


solve for 0n at large n
 is by substituting DE at n = 0, 1, ...
ICs for y[-1], y[-2]; yt=yc+yp for y[0], y[1]
Dan Ellis 2003-09-09 44
LCCDEs: zero input/zero state
 Alternative approach to solving
LCCDEs is to solve two subproblems:
 yzi[n], response with zero input (just ICs)
 yzs[n], response with zero state (just x[n])
 Because of linearity, y[n] = yzi[n]+yzs[n]
 Both subproblems are real
 But, have to solve for is twice
(then sum them)

Dan Ellis 2003-09-09 45


Impulse response of LCCDEs
 Impulse response: [n] LCCDE h[n]

i.e. solve with x[n] = [n] y[n] = h[n]


(zero ICs)
 With x[n] = [n], form of yp[n] = 0
just solve yc[n] for n = 0,1... to find is

Dan Ellis 2003-09-09 46


LCCDE IR example
 e.g. y[n] + y[n 1] 6y[n 2] = x[n]
(from before); x[n] = [n]; y[n] = 0 for n<0
n n
 yc [n] = 1 (3) + 2 (2)
1
 n = 0: y[0] + y[1] 6y[2] = x[0]
1 + 2 = 1
 n = 1: 1 (3) + 2 (2) +1 = 0
1 = 0.6, 2 = 0.4
n n n0
 thus h[n] = 0.6(3) + 0.4 (2) Infinite length
Dan Ellis 2003-09-09 47
System property: Stability
 Certain systems can be unstable e.g.
x[n] + y[n] y[n]
z -1 ...
2
-1 1 2 3 4 n
Output grows without limit in some
conditions

Dan Ellis 2003-09-09 48


Stability
 Several definitions for stability; we use
Bounded-input, bounded-output
(BIBO) stable
 For every bounded input x[n] < Bx n
output is also subject to a finite bound,
y[n] < By n

Dan Ellis 2003-09-09 49


Stability example
1 M 1
 MA filter: y[n] = k=0 x[n k]
M
1 M 1
y[n] = k=0 x[n k]
M
1 M 1
k=0 x[n k]
M
1
M Bx By BIBO Stable
M

Dan Ellis 2003-09-09 50


Stability & LCCDEs
 LCCDE output is of form:
n n n
y[n] = 1 1 + 2 2 + ...+ 0 + ...

 s and s depend on input & ICs,


but to be bounded for any input
we need || < 1

Dan Ellis 2003-09-09 51


4. Correlation
 Correlation ~ identifies similarity
between sequences:

y[n]x[n l]
Cross
correlation rxy [l] =
of x against y lag n=

 Note: ryx [l] = x[n]y[n l] call m = n - l
n=

= x[m + l]y[m] = rxy [l]
m=

Dan Ellis 2003-09-09 52


Correlation and convolution

 Correlation: rxy [n] = y[k]x[k n]
k=

 Convolution: x[n] y[n] = y[k]x[n k]
k=

 Hence: rxy [n] = y[n] x[n]

Correlation may be calculated by


convolving with time-reversed sequence
Dan Ellis 2003-09-09 53
Autocorrelation
 Autocorrelation (AC) is correlation of
signal with itself:

rxx [l] = x[n]x[n l] = rxx [l]
n=

 Note: rxx [0] = [n] = x
x 2 Energy of
sequence x[n]
n=

Dan Ellis 2003-09-09 54


Correlation maxima
rxx [l]
 Note: rxx [l] rxx [0] 1
rxx [0]
rxy [l]
 Similarly: rxy [l] x y 1
rxx [0]ryy [0]

 From geometry, xi 2
angle
between
xy = i xi yi = x y cos x and y

 when x//y, cos = 1, else cos < 1


Dan Ellis 2003-09-09 55
AC of a periodic sequence
 Sequence of period N: x[n] = x[n + N]
 Calculate AC over a finite window:
M
1
rxx [l] =
2M +1 n=M
x[n]x[n l]
N 1
1
= x[n]x[n l] if M >> N
N n=0

Dan Ellis 2003-09-09 56


AC of a periodic sequence

1 N 1 2
rxx [0] = x [n] = Px
Average energy per
sample or Power of x
N n=0

N 1
1
rxx [l + N] = x[n]x[n l N ] = rxx [l]
N n=0

 i.e AC of periodic sequence is periodic

Dan Ellis 2003-09-09 57


What correlations look like
rxx [l]
 AC of any x[n]

l
rxx [l]
 AC of periodic
l
rxy [l]
 Cross correlation
l
Dan Ellis 2003-09-09 58
What correlation looks like
Autocorrelation of generic signal
0.01 0.1

0.005
x[n] 0.05
rxx[l]
0 0

0.005 -0.05

0.01 -0.1
0 20 40 60 80 100 -100 -80 -60 -40 -20 0 20 40 60 80 100

Autocorrelation of near-periodic signal


0.2 0.2

0.1 x[n] 0.1 rxx[l]


0 0

-0.1 0.1

-0.2 0.2
0 20 40 60 80 100 100 80 60 40 20 0 20 40 60 80 100

Cross-correlation
0.02 0.02
x[n] 0.01
rxy[l]
0
0
0.02
0.01
y[n]
0.04 0.02
0 20 40 60 80 100 100 80 60 40 20 0 20 40 60 80 100

Dan Ellis 2003-09-09 59

Potrebbero piacerti anche