In [1]:

```
import math
import cmath
#(a)Calculate the line Characteristic Impedance
R=2 #resistance ohms/m
L=8*(10**-9) #inductance H/m
C=0.23*(10**-12)#capacitance Farad
f=1*(10**9) #frequency hertz
G=0.5*(10**-3) #conductance mho/m
w=2*math.pi*f #angular frequency hertz
Z0=sqrt((R+(1j*w*L))/(G+(1j*w*C)))
X=round(Z0.real,2)
Y=round(Z0.imag,2)
Z0=complex(X,Y)
print"The line characteristic impedance is =",Z0
#(b)Calculate the propagation constant
r=sqrt((R+(1j*w*L))*(G+(1j*w*C)))
X=round(r.real,3)
Y=round(r.imag,3)
r=X+1j*Y
print"The propagation constant is =",r
```

In [13]:

```
import cmath
import math
#(a)Calculate the reflection coefficient
Zl=70+(1j*50) #load impedance ohms
Z0=75+(1j*0.01) #characteristic impedance ohms
r=(Zl-Z0)/(Zl+Z0)
X=round(r.real,2)
Y=round(r.imag,2)
r=complex(X,Y)
print"(a) The reflection coefficient is =",r
#(b)Calculate the transmission coefficient
T=(2*Zl)/(Zl+Z0)
X=round(T.real,2)
Y=round(T.imag,2)
l=complex(X,Y)
print"(b) The transmission coefficient is =",l
#(c)Verify the relationship shown in Eq(3-2-21) ie. T**2=(Zl/Z0)*(1-(r**2)
q=T**2 #where T is the transmission coefficient
o=cmath.phase(q) #phase of T**2 in radians
o=round(math.degrees(o),2)
M=round(abs(T),2) #magintue of T**2
print"(c) The value of T**2 in polar coordinates is(magnitude,phase)=","(",M,",",o,"degree )"
p=(Zl/Z0)*(1-(r**2))
o=cmath.phase(p) #phase of (Zl/Z0)*(1-(r**2) in radians
o=round(math.degrees(o))
M=round(abs(T),2) #magintue of (Zl/Z0)*(1-(r**2)
print"The value of (Zl/Z0)*(1-(r**2)) in polar coordinates is(magnitude,phase)=","(",M,",",o,"degree )"
print"Since T**2=(Zl/Z0)*(1-(r**2)) hence the relationship shown in Eq(3-2-21) is verified"
#(d)Verify the transmission coefficient equals the algebraic sum of 1 plus the reflection coefficient as shown in Eq(2-3-18)
y=r+1
print"(d) T =",l
print" y=r+1=",y
print"Since T=r+1 hence the relationship shown in Eq(2-3-18) is verified"
```

In [14]:

```
import cmath
#(a)Calculate the reflection coefficient
Zl=73-(1j*42.5) #load impedance ohms
Z0=50+(1j*0.01) #characteristic impedance ohms
r=(Zl-Z0)/(Zl+Z0)
o=cmath.phase(r) #in radians
o=round(math.degrees(o),1)
M=round(abs(r),3)
print"The reflection coefficient is(magnitude,phase) =","(",M,",",o,"degree)" #calculation mistake in book
#(b)Calculate the standing-wave ratio
p=(1+M)/(1-M)
print"The standing-wave ratio is =",round(p,2) #answer is wrong in book
```

In [15]:

```
import math
#(a)Calculate the input impedance
Bd=(((2*math.pi)/l)*(l/4)) #from Eq(3-4-26) the line that is 2.25 wavelengths long looks like a quarter-wave line
#l is the wavelength
R0=50.0 #characteristic impedance in ohms
Rl=75 #load resistance impedance
Zin=(R0**2)/Rl
print"The input impedance((in ohms) is =",round(Zin ,2),"ohms"
#(b)Calculate the magnitude of the instantaneous load voltage
rl=(Rl-R0)/(Rl+R0) #reflection coefficient
V=30 #open-circuit output voltage
Vl=V*(exp(-1j*Bd))*(1+rl)
Vl=abs(Vl)
print"The instantaneous voltage at the load(in V) is =",int(Vl),"V"
#(c) Calculate the instantaneous power delivered to the load
Pl=(Vl**2)/Rl
print"The instantaneous power delivered to the load(in W)is =",round(Pl,2),"W"
```

In [23]:

```
#location determination of voltage maximum and minimum from load
Zl=1+1j*1 #Given normalised load impedance
print"1. Enter Zl=1+(j*1) on the chart.\n"
print"2. Read 0.162 lambda on the distance scale by drawing a dashed-straight line from the centre of the chart through the load point and inersecting the distance scale.\n"
print"3. Move a distance from the point at 0.162 lambda towards the generator and first stop at the voltage maxima on the right-hand real axis at 0.25 lambda."
lamda = 5 #Given wavelength =5 cm
d1Vmax=round((0.25-0.162)*lamda,2)
print"d1(Vmax) (in cm)=",d1Vmax,"cm","\n"
print"4. Similarly,move a distance from the point of 0.162 lambda towards the generator and first stop at the voltage minimum on the left-hand real axis at 0.5 lambda"
d2Vmin=(0.5-0.162)*lamda
print"d2(Vmin) (in cm)=",d2Vmin,"cm","\n"
print"5. Make a standing wave circle with the centre (1,0) and pass the circle through the point of 1+j1.The location intersected by the circle at the right portion of the real axis indicates the SWR.This is p=2.6"
```

In [28]:

