Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

1

Pengolahan Sinyal Digital


Adhi Harmoko Saputro

DSP - Fisika UI
2

Differential Equations
Adhi Harmoko Saputro

DSP - Fisika UI
3

LTI System

Convolution y [ n]  x [ n] ∗ h [ n]
Signal
LTI System
N M
Differential ∑ ak y [ n=
− k ] ∑ bk x [ n − k ]
Equations
= k 0= k 0

a recursive approach for computing the


current output, given the input values and
previously computed output values

DSP - Fisika UI
4

Linear Constant-Coefficient Difference Equations


• In general, an Nth-order linear constant coefficient difference equation has the form
N M

=
k
k 0= k 0
∑ a y [ n=
− k ] ∑ b x [n − k ]k

• The output is not uniquely specified for a given input


• The initial conditions are required
• Linearity, time invariance, and causality depend on the initial conditions
• If initial conditions are assumed to be zero, system is linear, time invariant, and
causal

DSP - Fisika UI
5

Linear Constant-Coefficient Difference Equations


• Example
• Moving Average

y[n] = x[n] + x[n − 1] + x[n − 2] + x[n − 3]

• Difference Equation Representation


0 3

=
k
k 0= k 0
∑ a y [n − k ] = ∑ b x [n − k ]
k where ak = bk = 1

DSP - Fisika UI
6

Recursive Solution
• In the discrete-time case, there are an alternative to find the Differential Equations

1M N

y [ n]
=  ∑ bx x [ n − k ] − ∑ ak y [ n − k ] 
= ao  k 0=k 1 

• This is often how digital filters are implemented on a computer or a digital signal
processor board
• The response of a differential equation
• The differential equation is discretized at a given sampling rate to obtain a
difference equation
• The response of the difference equation is computed recursively

DSP - Fisika UI
7

General Solution
• A general solution can be expressed as the sum of a homogeneous response
(natural response), and a particular solution (forced response) of the system:

y [ n ] yh [ n ] + y p [ n ]
=

• The concept of initial rest of the LTI causal system described by the difference
equation here means that x[n] = 0 implies y[n] = 0

DSP - Fisika UI
8

General Solution
• The homogeneous part of the solution
N
yh [ n ] = ∑ ck zkn
k =1

zk, k = 1, . . . , N are N roots (also called natural frequencies) of the characteristic


equation
N

∑ k =0
a z
k =1
k

• important in determining the stability of systems

DSP - Fisika UI
9

General Solution
• The particular part of the solution is determined from the right-hand side

x[n] yp[n]
A K
A.Mn K.Mn
A.nM K0nM + K1nM-1 + K2nM-2 + … + KM
An.nM An ( K0nM + K1nM-1 + K2nM-2 + … + KM )

DSP - Fisika UI
10

Example
• Consider the difference equation

y[n] – 3y[n – 1] – 4y[n – 2]=0

• Find system response y[n] for y[–1] = 5 and y[–2] = 0 !

DSP - Fisika UI
11

Example
• Solution: Assumption  homogen solution
yh[n] = zn

• Subsitution to original equation


zn – 3zn-1 – 4zn-2 = 0
zn-2 (z2 – 3z – 4) = 0
(z + 1)(z – 4) = 0
z = -1 and z = 4

DSP - Fisika UI
12

Example
• Solution
y [ n ] yh [ n ] + y p [ n ]
=

y [ n ] = a1 (−1) n + a2 (4) n

• Finding a1 and a2 to fulfil the solution

DSP - Fisika UI
13

Example
• Finding a1 and a2 to fulfil the solution

y[n] – 3 y[n –1] – 4 y[n – 2] = 0


y[n] = 3 y[n –1] + 4 y[n – 2]

y[0] = 3 y[–1] + 4 y[–2] yh [ n ] = a1 (−1) n + a2 (4) n


y[1] = 3 y[0] + 4 y[–1] yh [ 0=
] a1 + a2
= 3 y {3 y[–1] + 4 y[–2]} + 4 y[–1]
yh [1] =−a1 + 4a2
= 13 y[−1] + 12 y[−2]

DSP - Fisika UI
14

Example
• Input the initial value
y[0] = 15
y[1] = 65

15= a1 + a2 a1 = −1
65 =−a1 + 4a2 a2 = 16

• Solution
y[n] =−1( −1) + 16 ( 4 )
n n
n≥0

DSP - Fisika UI
15

Example
• Consider the difference equation
5 1
y [ n ] − y [ n − 1] + y [ n − =
2] 3 x [ n ] − 2 x [ n − 1]
6 6
• Find the recursive form of the difference equation
• Assuming initial rest and that the input is an impulse,
• y[−2] = y[−1] = 0

DSP - Fisika UI
16

Example
5 1
y [=
n] y [ n − 1] − y [ n − 2] + 3 x [ n ] − 2 x [ n − 1]
6 6
• the recursion can be started
5 1
y [ 0=
] y [ −1] − y [ −2] + 3x [0] − 2 x [ −1]
6 6
5 1
= ( 0 ) − ( 0 ) + 3 (1) − 2 ( 0 ) = 3
6 6
5 1
[1] y [0] − y [ −1] + 3x [1] − 2 x [0]
y=
6 6
5 1 1
= ( 3) − ( 0 ) + 3 ( 0 ) − 2 (1) =
6 6 2

DSP - Fisika UI
17

Example

5 1
y [ 2] = y [1] − y [ 0] + 3 x [ 2] − 2 x [1]
6 6
51 1 1
=   − ( ) ( ) ( )
3 + 3 0 − 2 0 = −
62 6 12

DSP - Fisika UI
18

