function class13()
%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('../matlab/altmany-export_fig-8016f6a')
addpath('../matlab/')
namebase = ['./' ];

Ts = 0.01; Fs = 1/Ts;


n = 1;

% LOW PASS FILTER
z{n} = [-1, nan];
p{n} = [0, nan];
K{n} = 1;
n = n + 1;

z{n} = [-1, -1, nan];
p{n} = [0, 0, nan];
K{n} = 1;
n = n + 1;

z{n} = [-1, -0.5+0.5j, -0.5-0.5j];
p{n} = [0,0,0];
K{n} = 1;
n = n + 1;

z{n} = [0, nan];
p{n} = [0.5, nan];
K{n} = 1;
n = n + 1;

z{n} = [0, 0, nan];
p{n} = [0.5, 0.5, nan];
K{n} = 1;
n = n + 1;

z{n} = [0, 0 ,0];
p{n} = [0.5, (0.5+0.5j)*sqrt(2)*0.5, (0.5-0.5j)*sqrt(2)*0.5];
K{n} = 1;
n = n + 1;


% HIGH PASS FILTER
z{n} = [1, nan];
p{n} = [0, nan];
K{n} = 1;
n = n + 1;

z{n} = [1, 1, nan];
p{n} = [0, 0, nan];
K{n} = 1;
n = n + 1;

z{n} = [1, 0.5+0.5j, 0.5-0.5j];
p{n} = [0,0,0];
K{n} = 1;
n = n + 1;

z{n} = [0, nan];
p{n} = [-0.5, nan];
K{n} = 1;
n = n + 1;

z{n} = [0, 0, nan];
p{n} = [-0.5, -0.5, nan];
K{n} = 1;
n = n + 1;

z{n} = [0, 0 ,0];
p{n} = [-0.5, (-0.5+0.5j)*sqrt(2)*0.5, (-0.5-0.5j)*sqrt(2)*0.5];
K{n} = 1;
n = n + 1;


% BAND PASS FILTER
z{n} = [-1, nan];
p{n} = [0, nan];
z{n} = [z{n}*1j z{n}*(-1j)];
p{n} = [p{n}*1j p{n}*(-1j)];
K{n} = 1;
n = n + 1;

z{n} = [-1, -1, nan];
p{n} = [0, 0, nan];
z{n} = [z{n}*1j z{n}*(-1j)];
p{n} = [p{n}*1j p{n}*(-1j)];
K{n} = 1;
n = n + 1;

z{n} = [-1, -0.5+0.5j, -0.5-0.5j];
p{n} = [0,0,0];
z{n} = [z{n}*1j z{n}*(-1j)];
p{n} = [p{n}*1j p{n}*(-1j)];
K{n} = 1;
n = n + 1;

z{n} = [0, nan];
p{n} = [0.5, nan];
z{n} = [z{n}*1j z{n}*(-1j)];
p{n} = [p{n}*1j p{n}*(-1j)];
K{n} = 1;
n = n + 1;

z{n} = [0, 0, nan];
p{n} = [0.5, 0.5, nan];
z{n} = [z{n}*1j z{n}*(-1j)];
p{n} = [p{n}*1j p{n}*(-1j)];
K{n} = 1;
n = n + 1;

z{n} = [0, 0 ,0];
p{n} = [0.5, (0.5+0.5j)*sqrt(2)*0.5, (0.5-0.5j)*sqrt(2)*0.5];
z{n} = [z{n}*1j z{n}*(-1j)];
p{n} = [p{n}*1j p{n}*(-1j)];
K{n} = 1;
n = n + 1;



% BAND STOP / NOTCH FILTER
z{n} = [1, 1, 0, 0, 0, 0, 0, 0];
p{n} = [(0.5+0.5j)*sqrt(2)*0.6, (0.5-0.5j)*sqrt(2)*0.6, (0.5+0.25j)/abs(0.5+0.25j)*0.8, (0.5-0.25j)/abs(0.5-0.25j)*0.8, (0.25+0.5j)/abs(0.25+0.5j)*0.4, (0.25-0.5j)/abs(0.25-0.5j)*0.4, -0.2*j, 0.2*j];
z{n} = [z{n}*1j z{n}*(-1j)];
p{n} = [p{n}*1j p{n}*(-1j)];
K{n} = 1;
n = n + 1;


