function class16()
%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.001; Fs = 1/Ts;
ts(1) = 1/2;    % Sampling rate
ts(2) = 1;      % Sampling rate
ts(3) = 2;      % Sampling rate
fs = 1./ts;

mysignal  = @(x, delay) exp(-(x-delay).^2);

t = (-10:Ts:(10-Ts)).'; N = length(t);
r = floor(N/2)+1; f = fftshift(ifftshift((((1:N)-r)/(N)))*Fs).'; df = Fs/N;

% BUILD PULSE TRAINS
pulsetrain  = zeros(N,length(ts));
fpulsetrain = zeros(N,length(ts));
for m = 1:length(ts)
    pulsetrain(abs(rem(round(t/Ts), ts(m)/Ts)) < 1,m) = 1;
    pulsetrain(pulsetrain(:,1)==0,m) = nan;
    
    fpulsetrain(abs(rem(round(f/df), fs(m)/df)) < 1,m) = fs(m);
    fpulsetrain(fpulsetrain(:,1)==0,m) = nan;
end


n = 1;
% ---------------------------------------------
% FREQUENCY DOMAIN SIGNAL
% ---------------------------------------------
fnc{n} = @plot; 
x{n} = f*2; 
pt = fpulsetrain(:,1); pt(isnan(pt)) = 0;
y{n} = conv(1/Fs*abs(fftshift(fft(mysignal(t, 0)))), pt, 'same');
xlbl{n} = '\Omega'; ylbl{n} = 'X(\Omega)'; figwidth{n} = 3.33; 
hideticks{n} = false; xTickSuffix{n}  = '\pi'; 
axis{n} = [-10 10 0 4*fs(1)];
xTick{n} = (-4:2:4)*fs(1);
caption{n} = 'The Fourier transform of a sampled Gaussian pulse with a sampling rate of $\Omega_s = 4 \pi$.';
n = n + 1;

% 5
fnc{n} = @plot; 
x{n} = f*2; 
y{n} = (abs(x{n}) < fs(1));
xlbl{n} = '\Omega'; ylbl{n} = 'H(\Omega)'; figwidth{n} = 3.33; 
hideticks{n} = false; xTickSuffix{n}  = '\pi'; 
axis{n} = [-10 10 0 4*fs(1)];
xTick{n} = [-fs(1) fs(1)];
caption{n} = 'Low-pass ideal reconstruction filter with cut-off frequency at $\Omega_c = 2 \pi$.';
n = n + 1;

% 6
fnc{n} = @plot; 
x{n} = f*2; 
y{n} = (abs(x{n}) < 2).*y{n-2};
xlbl{n} = '\Omega'; ylbl{n} = 'H(\Omega)'; figwidth{n} = 3.33; 
hideticks{n} = false; xTickSuffix{n}  = '\pi'; 
axis{n} = [-10 10 0 4];
xTick{n} = (-4:2:4)*fs(1);
caption{n} = 'The Fourier transform of the sampled Gaussian pulse after applying the reconstruction filter.';
n = n + 1;

%3
fnc{n} = @stem; 
x{n} = t; 
y0 = mysignal(t, 0).*pulsetrain(:,1); 
ym = y0; ym(ym > 0) = 0; ym(ym == 0) = nan;
yp = y0; yp(yp < 0) = 0; yp(yp == 0) = nan;
y{n} = [yp(:) ym(:)]; 
xlbl{n} = 't'; ylbl{n} = 'x(t)'; figwidth{n} = 3.33; 
ynum{n} = false;
hideyticks{n} = false; marker{n} = {'^', 'v'}.'; 
myColorMap{n}   = [ 79 129 189; 79 129 189 ]/255;
markersize{n} = 6; 
axis{n} = [-4 4 0 1];
caption{n} = 'The sampled Gaussian pulse in time.';
n = n + 1;






