From rbrooks@charcoal.eg.bucknell.edu Thu Sep 18 11:25 EDT 1997
Date: Thu, 18 Sep 1997 11:25:39 -0400
From: rbrooks@charcoal.eg.bucknell.edu (Brooks Robert Austin '99)

% Part e: set initial condition y[-1] = -1

% Part a: x[n] = u[n], output y1[n]

n = 0:10;

x = 1;
y1(1) = -.5 + x;      % Do time n=0 separately to handle initial condition.

for i=2:11      % Compute system outputs for times 1, 2, ..., 10
  x = 1;
  y1(i) = 0.5*y1(i-1) + x;
end

figure(1)       % Plot output signal y1[n]
stem(n, y1)
title('Problem 1.34 (a)')
xlabel('Time index (n)')
ylabel('y1[n]')


% Part b: x[n] = u[n], output y2[n]

x = 2;
y2(1) = -.5 + x;

for i=2:11
  x = 2;
  y2(i) = 0.5*y2(i-1) + x;
end

figure(2)
stem(n, y2)
title('Problem 1.34 (b)')
xlabel('Time index (n)')
ylabel('y2[n]')


% Part c: x[n] = sin(pi*n/4)*u[n]

x = sin(pi/4);
y3(1) = -.5 + x;

for i=2:11
  x = sin(pi*i/4);
  y3(i) = 0.5*y3(i-1) + x;
end

figure(3)
stem(n, y3)
title('Problem 1.34 (c)')
xlabel('Time index (n)')
ylabel('y3[n]')


% Part d: x[n] = 2*u[n] + sin(pi*n/4)*u[n]

x = 2 + sin(pi/4);
y4(1) = -.5 + x;

for i=2:11
  x = 2 + sin(pi*i/4);
  y4(i) = 0.5*y3(i-1) + x;
end

figure(4)
stem(n, y4)
title('Problem 1.34 (d)')
xlabel('Time index (n)')
ylabel('y4[n]')


