function class14()
%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;

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

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

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

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

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

% IIR
z{n} = 0.5*[1, -1, j, -j];
p{n} = 0.66*[-1+j, -1-j, 1+j, 1-j];
K{n} = 1;
n = n + 1;

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

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

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

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

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

% MINIMUM PHASE
z{n} = 0.5*[1, -1, j, -j];
p{n} = 0.5*[-1+j, -1-j, 1+j, 1-j];
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)]};
    if (sum(p{m} == 0) > 1)
        textloc{n} = [0.1 0.1]; textcont{n} = ['\times ' num2str((sum(p{m} == 0)))];
    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);
    
    index = find(den{1} ~= 0, 1, 'first');
    den{1} = den{1}(index : end);
    
    fnc{n} = @stem; x{n} = (1-index):(21-index);
    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
