f1=[5000 10000 20000 40000 100000 150000 200000 400000 500000];
f=5000:5000:500000;
r1=[268 268 269  271 282 295 312 390 425];
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=1.2; d2=2;d3=.3;
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);
A(k)=cosh(gamma(k)*d1);
D(k)=A(k);
C(k)=(1/zc(k))*sinh(gamma(k)*d1);
e(k)=A(k)*D(k)-B(k)*C(k);

end
for k=1:length(f);
B2(k)=zc(k)*sinh(gamma(k)*d2);
A2(k)=cosh(gamma(k)*d2);
D2(k)=A2(k);
C2(k)=(1/zc(k))*sinh(gamma(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);
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);

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)];
m5=m1*m2*m3*m4;
hc(k)= rr/(m5(1,1)*rr+m5(1,2));
hc3(k)=(abs(hc(k)))^2;
end
semilogy(f,hc3)