```
#Impedance determination with short-circuit minima shift
print"1. When the line is shorted ,the first voltage minimum occurs at the place of the load.","\n"
print"2. When the line is loaded ,the first voltage minimum shifts 0.15 lambda from the load. The distance between two successive minimas is one-half the wavelength.","\n"
print"3. Plot a SWR cirle for p=2 .","\n"
print"4. Move a distance of 0.15 lambda from the minimum point along the distance scale toward the load and stop at 0.15 lambda.","\n"
print"5. Draw a line from this point to the centre of the chart.","\n"
print"6. The intersection between the line and the SWR circle is Zt=1-j*0.65","\n"
Zt=1-(1j*0.65)
Z0=50 #characeristic impedance of the line(ohms)
Zl=Zt*Z0
print"7. The load impedance is(in ohm)=",Zl,"ohms"
```

In [77]:

```
#calculate the stub position(closest to the load)and length so that a match is obtained
R0=50 #characteristic impedance(ohms)
Zl=50/(2+1j*(2+sqrt(3)))
zl=Zl/R0 #normaised load impedance
yl=1/zl #normaised load admittance
yl=complex(yl.real,round(yl.imag,3))
print"1. Compute the normalised load admittance and enter it on the smith chart"
print" yl=(1/zl)=(R0/Zl)=",yl,"\n"
print"2.Draw a SWR circle throuh the point of yl so that he circle intersects the unity circle at the point yd."
print" yd=",complex(1,-2.6)
print" Note that there are infinite number of yd.Take the one that allows the stub to be attached as closely as possible to the load","\n"
print"3. Since the charcteristic impedance of the stub is different from that of the line ,the condition for impedance matching at the junction requires Y11=Yd + Ys ,where Ys is the susceptance that the stub will contribute.\n"
print"It is clear that the stub and the portion of the line from the load to the junction are in parallel,as seen by the main line extending to the generator.The admittances must be converted to normalised values for matching on the smith chart.Then Eq(3-6-2) becomes"
print" y11*Y0= yd*Y0 + ys*y0s"
y11=1
Y0=100 #charcteristic impedance of the stub(ohms)
Y0s=50
print" ys=(y11-yd)*(Y0/Y0s)=", (y11-yd)*(Y0/Y0s),"\n"
print"4. The distance between the load and the stub position can be calculated from the distance scale as"
print" d=(0.302-0.215)*lambda=",(0.302-0.215),"lambda \n"
print"5. Since the stub contributes a susceptance of +j5.20 ,enter +j5.20 on the chart and determine the required distance l from the short circuited end(z=0,y=infinity),which corresponds to the right side of the real axis on the chart,by transversing the chart towards the generator until the point of +j5.20 is reached. \n"
print" Then l=(0.5 -0.031)lambda =0.469 lambda.\n"," When a line is matched at the junction ,there will be no standing wave in the line from the stub to the generator"
print"6. If an inductive stub is required \n"," y'd = 1+j2.6","\n"," and the susceptance will be \n"," y's =-j5.2"
print"7. The position of the stub from the load is \n"," d'=(0.5-(0.215-0.198))lambda = 0.483 lambda" ,"\n"," and the length of the short-circuted stub is \n"," l'=0.031 lambda"
```

In [93]:

```
#Determine the length of short-circuited stubs when the match is achieved.What terminations are forbidden for matching the line by the double-stub device
Zl=100+(1j*100) #Terminating impedance(ohms)
R0=50 #charcteristic impedance of the stub and the line(ohms)
zl=Zl/R0
print"1. Compute the normalised load impedance and enter it on the smith chart \n"," zl=",zl,"\n"
print"2. Plot a SWR p circle and read the normalised load admittance 180 degree out of phase with zl on the SWR circle:"
yl=1/zl
print" yl=",yl,"\n"
#result is drawn on the basis of smith chart
print"3. Draw the spacing circle of (3/8)lambda by rotating the constant-conductance unity circle (g=1) through a phase angle of 2Bd=2B(3/8)lambda =3/2(pi)towards the load.Now y11 must be on this spacing circle ,since yd2 will be on the g=1 circle(y11 and yd2 are 3/8lambda apart). \n"
print"4. Move yl for a distance of 0.4 lambda from 0.458 to 0.358 along the SWR p circle toward the generator and read yd1 on the chart:"
yd1=0.55- 1j*1.08
print" yd1=0.55-1j*1.08","\n"
print"5. There are two possible solutions for y11.They can be found by carrying yd1 along the constant-conducatnce (g=0.55)circle that intersects the spacing circle at two points \n"," y11=0.55-j0.11","\n"," y'11=0.55-j1.88"
y11=0.55-(1j*0.11)
y112=0.55-(1j*1.88)
print"6. At the junction 1-1 \n"," y11=yd1+ys1 \n"," ys1=",y11-yd1,"\n"," ys12=",y112-yd1
ys12=y112-yd1
print(ys12,'ys12=')
print"7. The length of the stub 1 are found as \n"," l1=(0.25+0.123)lambda=0.373lambda \n"," l'1=(0.25-0.107)lambda=0.143 lambda \n"
print"8. The (3/8)lambda section of the line transforms y11 to yd2 and y11 to y'd2 along their constant standing-wave circles respectively .That is \n"," yd2=1-j0.61 \n"," y'd2=1+j2.60"
print"9. Then stub 2 must contribute \n"," ys2=+j0.61 \n"," y's2=-j2.6"
print"10. The lengths of the stub 2 are found as \n"," l2=(0.25+0.087)lambda=0.337 lambda \n"," l'2=(0.308-0.25)lambda=0.058 lambda"
print"11. It can be seen that normaised admittance yl located inside the hatched area cannot be brought to lie on the locus of y11 or y'11 for a possible match by the parallel connection of any short-circuited stub because the spacing circle and g=2 circle are mutually tangent.Thus the area of g=2 circle is called the forbidden region of the normalised load admittance for possible match."
```