% ALL PASS
p{n} = [0, nan];
z{n} = [nan, nan];
K{n} = 1;
n = n + 1;

p{n} = [0.5, nan];
z{n} = 1./p{n};
K{n} = 1;
n = n + 1;

p{n} = [0.5, 0.5, nan];
z{n} = 1./p{n};
K{n} = 1;
n = n + 1;

p{n} = [0.5, (0.5+0.5j)*sqrt(2)*0.5, (0.5-0.5j)*sqrt(2)*0.5];
z{n} = 1./p{n};
K{n} = 1;
n = n + 1;





M = n-1;

n = 1;


for m = 1:M
    sys = zpk(z{m}(~isnan(z{m})),p{m}(~isnan(p{m})),K{m},1); 
    [num,den] = tfdata(sys);

    fnc{n} = @plot; x{n} = [real(p{m}).' real(z{m}).'];    y{n} = [imag(p{m}).' imag(z{m}).'];
    xlbl{n} = 'Re'; ylbl{n} = 'Im'; ynum{n} = false;  
    markersize{n} = 10; 
    axis{n} = [-max([max(abs(real(x{n}))) max(abs(imag(x{n}))) 1]) max([max(abs(real(x{n}))) max(abs(imag(x{n}))) 1]) -max([max(abs(real(y{n}))) max(abs(imag(y{n}))) 1]) max([max(abs(real(y{n}))) max(abs(imag(y{n}))) 1])];
    pzzplot{n} = true; roc{n} = 0;  figwidth{n} = 3.33; figheight{n} = 3.0;
    %textloc{n} = {[-1 1.5]}; textcont{n} = {['\bf System ' num2str(m)]};
    textloc{n} = {}; textcont{n} = {};
    if (sum(z{m} == 0) > 1) || (sum(p{m} == 0) > 1)
        textloc{n} = [textloc{n}; 0.1 0.1]; textcont{n} = [textcont{n}; '\times ' num2str((sum(p{m} == 0))+(sum(z{m} == 0)))];
    end
    if (sum(z{m} == 1) > 1) || (sum(p{m} == 1) > 1)
        textloc{n} = [textloc{n}; 1.1 0.1]; textcont{n} = [textcont{n}; '\times ' num2str((sum(p{m} == 1))+(sum(z{m} == 1)))];
    end
    if (sum(z{m} == -1) > 1) || (sum(p{m} == -1) > 1)
        textloc{n} = [textloc{n}; -0.9 0.1]; textcont{n} = [textcont{n}; '\times ' num2str((sum(p{m} == -1))+(sum(z{m} == -1)))];
    end
    if (sum(z{m} == 1j) > 1) || (sum(p{m} == 1j) > 1)
        textloc{n} = [textloc{n}; 0.1 1.1]; textcont{n} = [textcont{n}; '\times ' num2str((sum(p{m} == 1j))+(sum(z{m} == 1j)))];
    end
    if (sum(z{m} == -1j) > 1) || (sum(p{m} == -1j) > 1)
        textloc{n} = [textloc{n}; 0.1 -0.9]; textcont{n} = [textcont{n}; '\times ' num2str((sum(p{m} == -1j))+(sum(z{m} == -1j)))];
    end
    if (sum(z{m} == 0.5) > 1) || (sum(p{m} == 0.5) > 1)
        textloc{n} = [textloc{n}; 0.6 0.1]; textcont{n} = [textcont{n}; '\times ' num2str((sum(p{m} == 0.5))+(sum(z{m} == 0.5)))];
    end
    if (sum(z{m} == -0.5) > 1) || (sum(p{m} == -0.5) > 1)
        textloc{n} = [textloc{n}; -0.4 0.1]; textcont{n} = [textcont{n}; '\times ' num2str((sum(p{m} == -0.5))+(sum(z{m} == -0.5)))];
    end
    if (sum(z{m} == 0.5*1j) > 1) || (sum(p{m} == 0.5*1j) > 1) 
        textloc{n} = [textloc{n}; 0.1 0.6]; textcont{n} = [textcont{n}; '\times ' num2str((sum(p{m} == 0.5*1j))+(sum(z{m} == 0.5*1j)))];
    end
    if (sum(z{m} == -0.5*1j) > 1) || (sum(p{m} == -0.5*1j) > 1)
        textloc{n} = [textloc{n}; 0.1 -0.4]; textcont{n} = [textcont{n}; '\times ' num2str((sum(p{m} == -0.5*1j))+(sum(z{m} == -0.5*1j)))];
    end
    if (sum(z{m} == 2) > 1) || (sum(p{m} == 2) > 1)
        textloc{n} = [textloc{n}; 2.1 0.1]; textcont{n} = [textcont{n}; '\times ' num2str((sum(p{m} == 2))+(sum(z{m} == 2)))];
    end
    if isempty(textloc{n}), textloc{n} = []; end
    if isempty(textcont{n}), textcont{n} = []; end
    caption{n} = 'Filter pole-zero plot';
    n = n + 1;
    
    
    sys = zpk(z{m}(~isnan(z{m})),p{m}(~isnan(p{m})),K{m},1); 
    [num,den] = tfdata(sys);
    
    fnc{n} = @plot;
    [y{n}, x{n}] = freqz(num{1},den{1}, 1024, 'whole'); 
    y{n} = fftshift(abs(y{n})); 
    x{n} = (x{n}-pi)/pi;
    %textloc{n} = {[-1 1.5*max(abs(y{n}))]}; textcont{n} = {['\bf Freq. Response ' num2str(m)]};
    xlbl{n} = '\omega'; ylbl{n} = '|H(\omega)|'; figwidth{n} = 2.4;  xTickSuffix{n}  = '\pi'; 
    hidexticks{n} = false; axis{n} = [-1 1 -(max(abs(y{n}))) (max(abs(y{n})))];
    caption{n} = 'Filter magnitude response';
    n = n + 1;
    
    fnc{n} = @plot;
    [y{n}, x{n}] = freqz(num{1},den{1}, 1024, 'whole'); 
    y{n} = fftshift(angle(y{n})); 
    x{n} = (x{n}-pi)/pi;
    %textloc{n} = {[-1 1.5*max(abs(y{n}))]}; textcont{n} = {['\bf Freq. Response ' num2str(m)]};
    xlbl{n} = '\omega'; ylbl{n} = '\angle H(\omega)'; figwidth{n} = 2.4;  xTickSuffix{n}  = '\pi'; 
    hidexticks{n} = false; axis{n} = [-1 1 -(max(abs(y{n}))) (max(abs(y{n})))];
    caption{n} = 'Filter phase response';
    n = n + 1;
    
    sys = zpk(z{m}(~isnan(z{m})),p{m}(~isnan(p{m})),K{m},1); 
    [num,den] = tfdata(sys);
    
    fnc{n} = @stem; x{n} = 0:20;
    y{n} = filter(num{1},den{1}, [1; zeros(20,1)]);
    xlbl{n} = 'n'; ylbl{n} = 'h[n]'; figwidth{n} = 2.4; 
    %textloc{n} = {[5 1.5*max(abs(y{n}))]}; textcont{n} = {['\bf Impulse Response ' num2str(m)]};
    hidexticks{n}  = true; ynum{n} = false; hideyticks{n}  = false; 
    axis{n} = [-5 20 -max(abs(y{n})) max(abs(y{n}))]; yTick{n} = [-max(abs(y{n})) max(abs(y{n}))];
    caption{n} = 'Filter impulse response';
    n = n + 1;
    
end


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} = [];
roc{n} = [];
myColorMap{n} = [];
xTick{n} = []; 
yTick{n} = [];
pzzplot{n} = [];
textloc{n} = [];
textcont{n} = '';
caption{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}, 'roc', roc{n}, ...
                  'myColorMap', myColorMap{n}, 'xTick', xTick{n}, 'yTick', yTick{n}, ...
                  'pzzplot', pzzplot{n}, 'textloc', textloc{n}, 'textcont', textcont{n}, ...
                  'caption', caption{n}, 'captionFile', [namebase 'caption' num2str(n, '%03u') '.html']);
end
