clear all
close all

L = 40;  %Cable length (m)
Vt = 21.6;
Vc = 19.0;

data = load('awg.txt');

awg_size = data(1:14,1); %Guage
awg_diam = data(1:14,2); %Inches
awg_R  = data(1:14,3)/1000; %Ohms per m

plotyy(awg_size,awg_diam,awg_size,awg_R);
xlabel('Wire Guage');

I = 4:4:20;

Delta_V = 2*L*awg_R*I;

figure('Position',[520   179   779   919]);
ah1 = subplot(2,1,1)
plot(awg_size,Vt-Delta_V,awg_size,Vc*ones(length(awg_size),1),'--');
xlabel('Wire Size (AWG)');
ylabel('Delivered Voltage');
legendtxt = cell(length(I),1);
for i = 1:length(I)
  legendtxt{i} = ['I = ' num2str(I(i)) ' Amps'];
end
legend(legendtxt,'Location','SouthWest');
title(['Transmission loss versus wire size for ' num2str(Vt) 'V transmission voltage over 40 meter cable']);

ah2 = subplot(2,1,2)
plot(awg_size,100*(Vt-Delta_V)/Vt)
xlabel('Wire Size (AWG)');
ylabel('Efficiency (%)');
legendtxt = cell(length(I),1);
for i = 1:length(I)
  legendtxt{i} = ['I = ' num2str(I(i)) ' Amps'];
end
legend(legendtxt,'Location','SouthWest');



print('-dpdf','TransmissionLoss');
