function prac()
%CLASS02  Displays plots for ECE 3500 class
%   CLASS02()  creates all the plots for class lecture notes through the
%   use of Dr. Harley's plotforclass MATLAB function. To get the full
%   results from the lecture notes, this function requires the "export_fig"
%   and "oaxes" functions from the MathWorks File Exchange. 
%
%   INPUTS: none
%
%   OUTPUTS: none
%
%   see also: plot, stem, subplot, figure

close all;

addpath(genpath('../matlab/'))
namebase = ['./'];

n = 1;


%===============
%Q1a
%===============
fnc{n} = @stem; x{n} = -20:1:20; 
y{n} = (x{n} == 0) - (x{n} == 1);
xlbl{n} = 'n'; ylbl{n} = 'h[n]';  axis{n} = [-6 6 -1 1]; figwidth{n} = 3;
figheight{n} = 1.25;
ynum{n} = true; hidexticks{n} = true; hideyticks{n} = true;
n = n + 1; 

%===============
%Q1b
%===============
fnc{n} = @stem; x{n} = -20:1:20; 
y{n} = 2*(x{n} >= 0);
xlbl{n} = 'n'; ylbl{n} = 'h[n]';  axis{n} = [-6 6 0 2]; figwidth{n} = 3;
figheight{n} = 1.25;
ynum{n} = true; hidexticks{n} = true; hideyticks{n} = true;
n = n + 1; 

%===============
%Q1c
%===============
fnc{n} = @stem; x{n} = -20:1:20; 
y{n} = 3*(x{n} == 0);
xlbl{n} = 'n'; ylbl{n} = 'h[n]';  axis{n} = [-6 6 0 3]; figwidth{n} = 3;
figheight{n} = 1.25;
ynum{n} = true; hidexticks{n} = true; hideyticks{n} = true;
n = n + 1; 


%===============
%Q2a
%===============
fnc{n} = @stem; x{n} = -20:1:20; 
y{n} = (x{n} == 0) - (x{n} == 1);
xlbl{n} = 'n'; ylbl{n} = 'h[n]';  axis{n} = [-6 6 -1 1]; figwidth{n} = 3;
figheight{n} = 1.25;
ynum{n} = true; hidexticks{n} = true; hideyticks{n} = true;
n = n + 1; 

%===============
%Q2b
%===============
fnc{n} = @stem; x{n} = -20:1:20; 
y{n} = 2*(x{n} >= 0);
xlbl{n} = 'n'; ylbl{n} = 'h[n]';  axis{n} = [-6 6 0 2]; figwidth{n} = 3;
figheight{n} = 1.25;
ynum{n} = true; hidexticks{n} = true; hideyticks{n} = true;
n = n + 1; 

%===============
%Q2b
%===============
fnc{n} = @stem; x{n} = -20:1:20; 
y{n} = 3*(x{n} == 0);
xlbl{n} = 'n'; ylbl{n} = 'h[n]';  axis{n} = [-6 6 0 3]; figwidth{n} = 3;
figheight{n} = 1.25;
ynum{n} = true; hidexticks{n} = true; hideyticks{n} = true;
n = n + 1; 




pltopt{n} = [];
figheight{n} = [];
axis{n} = [];
figwidth{n} = [];
hidexticks{n} = [];
hideyticks{n} = [];
marker{n} = [];
markersize{n} = [];
xTickPrefix{n} = [];
xTickSuffix{n} = [];
yTickPrefix{n} = [];
yTickSuffix{n} = [];
LineStyleOrder{n} = [];
ynum{n} = [];
pzplot{n} = [];
pzzplot{n} = [];
roc{n} = [];

for n = 1:length(x)
    plotforclass( 'fnc', fnc{n}, 'x', x{n}, 'y', y{n}, ...
                  'flname', [namebase 'fig_' num2str(n, '%03u')], ...
                  'xlbl', xlbl{n}, 'ylbl', ylbl{n}, 'figwidth', figwidth{n}, ...
                  'hidexticks', hidexticks{n}, 'hideyticks', hideyticks{n}, 'marker', marker{n}, ...
                  'markersize', markersize{n}, 'axis', axis{n}, ...
                  'xTickPrefix', xTickPrefix{n}, 'yTickPrefix', yTickPrefix{n}, ...
                  'yTickSuffix', yTickSuffix{n}, 'figheight', figheight{n}, ...
                  'xTickSuffix', xTickSuffix{n}, 'LineStyleOrder', LineStyleOrder{n}, ...
                  'pltopt', pltopt{n}, 'ynum', ynum{n}, 'pzplot', pzplot{n}, ...
                  'pzzplot', pzzplot{n}, 'roc', roc{n});
end

end

function y=delay_s(x,M)
    %Ensure input is what it should be
    if mod(M,1)~=0; error('M must be a integer.'); end
  
    N = length(x);
    y = zeros(N, 1);
    for n = 1:N
        if n-M > 0 && n-M < N
            y(n) = x(n-M);
        end
    end
    
end

function y=accum_energy_s(x,M)
    %Ensure input is what it should be
    if mod(M,1)~=0; error('M must be a integer.'); end
    if M<=0; error('M must be a positive integer.'); end
    
    N = length(x);
    y = zeros(N,1);
    for n = 1:N
        y(n) = sum(abs(x(1:n)).^2);
    end
    
end

function y=reverb_s(x,M,A)
    %Ensure input is what it should be
    if mod(M,1)~=0; error('M must be a integer.'); end
    if M<=0; error('M must be a positive integer.'); end
    
    %Just do this one with my own convolution
    xx = [zeros(1,M),x,zeros(1,M)];
    yy = zeros(size(xx));
    for i=1:length(xx)-M
        yy(i+M) = A*yy(i)+xx(i+M);
    end

    y = yy(1+M:end-M);
end

function y=running_avg_s(x,M)
    %Ensure input is what it should be
    if mod(M,1)~=0; error('M must be a integer.'); end
    if M<=0; error('M must be a positive integer.'); end

    N = length(x);
    y = zeros(N,1);
    for m = 0:(M-1)
        y = y + 1/M*delay_s(x,m);
    end
    
end

function y=running_avga_s(x,M)
    %Ensure input is what it should be
    if mod(M,1)~=0; error('M must be a integer.'); end
    if M<=0; error('M must be a positive integer.'); end

    N = length(x);
    y = zeros(N,1);
    for m = 0:(M-1)
        y = y + 1/M*delay_s(x,-m);
    end
    
end