for m = 1:length(ts)
% 
    fnc{n} = @stem; 
    x{n} = t; 
    y0 = mysignal(t, 0).*pulsetrain(:,m); 
    ym = y0; ym(ym > 0) = 0; ym(ym == 0) = nan;
    yp = y0; yp(yp < 0) = 0; yp(yp == 0) = nan;
    y{n} = [yp(:) ym(:)]; 
    xlbl{n} = 't'; ylbl{n} = 'x(t)'; figwidth{n} = 3.33; 
    ynum{n} = false;
    hideyticks{n} = false; marker{n} = {'^', 'v'}.'; 
    myColorMap{n}   = [ 79 129 189; 79 129 189 ]/255;
    markersize{n} = 6; 
    axis{n} = [-4 4 0 1];
    caption{n} = ['A Gaussian pulse sampled at a rate of $\Omega_s = ' num2str(4*2^(-(m-1))) '\pi$.'];

    n = n + 1;

    fnc{n} = @plot; 
    x{n} = f*2; 
    pt = fpulsetrain(:,m); pt(isnan(pt)) = 0;
    y{n} = conv(1/Fs*abs(fftshift(fft(mysignal(t, 0)))), pt, 'same');
    xlbl{n} = '\Omega'; ylbl{n} = 'X(\Omega)'; figwidth{n} = 3.33; 
    hideyticks{n} = false; xTickSuffix{n}  = '\pi'; 
    axis{n} = [-10 10 0 4];
    caption{n} = 'Fourier transform of the sampled pulse to the left.';

    n = n + 1;

end


