简体   繁体   中英

How to solve for the impulse response using a differential equation?

Given a differential equation: y[n] - 0.9y[n-1] + 0.81y[n-2] = x[n] - x[n-2]

a. Find the impulse response for h[n], n=0,1,2 using recursion.

b. Find the impulse response using MATLAB command filter.

I understand that this is homework, so I will try to give you guidelines without actually giving away the answer completely:

Using recursion

This is actually quite simple, because the differential equation contains the body of the recursive function almost entirely: y[n] = 0.9y[n-1] - 0.81y[n-2] + x[n] - x[n-2]

The parts in bold are actually the recursive calls! What you need to do is to build a function (let's call it func ) that receives x and n , and calculates y[n] :

function y = func(x, n)
   if (n < 0)
      %# Handling for edge case n<0
      return 0
   else if (n == 0)
      %# Handling for edge case n=0
      return x(0)
   else
      %# The recursive loop
      return 0.9 * func(x, n-1) - 0.81 * func(x, n-2) + x(n) - x(n-2)
   end

Note that it's pseudo-code , so you still have to check the edge cases and deal with the indexation (indices in MATLAB start with 1 and not 0!).

Using filters

The response of a digital filter is actually the y[n] that you're looking for. As you probably know from lesson, the coefficients of that filter would be the coefficients specified in the differential equation. MATLAB has a built-in function filter that emulates just that, so if you write:

B = [1, 0, 1];        %# Coefficients for x
A = [1, 0.9, -0.81];  %# Coefficients for y
y = filter(B, A, x);

You'd get an output vector which holds all the values of y[n].

a=[1 -0.9 0.81]
b=[1 -1]
impz(b,a,50)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM