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

close all;

addpath(genpath('../matlab/'))
namebase = ['./'];
Ts = 0.01; Fs = 1/Ts;
T0 = 1000;

n = 1;

% t{ 1} = linspace(-4*pi-pi/100,4*pi+pi/100,T0);    ticks{ 1} = [-4*pi:pi:4*pi];   x{ 1} = triangularPulse(-pi/2+0,0,pi/2+0,mod(t{1},2*pi))+triangularPulse(-pi/2+0,0,pi/2+0,mod(-t{1},2*pi));
% t{ 2} = linspace(-4*pi-pi/100,4*pi+pi/100,T0);    ticks{ 2} = [-4*pi:pi:4*pi];   x{ 2} = .5*triangularPulse(-pi+0,0,pi+0,mod(t{1},2*pi))+.5*triangularPulse(-pi+0,0,pi+0,mod(-t{1},2*pi));
% t{ 3} = -10:1:10;    ticks{ 3} = [-40:5:40];   x{ 3} = sinc(t{ 3}/8).^2;
% t{ 4} = -5:1:5;    ticks{ 4} = [-20:5:20];   x{ 4} = sinc(t{ 4}/4).^2;
% t{ 5} = linspace(-4*pi-pi/100,4*pi+pi/100,T0);    ticks{ 5} = [-4*pi:pi:4*pi];   x{ 5} = triangularPulse(-pi/2+0,0,pi/2+0,mod(t{1},2*pi))+triangularPulse(-pi/2+0,0,pi/2+0,mod(-t{1},2*pi));
% t{ 6} = linspace(-4*pi-pi/100,4*pi+pi/100,T0);    ticks{ 6} = [-4*pi:pi:4*pi];   x{ 6} = triangularPulse(-pi/4+0,0,pi/4+0,mod(t{1},pi))+triangularPulse(-pi/4+0,0,pi/4+0,mod(-t{1},pi));
% t{ 7} = linspace(-4*pi-pi/100,4*pi+pi/100,T0);    ticks{ 7} = [-4*pi:pi:4*pi];   x{ 7} = 2*triangularPulse(-pi/4+0,0,pi/4+0,mod(t{1},2*pi))+2*triangularPulse(-pi/4+0,0,pi/4+0,mod(-t{1},2*pi));
% t{ 8} = -10:1:10;    ticks{ 8} = [-40:5:40];   x{ 8} = sinc(t{ 8}/8).^2;
% t{ 9} = -20:1:20;    ticks{ 9} = [-80:5:80];   x{ 9} = zeros(1,2*(length(t{8})-1)+1); x{9}(1:2:end) = x{ 8};
% t{10} = -20:1:20;    ticks{10} = [-80:5:80];   x{10} = resample(x{8}, 2, 1); x{10} = x{ 10}(1:(end-1));
% t{11} = linspace(-4*pi-pi/100,4*pi+pi/100,T0);    ticks{11} = [-4*pi:pi:4*pi];   x{11} = .25*triangularPulse(-3*pi/2+0,0,3*pi/2+0,mod(t{1},2*pi))+0.25*triangularPulse(-3*pi/2+0,0,3*pi/2+0,mod(-t{1},2*pi));
% t{12} = -9:3:10;    ticks{ 12} = [-20:20:20];   x{ 12} = sinc(t{ 12}/8).^2;
% t{13} = linspace(-4*pi-pi/100,4*pi+pi/100,T0); t14 = t{13}(t{13} > -pi/4 & t{13} < pi/4);  ticks{13} = [-4*pi:pi:4*pi];   x{13} = .25*triangularPulse(-3*pi/2+0,0,3*pi/2+0,t{13}).*(t{13} > -pi & t{13} < pi) + .25*triangularPulse(-3*pi/2+0,0,3*pi/2+0,t{13}+2*pi).*(t{13}+2*pi > -pi & t{13}+2*pi < pi) + .25*triangularPulse(-3*pi/2+0,0,3*pi/2+0,t{13}-2*pi).*(t{13}-2*pi > -pi & t{13}-2*pi < pi) + .25*triangularPulse(-3*pi/2+0,0,3*pi/2+0,t{13}+4*pi).*(t{13}+4*pi > -pi & t{13}+4*pi < pi) + .25*triangularPulse(-3*pi/2+0,0,3*pi/2+0,t{13}-4*pi).*(t{13}-4*pi > -pi & t{13}-4*pi < pi);





% DOWNSAMPLING

fnc{n} = @stem; 
x{n} = -10:1:10;
y{n} = sinc(x{n}/4).^2;
xlbl{n} = 'n'; ylbl{n} = 'x[n]'; figwidth{n} = 3.33; 
ynum{n} = false;
axis{n} = [-10 10 -0.1 1];
caption{n} = 'Original signal $x[n]$.';
markersize{n} = 6; n = n + 1;

fnc{n} = @plot; 
x{n} = linspace(-4-.001,4+.001,T0);
y{n} = triangularPulse(-1/2+0,0,1/2+0,mod(x{n},2)) + triangularPulse(-1/2+0,0,1/2+0,mod(-x{n},2));
xlbl{n} = '\omega'; ylbl{n} = 'X(\omega)'; figwidth{n} = 3.33; 
axis{n} = [-4 4 -0.1 1];
xTickSuffix{n}  = '\pi'; 
caption{n} = 'DTFT of $x[n]$.';
markersize{n} = 6; n = n + 1;

fnc{n} = @stem; 
x{n} = -10:1:10;
y{n} = sinc(x{n}/4*2).^2;
xlbl{n} = 'n'; ylbl{n} = 'x[n]'; figwidth{n} = 3.33; 
ynum{n} = false;
axis{n} = [-5 5 -0.1 1];
caption{n} = 'DTFT of $x[n]$.';
markersize{n} = 6; n = n + 1;

