#program to find the equivalent voltages and current .
from sympy import symbols,sqrt,Matrix
a,b,A,Zte,V,I,C1,C2,P=symbols('a,b,A,Zte,V,I,C1,C2,P');
P=(a*b*A**2)/(4*Zte);
c=(1/2)*V*I;
d=(1/2)*(A**2)*C1*C2;
C1=sqrt((a*b)/2); # on comparision .
C2=sqrt((a*b)/2)*Zte; # on comparision .
c=Matrix([C1,C2]);
print c;
print "which completes the transmission line equivalence for the TE10 mode "
#program to compute reflection coefficient .
from math import pi,sqrt
a=0.03485;b=0.01580;eipsilao=8.854*10**-12;muo=4*pi*10** -7;
f=4.5*10**9;
w=2*pi*f; # angular frequency .
# for z<0 region air filled.
eipsilar=2.56; # for z>0 region .
ko=w*sqrt(muo*eipsilao);
k=ko*sqrt(eipsilar);
Ba=sqrt(ko**2-(pi/a)**2); # propagation constant in air region z<0.
Bd=sqrt(k**2-(pi/a)**2); # propagation constant in dielectric region z>0.
Zoa=(ko*377)/Ba;
Zod=(ko*377)/Bd;
tao=(Zod-Zoa)/(Zod+Zoa);
print "reflection coefficient",tao
# program to find the z parameter of the two port network .
from sympy import symbols,Matrix
Z11,Z12,Z22,Z21,Za,Zb,Zc=symbols('Z11,Z12,Z22,Z21,Za,Zb,Zc');
Z11=Za+Zc; # for I2=0.
Z12=(Zc/(Zb+Zc))*(Zb+Zc); #for I1=0.
Z21=(Zc/(Za+Zc))*(Za+Zc); # for I2=0.
Z22=Zb+Zc; #for I1=0.
Z=Matrix([[Z11,Z12],[Z21,Z22]]); # z_parameter matrix.
print "Z-parameter of two port network = ",Z
# program to find the s-parameter of 3-dB attenuator circuit .
from numpy import matrix
Za=8.56;Zb=8.56;Zc=141.8;Zo=50.;
S11=(((((Zo+Zb)*Zc)/(Zo+Zb+Zc))+Za)-Zo)/(((((Zo+Zb)*Zc)/(Zo+Zb+Zc))+Za)+Zo); # reflection coefficient seen at port 1.
S22=(((((Zo+Za)*Zc)/(Zo+Za+Zc))+Zb)-Zo)/(((((Zo+Za)* Zc)/(Zo+Za+Zc))+Zb)+Zo); # reflection coefficient seen at port 2.
S12=(((1/((((Zo+Za)*Zc)/(Zo+Za+Zc))+Zb))*(((Zo+Za)* Zc)/(Zo+Za+Zc)))*(Zo/(Zo+Za))); # transmission coefficient from port 2 to 1.
S21=(((1/((((Zo+Zb)*Zc)/(Zo+Zb+Zc))+Za))*(((Zo+Zb)* Zc)/(Zo+Zb+Zc)))*(Zo/(Zo+Zb))); # transmission coefficient from port 1 to 2.
S=matrix([[S11,S12],[S21,S22]]); # sparameter matrix.
print "S-parameter of 3db attenuator circuit is ="
print S
#program to determine the reciprccity and lossless of two port network and find return loss.
from sympy import symbols,I
from numpy import matrix
from math import log10
Rl,tao=symbols('Rl,tao');
S=matrix([[0.1,0.8*I],[0.8*I,0.2]]); # s-parameter matrix.
if (S[0,1]==S[1,0]):
print "the network is reciprocal ."
else:
print "the network is not reciprocal ."
if (S[0,0]**2+S[0,1]**2==1):
print "the network is lossless ."
else:
print "the network is lossy ."
tao=S[0,0]-(S[0,1]*S[1,0])/(1+S[1,1]); #input reflection coefficient .
Rl=-20*log10(abs(tao)); # return loss in dB.
#result
print "return loss at port 1 in dB= %.3f"%Rl
#program to find the ABCD parameter of a two-port network .
from sympy import symbols,Matrix
A,B,C,D,V1,V2,I1,I2,Z=symbols('A,B,C,D,V1,V2,I1,I2,Z');
#A=V1/V2; #for i2=0;
A=1;
B=V1/(V1/Z);
C=0;
D=I1/I1;
ABCD=Matrix([[A,B],[C,D]]);
#result
print "abcd parameter"
print ABCD
# program to find the admittance matrix for bridge-T network.
from sympy import symbols,Matrix
Za,Z1,Z2,Z3,Y,Ya,Yb,D=symbols('Za,Z1,Z2,Z3,Y,Ya,Yb,D');
Za=Matrix([[Z1+Z2,Z2],[Z2,Z1+Z2]]);
Yb=Matrix([[1/Z3,-1/Z3],[-1/Z3,1/Z3]]);
Y1=1/Z1;Y2=1/Z2;
Ya=Za**-1
Y=Ya+Yb;
D=((Z2+Z1)**2-Z2**2);
# result
print "admittance matrix for bridge-T network="
print Y