EE 451

Using MATLAB to find impulse and step responses
Consider the difference equation
y(n) + 0.25 y(n-1) = 5 x(n) - 0.75 x(n-1) - 1.75 x(n-2)
This has an impulse response
h(n) = -20 (-0.25)^n + 25 delta(n) - 7 delta(n-1)
and a step response
g(n) = -4 (-0.25)^n + 7 delta(n) + 2 u(n)
The following MATLAB commands finds the responses from the difference equations and from h(n) and g(n) directly:

n = 0:10
a = [1 0.25 0];                     % left hand side of difference equation
b = [5 -0.75 -1.75];                % right hand side of difference equation
h1 = -20*(-0.25).^n + 25*[n==0] - 7*[n==1];
[h2,x] = dimpulse(b,a,length(n));   %find h from difference equation
subplot(221)
stem(n,h1)
title('Impulse response')
subplot(222)
stem(n,h2)
title('Impulse response from difference equation')

g1 = -4*(-0.25).^n + 7*[n==0] + 2*[n>=0];
[g2,x] = dstep(b,a,length(n));      %find g from difference equation
subplot(223)
stem(n,g1)
title('Step response')
subplot(224)
stem(n,g2)
title('Step response from difference equation')



Bill Rison, <rison@ee.nmt.edu >