ADNU ECEM324 SIGNALS, SPECTRA AND SIGNAL PROCESSING (LAB

)
ACTIVITY #7 SOLVING DIFFERENCE EQUATION and IMPULSE RESPONSE
An LTI discrete system can also be described by a linear constant coefficient
difference equation of the form
N

− k)
∑ ak y(n=

M

∑b

=
k 0=
m 0

m

x(n − m),

∀n

(1)

N
eU
Cp
E

If aN ≠ 0 ,then the difference equation is of order N. This equation describes a
recursive approach for computing the current output, given the input values and
previously computed output values. In practice this equation is computed
forward in time, from n = −∞ to n = ∞ .Therefore another form of this equation is

y ( n)
=

M

∑b

N

m x ( n − m) − ∑ ak y ( n − k )

=
m 0=
k 1

Solving the Difference Equation:

AD

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 from the equation given in (2.21), and x is the
input sequence array. The output y has the same length as input x. One must
ensure that the coefficient a0 not be zero.
A FOR loop function can also be used to solve Difference Equation

IMPULSE response of the system

To compute and plot impulse response, OCTAVE provides the function impz.
When invoked by
h = impz(b,a,n);
it 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.
When no output arguments are given, the impz function plots the response in the
current figure window using the stem function.

SAMPLE EXERCISES 1

Ec

Solve the following difference equation for 0 ≤ n ≤ 10 :

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

given that
=
x(n) 4 cos(π n=
8), y (0) 1=
and y (1) 1.

nakz.713@gmail.com

2π n) + 4sin(0.1.a.1. subplot(2. stem(n.2). 100. . 0.713@gmail. ylabel(’s(n)’) A linear and time-invariant system is described by the difference equation: Ec y ( n) = −0.s) title(’Step Response’).x). determine the response y (n) over 0 ≤ n ≤ 200 using the filter function.6π n)] u (n) . Using the filter function. stem(y). s = filter(b.25 y (n − 2) =x(n) + 2 x(n − 1) + x(n − 3) a.120). SAMPLE EXERCISES 2 Given the following difference equation: y (n) − y (n − 1) + 0. x(2)=4*cos(pi/8). -1. ylabel(’h(n)’) Octave Script >> >> >> TASK 1 for b. Calculate and plot the impulse response h(n) at n = −20.9]. y(n) = y(n-1) + 2*y(n-2) + x(n-2). . >> subplot(2.n). >> h = impz(b. . 100. -1. . title(‘system output y(n)’). ylabel(‘y(n)’). If the input to this system is x(n) = [5 + 3cos(0. . xlabel(’n’).-20. xlabel(’n’).Solution: N eU Cp E y=[1 1]. end.h). 0. . >> b = [1]. b. for n = 3:11 n1= n-1 x(n) = 4*cos(pi*n1/8). . b.a. .9 y (n −= 1) x(n). compute and plot the impulse and step response of the system over 0 ≤ n ≤ 100 . n = [-20:120]. a = [1.5 y (n − 1) + 0. x(1)=4. xlabel(‘n’). Calculate and plot the unit step response s(n) at n = −20. a=[1.com . SOLUTION: From the given difference equation the coefficient arrays are: b = [1]. Octave Script for a.1). >> title(’Impulse Response’). ∀n AD a. x = stepseq(0. nakz. stem(n.9].