# calculate the input impedence, output impedence, voltage gain and current gain
import math
#Variable declaration
Hie=500.0 # the h-parameters of the transistor in ohm
Hfe=60.0 # the h-parameters of the transistor in ohm
Ic=3*10**-3 # collector current in ampere
Rb=220*10**3 # resistance in ohm
Rc=5.1*10**3 # resistance in ohm
Vcc=12.0 # voltage in volts
Vbe=0.6 # voltage in volts
Beta=60.0 # for transistor
#Calculations
zi=Hie
zo=Rc
Av=-Hfe*Rc/Hie
Ai=-Hfe
Ib=(Vcc-Vbe)/Rb
Ie=Beta*Ib
re=26*10**-3/Ie
Zin=Beta*math.ceil(re*100)/100
Zout=Rc
Av1=-Rc/re
Ai1=-Beta
#Result
print("part 1 - from h-parameter model:")
print("input impedence (ohm) = %.f"%zi)
print("ouput impedence (k-ohm) = %.1f "%(zo/1000))
print("current gain (unitless) = %.f"%Ai)
print("voltage gain (unitless) = %.f"%Av)
print("\npart 2 - from re model:")
print("base curret (micro-A) = %.1f"%(Ib*10**6))
print("emitter curret (mA) = %.3f"%(Ie*1000))
print("resistance = %.2f"%(math.ceil(re*100)/100))
print("input impedence (ohm) = %.1f"%Zin)
print("ouput impedence (k-ohm) = %.1f"%(Zout/1000))
print("current gain (unitless) = %.f"%Ai1)
print("voltage gain (unitless) = %.f"%(math.ceil(Av1)))
# calculate the input impedence, output impedence, voltage gain and current gain
import math
#Variable declaration
Hie=3.2 # the h-parameters of the transistor in kilo-ohm
Hfe=100.0 # the h-parameters of the transistor
R1=40.0 # resistance in kilo-ohm
R2=4.7 # resistance in kilo-ohm;
Rc=4.0 # resistance in kilo-ohm;
Re=1.2 # resistance in kilo-ohm;
Vcc=16.0 # voltage in volts
Vbe=0.6 # voltage in volts
Beta=100.0 # for transistor
#Calcualtions
Rb=(R1*R2)/(R1+R2)
zi=(Rb*Hie)/(Rb+Hie)
zo=Rc
Av=-(Hfe*Rc)/Hie
Ai=-(Rb*Hfe)/(Rb+Hie)
Vb=(R2*Vcc)/(R1+R2)
Ib=(Vb-Vbe)/(Rb+(1+Beta)*Re)
Ic=math.floor(Beta*Ib*100)/100
Ie=Ic
re=26.0/Ie
Zin=(Rb*(Beta*re*10**-3))/(Rb+(Beta*re*10**-3))
Zout=Rc
Av1=-(Rc*10**3)/re
Ai1=-(Beta*(Rb*10**3))/((Rb*10**3)+(Beta*re))
#Result
print("part 1 -from h-parameter model:")
print("base resistance (kilo-ohm) = %.1f"%Rb)
print("input impedence (kilo-ohm) = %.2f"%zi)
print("ouput impedence (kilo-ohm) = %.f"%zo)
print("current gain (unitless) = %.2f"%Ai)
print("voltage gain (unitless) = %.f"%Av)
print("\npart 2 -from re model:")
print("base voltage (V) = %.3f"%Vb)
print("base curret (micro-A) = %.2f"%(Ib*1000))
print("collector curret (mA) = %.2f"%Ic)
print("emitter curret (mA) = %.2f"%Ie)
print("resistance = %.2f"%re)
print("input impedence (kilo-ohm) = %.2f"%Zin)
print("ouput impedence (kilo-ohm) = %.f"%Zout)
print("current gain (unitless) = %.2f"%Ai1)
print("voltage gain (unitless) = %.1f"%Av1)
#Current gain values are slightly different
# calculate the input impedence, output impedence, voltage gain and current gain
import math
#Variable declaration
Re=4.0 # resistance in kilo-ohm
Rc=3.0 # resistance in kilo-ohm
Vcc=10.0 # collector voltage in volts
Vee=8.0 # emitter voltage in volts
Vbe=0.6 # base voltage in volts
#Calculation
Ie=(Vee-Vbe)/(Re*10**3)
re=math.floor(26*10**-3*100/Ie)/100
zi=((Re*10**3)*re)/((Re*10**3)+re);
zo=Rc;
Av=Rc/(re*10**-3);
Ai=Ie/Ie
#Result
print("emitter current (mA) = %.2f"%(Ie*1000))
print("input impedence (ohm) = %.f"%zi)
print("ouput impedence (kilo-ohm) = %.f"%zo)
print("current gain (unitless) = %.f"%Ai)
print("voltage gain (unitless) = %.2f"%Av)
# Collector efficiency
import math
#Vaariable declaration
P = 8.0 # zero-signal power dissipation
Pac = 2 # AC power output
#Calculations
eff = (Pac/P)*100
#Result
print("Collector Efficiency = %.f %%"%eff)
#example 3.3 is twice in the book
# determine collector efficiency
import math
#Variable declaration
Vmax=25.0 # collector emitter voltag in volts
Vmin=2.5 # collector emitter voltag in volts
#Calculations
eta= 50*((Vmax-Vmin)/(Vmax+Vmin))
#Result
print("collector efficiency (%%) = %.1f"%eta)
# determine maximum output power
import math
#Variable declaration
Rl=80.0 # load resistance in ohm
alfa=5.0 # turn ratio
Ic=120.0 # collector current in milli-ampere
#Calculations
Rl1=alfa**2*Rl
Imax=2*Ic
Imin=0
Irms=(1/math.sqrt(2))*((Imax-Imin)/2.0)
Pout=((Ic*10**-3)**2*Rl1)/2;
#Result
print("load as seen by transformer primary (ohm) = %.f"%Rl1)
print("maximum current (mA) = %.f"%Imax)
print("minimum current (mA) = %.f"%Imin)
print("rms value of current (mA) = %.2f"%Irms)
print("maximum power output (W) = %.1f"%Pout)
# (i) maximum output power (ii) maximum collector efficiency (iii) power rating of the transistor
import math
#Variable declaration
Vcc=10.0 # collector supply voltage in volts
Icq=200.0 # zero-signal collector current in milli-ampere
Rl=2.0 # load resistance in ohm
alfa=5.0 # turn ratio
#Calculations
Pout=(Vcc*(Icq*10**-3))/2
Pin=(Vcc*(Icq*10**-3))
eta=(Pout/Pin)*100
P=(Vcc*(Icq*10**-3))
Rl1=(alfa**2)*Rl
#REsult
print("output power for dc (w) = %.f"%Pout)
print("input power for ac (w) = %.f"%Pin)
print("collector efficiency (%%) = %.f"%eta)
print("power rating of the transistor (w) = %.f"%P)
print("load by the tranformer primary (ohm) = %.f"%Rl1)
# Various parameter calculations
import math
#Variable declaration
alpha=3.0
Podc=0.434 # output ac power in watts
Icq=140.0 # current in milli ampere
Rl=8.0 # load resistance in killo ohms
Vcq=10.0
Vcemax=18.3 # maximum collector to emitter voltage in volts
Vcemin=2.5 # minimum collector to emitter voltage in volta
Icmax=245.0 # maximum collector current in mili ampere
Icmin=25.0 # minimum collector current in mili ampere
#Calculations
Vcc=Vcq
Vlrms=(Vcemax-Vcemin)/(2*math.sqrt(2))
VLrms=(1/alpha)*Vlrms #rms value of load voltage
ILrms=(VLrms/Rl)*10**3 #rms value of load current
Pindc=Vcc*Icq*10**-3 #ac power developed across the load in watts
Pd=Pindc-Podc #power dissipated in watts
n=(Podc/Pindc)*100 #efficieny
#Result
print("maximum collector to emitter voltage in volts = %.1f"%Vcemax)
print("minimum collector to emitter voltage in volts = %.1f"%Vcemin)
print("maximum collector current in mA = %.f"%Icmax)
print("minimum collector current in mA = %.f"%Icmin)
print("rms value of load voltage = %.2f"%VLrms)
print("rms value of load current in mA = %.1f"%ILrms)
print("ac power developed across the load in watts = %.1f"%Pindc)
print("power dissipated in watts = %.3f"%Pd)
print("efficiency = %.f%%"%n)
#Value for rms voltage and current is slightly different than book
# overall efficiency
import math
#Variable declaration
Vcc=20.0 # in volts
Vce=2.5 # in volts
#Calculatins
eta=78.5*(1-(Vce/Vcc))
print(" overall efficiency = %.2f %%"%eta)
# the percent second harmonic distortion
import math
#Variable declaration
V1ce=22.0 # maximum voltage in volts
V2ce=1.2 # minimum voltage in volts
Vceq=10.0 # in volts
#Calculations
D2=(((1.0/2)*(V1ce+V2ce)-Vceq)/(V1ce-V2ce))*100;
#Result
print("the percent harmonic distortion = %.1f %%"%D2)
# the percent second harmonic distortion
import math
#Variable declaration
V1ce=18.0 # maximum voltage in volts
V2ce=2.0 # minimum voltage in volts
Vceq=10.0 # in volts
#Calculations
D2=(((1.0/2)*(V1ce+V2ce)-Vceq)/(V1ce-V2ce))*100
#Result
print("the percent harmonic distortion = %.f %% i.e. no distortion"%D2)
# Percentage Increase in powe
import math
#Variable declaration
#Vs=1.95*sin(400*t);in volt
#io=12*sin400*t+1.2*sin800*t+0.9*sin*1200*t+0.4*sin1600*t
#from current we have
V1=12.0 #in volt
V2=1.2 #in volt
V3=0.9 #in volt
V4=0.4 #in volt
#Harmonic distortion of each component is expressed as :
D2=V2/V1 #unitless
D3=V3/V1 #unitless
D4=V4/V1 #unitless
#Total distortion
D=math.sqrt(D2**2+D3**2+D4**2)
PowerIncrease=D**2*100
print("Total disortion = %.4f or %.2f%%"%(D,D*100))
print("\nTotal Power, P=(1+D2^2)*P1")
print("\nPercentage Increase in power because of distortion=(P-P1)*100/P1")
print("\nPercentage Increase in power = %.3f"%PowerIncrease)
# minimum power drain on the power supply
import math
#Variable declaration
Pl=10.0 # power delivered to load in watt
eta1=80.0/100 # output transformer efficiency
eta=78.5/100 # efficiency of a class B push pull amplfier under optimum condition
Pout=Pl/eta1
Pin=Pout/eta
print("ac power output of amplifier (W) = %.1f"%Pout)
print("minimum power drain on the power supply (W) = %.1f"%Pin)
# minimum average power dissipation
import math
#Variable declaration
Pl=10 # power delivered to load in watt
eta1=80.0/100 # output transformer efficiency
eta=78.5/100 # efficiency of a class B push pull amplfier under optimum condition
#Calcualtions
Pout=Pl/eta1
Pin=Pout/eta
Pd=Pin-Pout
Pd1=Pd/2.0
#Calculations
print("ac power output of amplifier (W) = %.1f"%Pout)
print("minimum power drain on the power supply for dc (W) = %.1f"%Pin)
print("minimum average power dissipation (W) = %.1f"%Pd)
print("minimum average power dissipation rating required for each transistor (W) = %.1f"%Pd1)
# the percent second harmonic distortion
import math
#Variable declaration
Vcc=50.0 # voltage in volts
Vmin=5.0 # minimum voltage in volts
Pd=40.0 # total power dissipation in watt
#Calculations
Icmax=Pd/(((2*Vcc)/math.pi)-((Vcc-Vmin)/2));
Pin=(2/math.pi)*(Vcc*Icmax);
Pout=((Icmax/2)*(Vcc-Vmin));
eta=(Pout/Pin)*100;
#Result
print("maximum collector current (A) = %.3f"%Icmax)
print("total power input (W) = %.2f"%Pin)
print("ac power output (W) = %.2f"%Pout)
print("conversion efficiency (%%) = %.2f"%eta)
#Answer for AC power output and efficiency is wrong in the book