From sgordon@charcoal.eg.bucknell.edu Wed Sep 17 00:11 EDT 1997
Date: Wed, 17 Sep 1997 00:11:17 -0400
From: sgordon@charcoal.eg.bucknell.edu (Steve-O)

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

% NOTE:  MATLAB does not allow an index of zero in vectors.
%        Thus the array index will be one greater than the time index.
%        In other words, the discrete-time signal value y[n] will be
%        stored at array location y[n+1].

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

yinit = 0;
n = 0: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;
y1(1) = 0.1*(yinit)^2 + 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.1*y1(i-1)^2 + 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] = 2u[n], output y2[n]
 
x = 2;
y2(1) = 0.1*(yinit)^2 + x;  % Do time n=0 separately to handle initial condition.
 
for i=2:11      % Compute system outputs for times 1, 2, ..., 10
  x = 2;
  y2(i) = 0.1*y2(i-1)^2 + x;
end
 
figure(2)       % Plot output signal y2[n]
stem(n, y2)
title('Problem 1.34 (a)')
xlabel('Time index (n)')
ylabel('y2[n]')

% Part c: x[n] = Sin(3.14159*n/4)u[n], output y3[n]
 
x = sin(3.14159*n/4);
y3(1) = 0.1*(yinit)^2 + sin(3.14159/4);  % Do time n=0 separately to handle initial
 
for i=2:11      % Compute system outputs for times 1, 2, ..., 10
  x = sin(3.14159*i/4);
  y3(i) = 0.1*y3(i-1)^2 + x;
end
 
figure(3)       % Plot output signal y3[n]
stem(n, y3)
title('Problem 1.34 (a)')
xlabel('Time index (n)')
ylabel('y3[n]')

% Part d: x[n] = 2u[n]+Sin(pi*n/4)u[n], output y1[n]
 
x = 2 + sin(3.14159*n/4);
y4(1) = 0.1*(yinit)^2 + 2 + sin(3.14159/4);  % Do time n=0 separately to handle 
 
for i=2:11      % Compute system outputs for times 1, 2, ..., 10
  x = 2 + sin(3.14159*i/4);
  y4(i) = 0.1*y4(i-1)^2 + x;
end
 
figure(4)       % Plot output signal y4[n]
stem(n, y4)
title('Problem 1.34 (a)')
xlabel('Time index (n)')
ylabel('y4[n]')




