









f1=[1000 10000 20000 40000 100000 150000 200000 400000 500000];
%f=5000:6780.8:500000;
%d=5000;
f=linspace(1000,500000,127);
d=(500000-1000)/126
r1=[268 268 269  271 282 295 312 390 425]; %diametrul conductorului=.4mm (26-AWG);
l1=10^(-6).*[680 678 675 669 650 642 635 619 608];
%c5=polyfit(f1,r1,3);

%c15=polyfit(f1,l1,3);
%r=polyval(c5,f);
%l=polyval(c15,f);
r=spline(f1,r1,f);
l=spline(f1,l1,f);
c=10^(-9)*45.5.*ones(size(f));
g=zeros(size(f));z1=zeros(size(f));y=zeros(size(f));d1=4*.3048; d5=4*.3048;%ultima portiune;
for k=1:length(f);
z1(k)=r(k)+2*pi*f(k)*l(k)*i;
y(k)=g(k)+2*pi*f(k)*c(k)*i;
zc(k)=sqrt(z1(k)/y(k)); %diam.=0.4mm;
gamma(k)=sqrt(z1(k)*y(k));%diam.=0.4mm;
alfa(k)=real(gamma(k));
beta(k)=imag(gamma(k));
 B(k)=zc(k)*sinh(gamma(k)*d1);
B5(k)=zc(k)*sinh(gamma(k)*d5);

A(k)=cosh(gamma(k)*d1);
A5(k)=cosh(gamma(k)*d5);
D5(k)=A5(k);
D(k)=A(k);
C(k)=(1/zc(k))*sinh(gamma(k)*d1);
C5(k)=(1/zc(k))*sinh(gamma(k)*d5);

e(k)=A(k)*D(k)-B(k)*C(k);

end
f11=[1000  5000 10000 50000  100000 150000 300000  500000];
%f=5000:5000:500000;
f=linspace(1000,500000,127);
r11=(1/1.6093).*[277.2 277.5 278  286.8 308.4 337.2 431.6 541.7];%diametrul conductor=.51mm;
l11=(1/1.6093)*10^(-3).*[.986 .984 .982 .958 .935 .920 .888 .857];
g11=(1/1.6093)*10^(-6).*[.115 .466 .853 3.458 6.32 8.993 16.44  25.633];
%c5=polyfit(f1,r1,3);

%c15=polyfit(f1,l1,3);
%r=polyval(c5,f);
%l=polyval(c15,f);
r2=spline(f11,r11,f);
l2=spline(f11,l11,f);
g2=spline(f11,g11,f);
c2=(1/1.6093)*10^(-9)*83.*ones(size(f));
%g=zeros(size(f));

z11=zeros(size(f));y=zeros(size(f)); d2=.0002;%portiunea cu d=.5mm;
d3=.3048*.5;%prima derivatie;
d4=.3048*.5;%a 2-a derivatie;
for k=1:length(f);
z11(k)=r2(k)+2*pi*f(k)*l2(k)*i;
y2(k)=g2(k)+2*pi*f(k)*c2(k)*i;
zc2(k)=sqrt(z11(k)/y2(k));%diam.=0.51mm;
gamma2(k)=sqrt(z11(k)*y2(k));%diam.=0.51mm;
%for k=1:length(f);
B2(k)=zc2(k)*sinh(gamma2(k)*d2);
A2(k)=cosh(gamma2(k)*d2);
D2(k)=A2(k);
C2(k)=(1/zc2(k))*sinh(gamma2(k)*d2);
e2(k)=A2(k)*D2(k)-B2(k)*C2(k);
end
for k=1:length(f);
zg(k)=zc(k)*cosh(gamma(k)*d3)/sinh(gamma(k)*d3);%diam.=0.4mm;
zg2(k)=zc(k)*cosh(gamma(k)*d4)/sinh(gamma(k)*d4);%diam.=0.4mm;
mod(k)=abs(zg(k));fi(k)=angle(zg(k));xr(k)=mod(k)*cos(fi(k));
yi(k)=mod(k)*sin(fi(k));
end
m1=ones(2,2);
m2=ones(2,2);
m3=ones(2,2);
m4=ones(2,2);
m5=ones(2,2);
m6=ones(2,2);
m7=ones(2,2);
rr=135;hc3=ones(size(f));
for k=1:length(f);
m1=[1 135;0 1];
m2=[A(k) B(k);C(k) D(k)];
m3=[1 0;1/zg(k) 1];
m4=[A2(k) B2(k);C2(k) D(k)];
m6=[1 0;1/zg2(k) 1];
m7=[A5(k) B5(k);C5(k) D5(k)];
m5=m1*m3*m2*m4*m7*m6;
hc(k)= rr/(m5(1,1)*rr+m5(1,2));
hc3(k)=(abs(hc(k)))^2;
end
semilogy(f,hc3)
xlabel('Frequency(Hz)');ylabel('Channel Power Transfer Characteristic')
title('Loop 17 transfer characteristic')
betaa=10^(-13);
for n=1:k
%hc(n)=exp(-alfa(o)*f(n)^.5);
hx(n)=betaa*f(n)^1.5;
end
cap=0;
for n=1:k
cap= cap+d*log2(1+hc3(n)/(hx(n)));
end
w=500000;m=127;
l=.12;l0=18000;
%beta=[10^(-7.5) 10^(-8) 10^(-9) 10^(-9.5) 10^(-10.5)];
%beta=[7.39*10^(-5.0)];
%alfa=1.158*l/l0;
%w=30.002;%m=100;
%d=.395;
%f=.772:d:w-d/2;
%f=linspace(1.167,30.002,74);
k=max(size(f));p=ones(1,k);

