% iSIM complix numbers 
% October 30, 2017


% Worksheet
% 1)
j=1i; % use our notation of j instead of i

z1 = 1+ j;
z2 = 3 + 4*j;

z1plusz2 = z1+z2
z1minusz2 = z1-z2
z1timesz2 = z1*z2
z1overz2 = z1/z2

% Plot
figure
myz = z1;
colorchoice = 'b';
quiver(0, 0, real(myz), imag(myz),'LineWidth',3,'Color',  colorchoice,'AutoScale','off')

hold on

myz = z2;
colorchoice = 'm';
quiver(0, 0, real(myz), imag(myz),'LineWidth',3,'Color',  colorchoice,'AutoScale','off')
set(gca,'FontSize',18);
av = 10;
axis([-av av -av av]); grid on; 
ylabel('Imaginary'); xlabel('Real');
%% Plot add and subtract
figure
myz = z1;
colorchoice = 'b';
quiver(0, 0, real(myz), imag(myz),'LineWidth',3,'Color',  colorchoice,'AutoScale','off')

hold on

myz = z2;
colorchoice = 'm';
quiver(real(z1), imag(z1), real(myz), imag(myz),'LineWidth',3,'Color',  colorchoice,'AutoScale','off')

myz = z1plusz2;
colorchoice = 'r';
quiver(0, 0, real(myz), imag(myz),'LineWidth',3,'Color',  colorchoice,'AutoScale','off')

myz = z1minusz2;
colorchoice = 'g';
quiver(0, 0, real(myz), imag(myz),'LineWidth',3,'Color',  colorchoice,'AutoScale','off')

set(gca,'FontSize',18);
av = 6;
axis([-av av -av av]); grid on; 
ylabel('Imaginary'); xlabel('Real');
legend({'z1','z2','z1 plus z2', 'z1 minus z2'})
hold off

%% Plot multiples
figure
myz = z1;
colorchoice = 'b';
quiver(0, 0, real(myz), imag(myz),'LineWidth',3,'Color',  colorchoice,'AutoScale','off')

hold on

myz = z2;
colorchoice = 'm';
quiver(0, 0, real(myz), imag(myz),'LineWidth',3,'Color',  colorchoice,'AutoScale','off')

myz = z1timesz2;
colorchoice = 'r';
quiver(0, 0, real(myz), imag(myz),'LineWidth',3,'Color',  colorchoice,'AutoScale','off')

myz = z1overz2;
colorchoice = 'g';
quiver(0, 0, real(myz), imag(myz),'LineWidth',3,'Color',  colorchoice,'AutoScale','off')

set(gca,'FontSize',18);
av = 7;
axis([-av av -av av]); grid on; 
ylabel('Imaginary'); xlabel('Real');
legend({'z1','z2','z1 times z2', 'z1 over z2'})
%% z3 or lpf
w = logspace(-3,3);
r3 = 1./(sqrt(1+w.^2));

figure; 
subplot(2,1,1);
loglog(w,r3,'LineWidth',3);
xlabel('w (rad/s)'); ylabel('Amplitude');
set(gca,'FontSize',18);
%
subplot(2,1,2);
theta3 = atand(-w);
semilogx(w,theta3,'LineWidth',3);
xlabel('w (rad/s)'); ylabel('Phase (rad)');
set(gca,'FontSize',18);
%
subplot(2,1,1); title('Low-Pass Filter')


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% z4 or hpf

w = logspace(-3,3);
r4 = w./(sqrt(1+w.^2));

figure; 
subplot(2,1,1);
loglog(w,r4,'LineWidth',3);
xlabel('w (rad/s)'); ylabel('Amplitude');
set(gca,'FontSize',18);
%
subplot(2,1,2);
theta4 = atan(1./w); % or atan((pi./2)-w);
semilogx(w,theta4,'LineWidth',3);

xlabel('w (rad/s)'); ylabel('Phase (rad)');
set(gca,'FontSize',18);
%
subplot(2,1,1); title('High-Pass Filter')

%% Brian's z at the end (you potentially can do a comet plot)
Z = 1./(1+sqrt(-1)*w);
plot(Z)
