From: Al on
I am using filtering to find the system response of a linear difference equation, y[n+1]-1.01y[n]=x[n+1]. The input will be x[n] = 500u[n]-1500delta[n-4]. Delta is an impulse function. I am not sure how to set up the inline function (4th line from bottom) to handle the delta term, -1500delta[n+1]. Are the coefficients, a and b, set up correctly?

clear;clc;close all % clear memory, command window, close figures
% Find h[n]
a=[1, -1.01]; % y coefficients for y[n+1]-1.01y[n]=x[n+1]
b=[1, 0] % coefficients input x[n+1]
n=[0:30]; % desired range of n values

% Set input to a delta function, x[n] = delta[n]
delta=inline('n==0','n'); % n==0 is 1 when n is 0 and 0 otherwise

% Compute the output y[n] = h[n] because the input is a delta function.
h=filter(b,a,delta(n));
figure; % create a new blank figure window
stem(n,h,'k') % plot using a stemplot with black lines
xlabel('n');ylabel('h[n]');title('Impulse Response');

% Find the zero-state response (zero initial conditions) when the
% input is x[n] = 500u[n]-1500delta[n-4]
% NOT SURE IF THIS IS CORRECT-1500 IS AN IMPULSE[N-4]
x = inline('500.*(n+1)-1500.*(n-4).*(n>=0)','n');
y = filter(b,a,x(n));
figure; stem(n,y,'k')
xlabel('n');ylabel('y[n] (zero-state)');title('Zero-State Response');