clear
pack

f1=[0 2500 10000 20000 40000 100000 150000 200000 400000 500000 650000 750000 850000 1000000 1100000];

f=2500:1000:1100000;d=4000;
r1=[280 280.007 280.11 280.44  281.748 290.433 302.070 316.393 383.562 417.427 465.785 496.218 525.274 566.521 592.628];
l1=10^(-6).*[587.132 587.075 586.738 586.099 584.443 577.878 571.525 564.889 539.437 528.409 514.272 506.304 499.343 490.494 485.481];
%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)*43*ones(size(f));
g=zeros(size(f));z1=zeros(size(f));y=zeros(size(f));d1=1.1; d5=.55;d7=1.5*.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));
gamma(k)=sqrt(z1(k)*y(k));
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);
B7(k)=zc(k)*sinh(gamma(k)*d7);





A(k)=cosh(gamma(k)*d1);
A5(k)=cosh(gamma(k)*d5);
A7(k)=cosh(gamma(k)*d7);
D7(k)=A7(k);
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);
C7(k)=(1/zc(k))*sinh(gamma(k)*d7);


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

end
f11=[0  2500 10000 20000 40000  100000 150000 200000 400000  500000 650000 750000 850000 1000000 1100000];
f=2500:1000:1100000;%r11 este rez. per. de .5mm;
r11=[179 179.015 179.244 179.97 182.79 199.608 218.721 239.132 316.23 350.243 396.528 424.835 451.480 488.857 512.317];
l11=10^(-6)*[673.574 673.466 672.923 671.98 669.716 661.677 654.622 647.735 624.309 615.202 604.192 598.261 593.217 586.966 583.495];
r12=[ 113 113.028 113.442 114.737 119.523 143.115 164.938 185.689 255.575 284.753 323.844 347.542 369.758 400.816 420.264];
l12=10^(-6)*[699.258 697.943 693.361 687.008 674.593 642.718 622.050 605.496 563.845 551.323 537.868 531.212 525.813 519.402 515.956];
r63=spline(f11,r12,f);
l63=spline(f11,l12,f);
c63= 50*10^(-9).*ones(size(f));
g63=zeros(size(f));
d63=.5;
for k=1:length(f);
z63(k)=r63(k)+2*pi*f(k)*l63(k)*i;
y63(k)=g63(k)+2*pi*f(k)*c63(k)*i;
zc63(k)=sqrt(z63(k)/y63(k));
gamma63(k)=sqrt(z63(k)*y63(k));
B63(k)=zc63(k)*sinh(gamma63(k)*d63);
A63(k)=cosh(gamma63(k)*d63);
D63(k)=A63(k);
C63(k)=(1/zc63(k))*sinh(gamma63(k)*d63);
e63(k)=A63(k)*D63(k)-B63(k)*C63(k);
end





r2=spline(f11,r11,f);
l2=spline(f11,l11,f);
g2=zeros(size(f));
c2= 50*10^(-9).*ones(size(f));
%g=zeros(size(f));

z11=zeros(size(f));y=zeros(size(f)); d2=1.25;%portiunea cu d=.5mm;
d3=.550;%prima derivatie;
d4=.3048*1.5;%a 2-a derivatie;
d6=.3048*1.5;% a 3-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));
gamma2(k)=sqrt(z11(k)*y2(k));
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);
zg2(k)=zc(k)*cosh(gamma(k)*d4)/sinh(gamma(k)*d4);
zg3(k)=zc(k)*cosh(gamma(k)*d6)/sinh(gamma(k)*d6);


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
uu=imag(gamma);vv=diff(uu./diff(f);gg=f(1:1,1:length(f)-1);
plot(gg,vv)