fnc{n} = @plot; 
x{n} = linspace(-4-.001,4+.001,T0);
y{n} = .5*triangularPulse(-1+0,0,1+0,mod(x{n},2))+.5*triangularPulse(-1+0,0,1+0,mod(-x{n},2));
xlbl{n} = '\omega'; ylbl{n} = 'X(\omega)'; figwidth{n} = 3.33; 
axis{n} = [-4 4 -0.1 1];
xTickSuffix{n}  = '\pi'; 
caption{n} = 'Downsampled signal $x[2 n]$.';
markersize{n} = 6; n = n + 1;


fnc{n} = @stem; 
x{n} = -10:1:10;
y{n} = sinc(x{n}/4*3).^2;
xlbl{n} = 'n'; ylbl{n} = 'x[n]'; figwidth{n} = 3.33; 
ynum{n} = false;
axis{n} = [-4 4 -0.1 1];
caption{n} = 'Downsampled signal $x[3 n]$.';
markersize{n} = 6; n = n + 1;

fnc{n} = @plot; 
x{n} = linspace(-4-.001,4+.001,T0);
y{n} = (1/3)*(triangularPulse(-3/2+0,0,3/2+0,mod(x{n},2))+triangularPulse(-3/2+0,0,3/2+0,mod(-x{n},2)));
xlbl{n} = '\omega'; ylbl{n} = 'X(\omega)'; figwidth{n} = 3.33; 
axis{n} = [-4 4 -0.1 1];
xTickSuffix{n}  = '\pi'; 
caption{n} = 'DTFT of $x[3 n]$.';
markersize{n} = 6; n = n + 1;




fnc{n} = @stem; 
x{n} = -10:1:10;
y{n} = sinc(x{n}/4*4).^2;
xlbl{n} = 'n'; ylbl{n} = 'x[n]'; figwidth{n} = 3.33; 
ynum{n} = false;
axis{n} = [-2 2 -0.1 1];
caption{n} = 'Downsampled signal $x[4 n]$.';
markersize{n} = 6; n = n + 1;

fnc{n} = @plot; 
x{n} = linspace(-4-.001,4+.001,T0);
y{n} = (1/4)*(triangularPulse(-4/2+0,0,4/2+0,mod(x{n},2))+triangularPulse(-4/2+0,0,4/2+0,mod(-x{n},2)));
xlbl{n} = '\omega'; ylbl{n} = 'X(\omega)'; figwidth{n} = 3.33; 
axis{n} = [-4 4 -0.1 1];
xTickSuffix{n}  = '\pi'; 
caption{n} = 'DTFT of $x[4 n]$.';
markersize{n} = 6; n = n + 1;











% DOWNSAMPLING WITH ANTI-ALIASING 
aa = 3/2;
fnc{n} = @plot; 
x{n} = linspace(-4-.001,4+.001,T0);
%y{n} = (1/3)*(triangularPulse(-3/2+0,0,3/2+0,mod(x{n},2))+triangularPulse(-3/2+0,0,3/2+0,mod(-x{n},2)));
y{n} = (1/3)*(triangularPulse(-aa+0,0,aa+0,x{n}).*(x{n} > -1 & x{n} < 1) + triangularPulse(-aa+0,0,aa+0,x{n}+2).*(x{n}+2 > -1 & x{n}+2 < 1) + triangularPulse(-3*1/2+0,0,3*1/2+0,x{n}-2).*(x{n}-2 > -1 & x{n}-2 < 1) + triangularPulse(-aa+0,0,aa+0,x{n}+4).*(x{n}+4 > -1 & x{n}+4 < 1) + triangularPulse(-aa+0,0,aa+0,x{n}-4).*(x{n}-4 > -1 & x{n}-4 < 1));
xlbl{n} = '\omega'; ylbl{n} = 'X(\omega)'; figwidth{n} = 3.33; 
axis{n} = [-4 4 -0.1 1];
xTickSuffix{n}  = '\pi'; 
caption{n} = 'DTFT of $x[3 n]$ after applying an anti-aliasing filter.';
markersize{n} = 6; n = n + 1;

aa = 4/2;
fnc{n} = @plot; 
x{n} = linspace(-4-.001,4+.001,T0);
%y{n} = (1/3)*(triangularPulse(-3/2+0,0,3/2+0,mod(x{n},2))+triangularPulse(-3/2+0,0,3/2+0,mod(-x{n},2)));
y{n} = (1/4)*(triangularPulse(-aa+0,0,aa+0,x{n}).*(x{n} > -1 & x{n} < 1) + triangularPulse(-aa+0,0,aa+0,x{n}+2).*(x{n}+2 > -1 & x{n}+2 < 1) + triangularPulse(-aa+0,0,aa+0,x{n}-2).*(x{n}-2 > -1 & x{n}-2 < 1) + triangularPulse(-aa+0,0,aa+0,x{n}+4).*(x{n}+4 > -1 & x{n}+4 < 1) + triangularPulse(-aa+0,0,aa+0,x{n}-4).*(x{n}-4 > -1 & x{n}-4 < 1));
xlbl{n} = '\omega'; ylbl{n} = 'X(\omega)'; figwidth{n} = 3.33; 
axis{n} = [-4 4 -0.1 1];
xTickSuffix{n}  = '\pi'; 
caption{n} = 'DTFT of $x[4 n]$ after applying an anti-aliasing filter.';
markersize{n} = 6; 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} = [];
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