% 
% 
% 
% fnc{n} = @plot; x{n} = -50:0.01:50; y{n} = cos(2*pi/4*x{n});
% xlbl{n} = 't'; ylbl{n} = 'x(t)'; figwidth{n} = 3.33; 
% hideticks{n} = false; n = n + 1;
% 
% fnc{n} = @plot; x{n} = linspace(-1/0.01/2, 1/0.01/2, length(x{n-1})); 
% y{n} = 1/2./(x{n}(2)-x{n}(1))./length(x{n-1})*fftshift(abs(fft(y{n-1})));
% y1 = y{n};
% xlbl{n} = '\Omega'; ylbl{n} = 'X(\Omega)'; figwidth{n} = 3.33; 
% hideticks{n} = false; xTickSuffix{n}  = '(2 \pi)'; 
% axis{n} = [-10 10 0 1];n = n + 1;
% 
% 
% 
% fnc{n} = @stem; x{n} = -50:0.01:50; myy = nan*ones(1,length(x{n}));  
% myy(~(x{n}*2-floor(x{n}*2))) = cos(2*pi/4*x{n}(~(x{n}*2-floor(x{n}*2))));
% y{n} = nan*ones(length(x{n}),2); 
% y{n}(myy >= 0,1) = myy(myy >= 0); y{n}(myy < 0,2) = myy(myy < 0);
% xlbl{n} = 't'; ylbl{n} = 'x(t)'; figwidth{n} = 3.33; 
% ynum{n} = false;
% hideticks{n} = false; marker{n} = {'^', 'v'}.'; 
% myColorMap{n}   = [ 79 129 189; ... %Blue
%                     79 129 189; ... %Blue
%                   ]/255;
% markersize{n} = 6; n = n + 1;
% 
% fnc{n} = @plot; x{n} = linspace(-1/0.01/2, 1/0.01/2, length(x{n-1})); 
% myy = zeros(1,length(x{n}));  
% myy(~(x{n}*2-floor(x{n}*2))) = cos(2*pi/4*x{n}(~(x{n}*2-floor(x{n}*2))));
% y{n} = 1/2./(x{n}(2)-x{n}(1))./length(x{n-1})*fftshift(abs(fft(myy)));
% y{n} = y{n} .* (abs(x{n}) < 2);
% xlbl{n} = '\Omega'; ylbl{n} = 'X(\Omega)'; figwidth{n} = 3.33; 
% hideticks{n} = false; xTickSuffix{n}  = '(2 \pi)'; 
% axis{n} = [-2 2 0 1.75];
% n = n + 1;
% 
% 
% 
% 
% fnc{n} = @stem; x{n} = -50:0.01:50; myy = nan*ones(1,length(x{n}));  
% myy(~(x{n}-floor(x{n}))) = cos(2*pi/4*x{n}(~(x{n}-floor(x{n}))));
% y{n} = nan*ones(length(x{n}),2); 
% y{n}(myy >= 0,1) = myy(myy >= 0); y{n}(myy < 0,2) = myy(myy < 0);
% xlbl{n} = 't'; ylbl{n} = 'x(t)'; figwidth{n} = 3.33; 
% ynum{n} = false;
% hideticks{n} = false; marker{n} = {'^', 'v'}.'; 
% myColorMap{n}   = [ 79 129 189; ... %Blue
%                     79 129 189; ... %Blue
%                   ]/255;
% markersize{n} = 6; n = n + 1;
% 
% fnc{n} = @plot; x{n} = linspace(-1/0.01/2, 1/0.01/2, length(x{n-1})); 
% myy = zeros(1,length(x{n}));  
% myy(~(x{n}-floor(x{n}))) = cos(2*pi/4*x{n}(~(x{n}-floor(x{n}))));
% y{n} = 1./(x{n}(2)-x{n}(1))./length(x{n-1})*fftshift(abs(fft(myy)));
% y{n} = y{n} .* (abs(x{n}) < 1);
% xlbl{n} = '\Omega'; ylbl{n} = 'X(\Omega)'; figwidth{n} = 3.33; 
% hideticks{n} = false; xTickSuffix{n}  = '(2 \pi)'; 
% axis{n} = [-2 2 0 1.75];
% n = n + 1;
% 
% 
% 
% fnc{n} = @stem; x{n} = -50:0.01:50; myy = nan*ones(1,length(x{n}));  
% myy(~(x{n}/2-floor(x{n}/2))) = cos(2*pi/4*x{n}(~(x{n}/2-floor(x{n}/2))));
% y{n} = nan*ones(length(x{n}),2); 
% y{n}(myy >= 0,1) = myy(myy >= 0); y{n}(myy < 0,2) = myy(myy < 0);
% xlbl{n} = 't'; ylbl{n} = 'x(t)'; figwidth{n} = 3.33; 
% ynum{n} = false;
% hideticks{n} = false; marker{n} = {'^', 'v'}.'; 
% myColorMap{n}   = [ 79 129 189; ... %Blue
%                     79 129 189; ... %Blue
%                   ]/255;
% markersize{n} = 6; n = n + 1;
% 
% fnc{n} = @plot; x{n} = linspace(-1/0.01/2, 1/0.01/2, length(x{n-1})); 
% myy = zeros(1,length(x{n}));  
% myy(~(x{n}/2-floor(x{n}/2))) = cos(2*pi/4*x{n}(~(x{n}/2-floor(x{n}/2))));
% y{n} = 2*1./(x{n}(2)-x{n}(1))./length(x{n-1})*fftshift(abs(fft(myy)));
% y{n} = y{n} .* (abs(x{n}) < 1/2);
% xlbl{n} = '\Omega'; ylbl{n} = 'X(\Omega)'; figwidth{n} = 3.33; 
% hideticks{n} = false; xTickSuffix{n}  = '(2 \pi)'; 
% axis{n} = [-2 2 0 1.75];
% n = n + 1;
% 
% 
% 
% 
% fnc{n} = @stem; x{n} = -50:0.01:50; myy = nan*ones(1,length(x{n}));  
% myy(~(x{n}/10-floor(x{n}/10))) = cos(2*pi/4*x{n}(~(x{n}/10-floor(x{n}/10))));
% y{n} = nan*ones(length(x{n}),2);
% y{n}(myy >= 0,1) = myy(myy >= 0); y{n}(myy < 0,2) = myy(myy < 0);
% xlbl{n} = 't'; ylbl{n} = 'x(t)'; figwidth{n} = 3.33; 
% ynum{n} = false;
% hideticks{n} = false; marker{n} = {'^', 'v'}.'; 
% myColorMap{n}   = [ 79 129 189; ... %Blue
%                     79 129 189; ... %Blue
%                   ]/255;
% markersize{n} = 6; n = n + 1;
% 
% fnc{n} = @plot; x{n} = linspace(-1/0.01/2, 1/0.01/2, length(x{n-1})); 
% myy = zeros(1,length(x{n}));  
% myy(~(x{n}/10-floor(x{n}/10))) = cos(2*pi/4*x{n}(~(x{n}/10-floor(x{n}/10))));
% y{n} = 10*1./(x{n}(2)-x{n}(1))./length(x{n-1})*fftshift(abs(fft(myy)));
% y{n} = y{n} .* (abs(x{n}) < 1/10);
% xlbl{n} = '\Omega'; ylbl{n} = 'X(\Omega)'; figwidth{n} = 3.33; 
% hideticks{n} = false; xTickSuffix{n}  = '(2 \pi)'; 
% axis{n} = [-2 2 0 1.75];
% n = n + 1;





pltopt{n} = [];
figheight{n} = [];
axis{n} = [];
figwidth{n} = [];
hideticks{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} = [];
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}, ...
                  'hideticks', hideticks{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}, ...
                  'caption', caption{n}, 'captionFile', [namebase 'caption' num2str(n, '%03u') '.html']);
end


end
