From michael@charcoal.eg.bucknell.edu Tue Sep 16 21:33 EDT 1997
Date: Tue, 16 Sep 1997 21:33:19 -0400
From: michael@charcoal.eg.bucknell.edu (Michael Sean Andrew '99)

% Sample MATLAB program for Homework 8:  Problem 1.34 in the Kamen/Heck text.
%
% ELEC 320, Fall 1997, Rich Kozick

% NOTE:  This is part f of problem 1.34, 
	I wasn't sure if you wanted us to do it.  But here it is.


% Parts a-d:  y[n] = 0.5*y[n-1] + x[n],  n = 0, 1, ..., 10
%             with initial condition y[-1] = 0.

yinit = -1;
n = 0:1:10;	% Vector of times at which we will evaluate system output.
                % This will be used for plotting.


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

x = 1;
c = sin(pi*1/4)*x;
d = 2*x + c;

y1(1) = 0.5*yinit + x;	% Do time n=0 separately to handle initial condition.
y2(1) = 0.5*yinit + 2*x;
y3(1) = 0.5*yinit + c;
y4(1) = 0.5*yinit + 2*x + c;
y5(1) = 2*y1(1) + y3(1);

for i=2:11	% Compute system outputs for times 1, 2, ..., 10
c = sin((pi*i)/4)*x;  
  
  x = 1;
  y1(i) = 0.5*y1(i-1) + x;
  y2(i) = 0.5*y2(i-1) + 2*x;
  y3(i) = 0.5*y3(i-1) + c;
  y4(i) = 0.5*y4(i-1) + 2*x + c; 
  y5(i) = 2*y1(i) + y3(i);	
end

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

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

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

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

figure(5)	% Plot output signal y5[n]
stem(n, y5)
title('Problem 1.34 (d)')
xlabel('Time index (n)')
ylabel('y5[n]')