%l=linspace(.000985,.000872,127);
%c=(.083*10^(-6)).*ones(1,k);hc=ones(1,k);

%for t=1:k
%r(t)=438.29996+33.3*(.00001*f(t))+5.012*(.00001*f(t))^2-.42*(.00001*f(t))^3+.012*(.00001*f(t))^4-.001*(.00001*f(t))^5;

%gamma(t)=sqrt((r(t)+i*2*pi*f(t)*l(t))*(i*2*pi*f(t)*c(t)));
%end
%alfa=unwrap(real(gamma));
%for t=1:k

%hc(t)=exp(-alfa(t)*2*9000*(.3048/1609.3));
%hc1(t)=exp(-1.4*.5*f(t)^.5);

%end
betaa=[10^(-13)];
x1=ones(1,43);x11=.5.*x1;x12=ones(1,27);x13=ones(1,19);x133=.5.*x13;x14=ones(1,38);
y1=[x11 x12 x133 x14];
for g=1:1
for n=1:k
%hc3(n)=10^(-2.32*l*(f(n)^.5)-.238*f(n)*l);
hx(n)=betaa(g)*f(n)^1.5;
end
p1=20;
la=w/p1
n0=10^(-11);n1=n0*d;
for n=1:k
   if y1(n)<=.5
a(n)=hx(n)*(hx(n)+hc3(n));n1=n0*d;
b(n)=n1*(2*hx(n)+hc3(n));c(n)=n1*(n1-d*(1/la)*hc3(n));
p(n)=(1/(2*a(n)))*(-b(n)+(b(n)^2-4*a(n)*c(n))^.5);
else
   p(n)=d/(2*la)-n1/(2*hc3(n));
   end
end

s=0;
for t=1:k
s=s+p(t);
end
dif=s-p1;
while dif<0
e=.005;
la=(1-e)*la;
n1=n0*d;

for n=1:k
   if y1(n)<=.5
a(n)=hx(n)*(hx(n)+hc3(n));b(n)=n1*(2*hx(n)+hc3(n));c(n)=n1*(n1-(1/la)*d*hc3(n));
p(n)=(1/(2*a(n)))*(-b(n)+(b(n)^2-4*a(n)*c(n))^.5);
else
   p(n)=d/(2*la)-n1/(2*hc3(n));
   end
end
%q=zeros(1,k);y=q>=c;u=y.*p;
s=0;
for t=1:k
s=s+p(t);
end
dif=s-p1;
end
x=1:1:k;f1=d.*x;%p2=(1/1).*u;
plot(f1,p)
%hold on
%semilogy(f1,p2)
cap(g)=0;
for n=1:k
cap(g)= cap(g)+d*log2(1+p(n)*hc3(n)/(n1+hx(n)*p(n)));
end
end
xlabel ('frecventa in khz');
ylabel ('densitatea spectrala per canal in mW')
title('Distributia puterii pentru o capacitate maxima')
%gtext('beta=10^(-7.5)') 
%gtext('beta=10^(-8)') 
gtext('beta=1.0*10^(-13)') 
%gtext('beta=10^(-9.5)') 
%gtext('beta=10^(-10.5)') 