Matlab Implemantation
• A function called filter is available to solve difference equations numerically, given
the input and the difference equation coefficients.
• In its simplest form this function is invoked by
y = filter(b,a,x)
• where
• b = [b0, b1, ..., bM]; a = [a0, a1, ..., aN] are the coefficient arrays

N M

=
k
k 0= k 0
∑ a y [ n=
− k ] ∑ b x [n − k ]k

DSP - Fisika UI
19

Matlab Implemantation
• To compute and plot impulse response, MATLAB provides the function impz.
• When invoked by

h = impz(b,a,n)

• Computes samples of the impulse response of the filter at the sample indices
given in n with numerator coefficients in b and denominator coefficients in a.

DSP - Fisika UI
20

Matlab Example
• Given the following difference equation

y(n) − y(n − 1) + 0.9y(n − 2) = x(n);

• Calculate and plot the impulse response h(n) at n = −20, . . . , 100.


• Calculate and plot the unit step response s(n) at n = −20, . . . , 100.
• Is the system specified by h(n) stable?

DSP - Fisika UI
21

Matlab Example
• From the given difference equation the coefficient arrays are
• b = [1]; a=[1, -1, 0.9];

>> b = [1]; a = [1, -1, 0.9]; n = [-20:100];


>> h = impz(b,a,n);
>> subplot(2,1,1); stem(n,h);
>> title(’Impulse Response’);
>> xlabel(’n’); ylabel(’h(n)’)

DSP - Fisika UI
22

Matlab Example

>> n=-20:100;
>> x = (n-0) >= 0; % x = stepseq(0,-20,100);
>> s = filter(b,a,x);
>> subplot(2,1,2); stem(n,s)
>> title(’Step Response’);
>> xlabel(’n’); ylabel(’s(n)’)

DSP - Fisika UI
23

Matlab Example
Impulse Response Step Response
1 2.5

0.8

0.6 2

0.4

0.2 1.5

s(n)
h(n)

-0.2 1

-0.4

-0.6 0.5

-0.8

-1 0
-20 0 20 40 60 80 100 120 -20 0 20 40 60 80 100

n n

DSP - Fisika UI
24

Matlab Example
• To determine the stability of the system, we have to determine h(n) for all n.
• Although we have not described a method to solve the difference equation
• we can use the plot of the impulse response to observe that h(n) is practically zero
for n > 120. Hence the sum

∑ h [ n]
>> sum(abs(h))
ans = 14.8785
which implies that the system is stable.

DSP - Fisika UI
25

Example
• Let us consider the convolution given in previous example. The input sequence is
of finite duration x(n) = u(n) − u(n − 10)
• while the impulse response is of infinite duration

h ( n ) = ( 0.9 ) u ( n )
n

• Determine y(n) = x(n) ∗ h(n).

DSP - Fisika UI
26

Example
• If the LTI system, given by the impulse response h(n), can be described by a
difference equation, then y(n) can be obtained from the filter function.
• From the h(n) expression

[ n − 1] ( 0.9 )( 0.9 )
( 0.9 ) h= [ n − 1] ( 0.9 ) u [ n − 1]
n −1 n
u=
h [ n ] − ( 0.9 ) h=
[ n − 1]
( 0.9 ) u [ n] − ( 0.9 ) u [ n − 1]
n n

= ( 0.9 ) ( u [ n ] − u=
[ n − 1]) ( 0.9 ) δ [ n]
n n

= δ [ n]

DSP - Fisika UI
27

Example
• The last step follows from the fact that δ(n) is nonzero only at n = 0.
• By definition h(n) is the output of an LTI system when the input is δ(n).
• Hence substituting x(n) for δ(n) and y(n) for h(n), the difference equation is

y [ n ] − ( 0.9 ) y [ n − 1] =x [ n]

DSP - Fisika UI
28

Example
• MATLAB’s filter function can be used to compute the convolution indirectly.

>> b = [1]; a = [1,-0.9];


>> n = -5:50;
>> x = stepseq(0,-5,50) - stepseq(10,-5,50);
>> y = filter(b,a,x);
>> subplot(2,1,2); stem(n,y);
>> title(’Output sequence’)
>> xlabel(’n’); ylabel(’y(n)’); axis([-5,50,-0.5,8])

DSP - Fisika UI
29

Example
Convolotion
8

y(n)
2

0
0 5 10 15 20 25 30 35 40

Differential Equation
8

4
y(n)

-5 0 5 10 15 20 25 30 35 40 45 50

DSP - Fisika UI
30

Example

err = y1(1:40) - y2(1:40);


mean(err);

disp(['Error ' num2str(mean(err))]);

DSP - Fisika UI
32

DIGITAL FILTERS
Adhi Harmoko Saputro

DSP - Fisika UI
33

DIGITAL FILTERS
• Two types of digital filters
• FIR filter If the unit impulse response of an LTI system is of finite duration, then
the system is called a finite-duration impulse response (or FIR) filter.
M
y [ n]
= ∑ b x [ n − m]
m
m=0

• h(n) = 0 for n < n1 and for n > n2

• IIR filter If the impulse response of an LTI system is of infinite duration, then the
system is called an infinite-duration impulse response (or IIR) filter.
N

∑ a y [n − k ] =
k =0
k x [ n]

DSP - Fisika UI
34

Matlab Implementation
• FIR filters are represented either as impulse response values {h(n)} or as difference
equation coefficients {bm} and {a0 = 1}.
• conv(x,h)
• filter(b,1,x)

• IIR filters are described by thedifference equation coefficients {bm} and {ak}
• filter(b,a,x)

DSP - Fisika UI
35

Terima Kasih
Adhi Harmoko Saputro

DSP - Fisika UI

You might also like