% Tune-Up #6 - Fall 2023 - ECE 313 Linear Systems & Signals - Evans

% Copy this file into a Matlab script window, add your code and
% answers to the questions as Matlab comments, hit "Publish", and
% upload the resulting PDF file to this page for the tune-up
% assignment.  Please do not submit a link to a file but instead
% upload the file itself.   Late penalty: 2 points per minute late.

% Homework problem 6.1(a).

% For the first-order unnormalized averaging filter (lowpass filter)
%      y[n] = x[n] + x[n-1]
% and the initial condition x[-1] = 0 as a necessary condition for LTI
% system properties to hold.
% Determine the formulas for, and plot in MATLAB, the following:

% i. impulse response
%    h[n] = d[n] + d[n-1] where d[n] is the discrete-time delta signal
h = [ 1 1 0 0 0 ];
n = [ 0 1 2 3 4 ];
stem(n, h);
ylim( [-0.5 1.5] ); 
xlim( [-0.5 4.5 ] );

% ii. step response
%     ystep[n] = u[n] + u[n-1]
stepsignal = [ 1 1 1 1 1 1 1 1 ];
ystep = filter( [1 1], 1, stepsignal );
n = [ 0 1 2 3 4 5 6 7 ];
figure;
stem(n, ystep);
ylim( [-0.5 2.5] ); 
xlim( [-0.5 7.5 ] );

% iii. Plot the magnitude and phase of the frequency response using freqz.
%      H( exp(j w) ) = 1 + exp(-j w)
figure;
freqz( [ 1 1 ] );
% Magnitude response: Low frequencies pass through with gain of 1 (0 dB)
%   and very high frequencies (close to pi) are attenuated.
% Phase response: A line with a slope of -1/2 if the phase were
%   plotted in radians.

