Você está na página 1de 3

Signals, Spectra and Signal Processing (EC413L1)

Name: Date:
Section: Rating:
Exercises #04
The Difference Equation

Introduction:
A linear, time-invariant discrete-time system can be described by a linear constant coefficient difference
equation of the form
N M
∑ a k y(n − k ) = ∑ b k x(n − k )
k =0 k =0

If aN ≠ 0, then the difference equation is of the 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 = ∞. The solution of this equation is of the form
y (n) = y c (n) + y p (n)

where yc(n) is the complementary solution and yp(n) is the particular solution.

Part 1 – Impulse and step response


A MATLAB routine called the filter()function is available to solve difference equations numerically,
given the input and the difference equation coefficients. In its simplest form, this routine is invoked by
>> y = filter(b,a,x)
where b and a are coefficient arrays from the equation given above 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. For
example, to find and plot the impulse and step response sequence of the difference equation
y(n) − y(n − 1) + 0.9 y(n − 2) = x(n)

for −20 ≤ n ≤ 120 , we define b and a as


>>b = [1];a = [1 -1 0.9];
Then we define the input impulse sequence and step sequence for −20 ≤ n ≤ 120 by
>>n = [-20:120];s = [zeros(1,20) 1 zeros(1,120)];
>>n = [-20:120];u = [zeros(1,20) ones(1,121)];
For the impulse response we set
>>x = s;
and use
>>y = filter(b,a,x);stem(n,y);grid on;axis([1 -1 -20 120]);
to obtain the following plot

1
Impulse response
1

0.8

0.6

0.4

0.2
y(n)

-0.2

-0.4

-0.6

-0.8

-1
-20 0 20 40 60 80 100 120
time index n

For the step response, set


>> x = u
and reinvoke the filter() function again to plot the step response
Step response
2.5

1.5
y(n)

0.5

0
-20 0 20 40 60 80 100 120
time index n

1. For each of the systems defined by difference equations, determine and plot the impulse and
step response. Use the Copy figure function of the MATLAB to plot the output in a separate sheet
of paper. Label each plots accordingly.
a. y(n) = 0.6y(n − 1) − 0.08 y(n − 2) + x(n)

b. y(n) = 0.7y(n − 1) − 0.1y(n − 2) + 2x(n) − x (n − 2)

c. y (n) − 4y (n − 1) + 4 y(n − 2) = x (n) − x(n − 1)

d. y(n) − 0.5 y(n − 1) + 0.25 y(n − 2) = x(n) + 2x (n − 1) + x(n − 3 )

2
Part 2 – Response to any arbitrary input
To determine the response of a system defined by a difference equation to any arbitrary input, just
generate the input signal sequence, assign it to x and use the filter()function to determine the output.
2. A “simple” digital differentiator is given by
y (n) = x(n) − x (n − 1)
which computes a backward first-order difference of the input sequence. Implement the
differentiator on the following sequences and plot the results on a separate sheet. Comment on
the appropriateness of this simple differentiator.
a. x (n) = 5[u(n) − u(n − 20 )]

b. x(n) = n[u(n) − u(n − 10 )] + (20 − n)[u(n − 10 ) − u(n − 20 )]

 πn 
c. x(n) = sin [u(n ) − u(n − 100 )]
 25 
Part 3 – Convolution vs. filtering
3. Given the sequence
y(n) − 3 y(n − 1) − 4 y(n − 2 ) = x(n ) + 2x(n − 1)
a. Determine the first 30 terms of its impulse response. Plot it on a separate sheet of paper.
b. Obtain the first 30 terms of the sequence

x(n) = (0.5 )n
Use MATLAB.
c. Obtain the convolution sum of the sequences produced in (a) and (b). Plot the resulting
sequence.
d. Use the filter() function to determine the output of the above difference equation to the
input given in (b). Plot the resulting sequence.
e. Comment on the similarities and differences in the plots obtained in items (c) and (d).

Você também pode gostar