# oscillation frequency 
import math
#Variable declaration
c=450.0         # capacitance of tunned circuit in pico farad
L=29.3          # INDUCTANCE of tunned circuit in micro henry
#Calculations
fo=(1/(2*math.pi*math.sqrt(L*10**-6*c*10**-12)))*10**-6
#Result
print("tunned frequency = %.2f MHz"%fo)
# tunned capacitance range of tunned circuit
import math
#Variable declaration
L=100.0              # INDUCTANCE of tunned circuit in micro henry
fo1=500.0            # tunned frequency in killo hertz
fo2=1500.0           # tunned frequency in killo hertz
#Calculations
C1= (1/(4*math.pi**2*(fo1*10**3)**2*L*10**-6))     # tunned capacitance
C2= (1/(4*math.pi**2*(fo2*10**3)**2*L*10**-6))     # tunned capacitance
#Result
print("tunned capacitance range of tunned circuit in pF is %.1f - %.f"%(C2*10**12,C1*10**12))
# TRANSFORMER WINDING RATIO
import math
#Variable declaration
Vcc=12.0             # collector vltage
Po=88.0              # power output in milli watt
Ploss=8.0            # power losses in milli watt
gm=10.0              # transconductance in milli ampere per volt
#Calculations
Pi= Po+Ploss         # input power in milli watt
Ic= Pi/Vcc           # collector current in milli ampere
Vb= Ic/(gm)          # base VOLTAGE 
TR=Vcc/Vb            # transfomer turn ratio
#Result
print("transformer winding turn-ratio is %.f"%TR)
# oscillation frequency 
import math
#Variable declaration
C1=0.005               # capacitance of tunned circuit in micro farad
C2=0.01                # capacitance of tunned circuit in micro farad
L=100.0                # INDUCTANCE of tunned circuit in micro henry
#Calculations
C=(C1*C2)/(C1+C2)                                      # total capacitance in micro farad
C = math.floor(C*10**4)/10**4
fo=(1/(2*math.pi*math.sqrt(L*10**-6*C*10**-6)))        # tunned frequency in killo hertz
#Result
print C
print("tunned frequency = %.2f kHz"%(fo*10**-3))
# oscillation frequency 
import math
#Variable declaration
C1=500.0             # capacitance of tunned circuit in PICO farad
C2=500.0             # capacitance of tunned circuit in pico farad
L=1.0                #INDUCTANCE of tunned circuit in milli henry
#Calculations
C=(C1*C2)/(C1+C2)                                       # total capacitance in micro farad
fo=(1/(2*math.pi*math.sqrt(L*10**-3*C*10**-12)))*10**-3 #tunned frequency in killo hertz
#Result
print("tunned frequency = %.1f kHz"%fo)
# tunned capacitance and inductance of tunned circuit
import math
#Variable declaration
fo=500.0              # tunned frequency in killo hertz
L3=1.0                # assume inductance 
#Calculations
LC= (1/(4*math.pi**2*(fo*10**-3)**2)) 
C=LC/(L3*10**-3)      # capacitance in pico farad
C1= 2*C 
C2=C1
#Result
print("inductance                              = %.f mH"%L3)
print("tunned capacitance C1 of tunned circuit = %.1f pF"%C1)
print("tunned capacitance C2 of tunned circuit = %.1f pF"%C2)
# tunned capacitance  of tunned circuit
import math
#Variable declaration
fo1=50.0               # tunned frequency in killo hertz
L1=100.0               # inductance in micro henry
L2=100.0               # inductance in micro henry
#Calculations
C= (1/(4*math.pi**2*(fo1*10**-6)**2*(L1+L2)*10**-6))*10**-12
#Result
print("tunned capacitance  tunned circuit = %.5f micro-F"%C)
# oscillation frequency 
import math
#Variable declaration
C=0.2           # capacitance of tunned circuit in MICRO farad
L1=0.5          # INDUCTANCE of tunned circuit in milli henry
L2=1.0          # INDUCTANCE of tunned circuit in milli henry
#Calculaions
fo=(1/(2*math.pi*math.sqrt((L1+L2)*10**-3*C*10**-6)))
#Result
print("tunned frequency = %.1f kHz"%fo)
# oscillation frequency 
import math
#Variable declaration
C=100.0          # capacitance of tunned circuit in pico farad
L1=1.0           # INDUCTANCE of tunned circuit in milli henry
L2=0.1           # INDUCTANCE of tunned circuit in milli henry
M = 0.05         # Mutual INDUCTANCE of tunned circuit in milli henry 
#Calculations
fo=(1/(2*math.pi*math.sqrt((L1+L2+2*M)*10**-3*C*10**-12))) # tunned frequency in killo hertz
#Result
print("tunned frequency = %.f kHz"%(fo/1000))
# feedback ratio
import math
#Variable declaration
Af=40.0            # gain wtih feedback
Vi=2.4             # input voltage
Vif=0.1            # input voltage with feedback
#Calculations
A= Af*(Vi/Vif)     # gain without feedback
Beta= (1-(A/Af))/A # feedback ratio
#Result
print("feedback ratio = %.3f"%Beta)
# resonant frequency
import math
#Variable declaration
Cs=0.08               # capacitance of tunned circuit in pico farad
Ls=0.8                # series INDUCTANCE of tunned circuit in henry
Cp=1.0                # parallel capacitance in pico farad
Rs=5.0                # SERIES RESISTANCE IN KILLO OHMS
#Calculations
fs=round((1/(2*math.pi*math.sqrt(Ls*Cs*10**-12)))*10**-3)               # series tunned frequency in killo hertz
fp=round(((1/(2*math.pi))*math.sqrt((1+Cs/Cp)/(Ls*Cs*10**-12)))*10**-3) # parralel tunned frequency in killo hertz
#Result
print("series tunned frequency   = %.f kHz"%fs)
print("parallel tunned frequency = %.f kHz"%fp)
# quality factor
import math
#Variable declaration
f=450.0               # resonant frequency in killo hertz
L=4.2                 # inductnace in henry
R=600.0               # resistance in ohms
#Calculations
Q= (2*math.pi*f*10**3*L)/R
#Result
print("quality factor is %.f"%Q)
#Answer in the book is slightly different
# resonant frequency
import math
#Variable declaration
Cs=0.01                # capacitance of tunned circuit in pico farad
Ls=0.8                 # series INDUCTANCE of tunned circuit in henry
Cp=20.0                # parallel capacitance in pico farad
Rs=5.0                 # SERIES RESISTANCE IN KILLO OHMS
#Calculations
fs=((1/(2*math.pi*math.sqrt(Ls*Cs*10**-12)))*10**-3)              # series tunned frequency in killo hertz
fp=(((1/(2*math.pi))*math.sqrt((1+Cs/Cp)/(Ls*Cs*10**-12)))*10**-3)# parralel tunned frequency in killo hertz
#Result
print("Series tunned frequency   = %.2f kHz"%(math.floor(fs*100)/100))
print("Parallel tunned frequency = %.2f KHz"%fp)
# resonant frequency,percentage change and quality factor
import math
#Variable declaration
Cs=0.065               # capacitance of tunned circuit in pico farad
Ls=0.33                # series INDUCTANCE of tunned circuit in henry
Cp=1.0                 # parallel capacitance in pico farad
Rs=5.5                 # SERIES RESISTANCE IN KILLO OHMS
#Calculation
fs=round((1/(2*math.pi*math.sqrt(Ls*Cs*10**-12)))*10**-3)               # series tunned frequency in killo hertz
fp=math.ceil(((1/(2*math.pi))*math.sqrt((1+Cs/Cp)/(Ls*Cs*10**-12)))*10**-3) # parralel tunned frequency in killo hertz
Pc= ((fp-fs)/fs)*100   # percentage by which series resonant frequency exceeds the parallel resonant frequency
Qs= ((2*math.floor(math.pi*100)*fs*10**3*Ls/100)/(Rs*10**3))                           # quality factor with series resonant frequency
Qp= ((2*math.floor(math.pi*100)*fp*10**3*Ls/100)/(Rs*10**3))                 # quality factor with parallled resonant frequency
#Result
print("series tunned frequency   = %.f kHz"%fs)
print("parallel tunned frequency = %.f kHz"%fp)
print("percentage by which series resonant frequency exceeds the parallel resonant frequency = %.1f%%"%Pc)
print("quality factor with series resonant frequency is %.2f"%Qs)
print("quality factor with paralled resonant frequency is %.2f"%(math.floor(Qp*100)/100))
# oscillation frequency 
import math
#Variable declaration
C1=120.0               # capacitance of tunned circuit in PICO farad
C2=1500.0              # capacitance of tunned circuit in pico farad
C3=15.0                # capacitance of tunned circuit in pico farad
L=10.0                 # INDUCTANCE of tunned circuit in micro henry
#Calculations
Cx=(C1*C2)/(C1+C2)     # capacitance in pico farad
Ct=(Cx*C3)/(Cx+C3)     # total capacitance in pico farad
fo=(1/(2*math.pi*math.sqrt(L*10**-6*Ct*10**-12)))*10**-6      # tunned frequency in mega hertz
foa= (1/(2*math.pi*math.sqrt(L*10**-6*C3*10**-12)))*10**-6    # actual resonant frequency in mega hertz
#Result
print("tunned frequency          = %.2f MHz"%fo)
print("actual resonant frequency = %.2f MHz"%foa)
# resonant frequency 
import math
#Variable declaration
R=500.0               # resistance in ohms
C1=0.01               # capacitance of tunned circuit in pico farad
C2=10.0               # capacitance of tunned circuit in pico farad
L=0.06                # INDUCTANCE of tunned circuit in  henry
#Calculations
C=(C1*C2)/(C1+C2)     # total capacitance in micro farad
fs=((1/(2*math.pi*math.sqrt(L*C1*10**-12)))*10**-6)  # series tunned frequency in mega hertz
C=(C1*C2)/(C1+C2)                                    # total capacitance in pico farad
fp=(1/(2*math.pi*math.sqrt(L*C*10**-12))*10**-6)     #parralel tunned frequency in mega hertz
#Result
print("series tunned frequency   = %.3f MHz"%fs)
print("parallel tunned frequency = %.4f MHz"%fp)
# oscillation frequency 
import math
#Variable declaration
C=100.0                   # capacitance of tunned circuit in pico farad
L1=50.0                   # INDUCTANCE of tunned circuit in micro henry
L2=50.0                   # INDUCTANCE of tunned circuit in micro henry
#Calculations
fo=(1/(2*math.pi*math.sqrt((L1+L2)*10**-6*C*10**-12)))*10**-6          # tunned frequency in mega hertz
#Result
print("Tunned frequency = %.2f MHz"%fo)
# oscillation frequency 
import math
#Variable declaration
C1=120.0             # capacitance of tunned circuit in PICO farad
C2=1500.0            # capacitance of tunned circuit in pico farad
L=10.0               # INDUCTANCE of tunned circuit in micro henry
#Calculation
C=(C1*C2)/(C1+C2)    # total capacitance in pico farad
fo=(1/(2*math.pi*math.sqrt(L*10**-6*C*10**-12)))*10**-6    # tunned frequency in mega hertz
#Result
print("tunned frequency = %.2f MHz"%fo)
# oscillation frequency 
import math
#Variable declaration
C1=120.0            # capacitance of tunned circuit in PICO farad
C2=1500.0           # capacitance of tunned circuit in pico farad
C3=15.0             # capacitance of tunned circuit in pico farad
L=10.0              # INDUCTANCE of tunned circuit in micro henry
#Calculations
Cx=(C1*C2)/(C1+C2)  # capacitance in pico farad
Ct=(Cx*C3)/(Cx+C3)  # total capacitance in pico farad
fo=(1/(2*math.pi*math.sqrt(L*10**-6*Ct*10**-12)))*10**-6       # tunned frequency in mega hertz
#Result
print("tunned frequency = %.2f MHz"%fo)
# oscillation frequency 
import math
#Variable declaration
C=100.0             # capacitance in pico farad
R=800.0             # resistance in killo ohms
#Calculations
fo=round(1/(2*math.pi*R*10**3*C*10**-12*math.sqrt(6))) # RESONANT FREQUENCY IN HERTZ
#Result
print("Resonant frequency = %.f Hz"%fo)
# oscillation frequency 
import math
#Variable declaration
w=2*10**3                  # in radiand per second
#Calculations
f= round(w/(2*math.pi))    # resonant frequency
X=(((16*10**9*4*w**2*10**3))/((4*w**2*10**3)**2))
#Result
print("resonant frequency         = %.f Hz"%f)
print("oscillations are sustained = %.f"%X)
# Design R-C phase shift oscillator
import math
#Variable declaration
fo=1.0                        # resonant frequency in killo hertz
Av= 29.0                      # voltage gain
Vcc=10.0                      # collector voltage
Ib=0.5                        # maximum base current in micro ampere
Rf2=180.0                     # standard resistance in killo ohms
#Calculations
I1=100*Ib                     # assume current in micro ampere
Vosat= 0.9*Vcc                # saturation voltage assume
V1=Vosat/Av                   # voltage for sustained oscillations
R1=(V1/(I1*10**-6))*10**-3    # RESISTANCE IN KILLO PHMS
Rf1=Av*R1                     # resistance in killo ohms
R3=Rf2 
R=R1 
C=(1/(2*math.pi*R*10**3*fo*10**3*math.sqrt(6)))*10**6 
#Result
print("Resistance  R1 for the R-C Phase shift oscillator  = %.1f k-ohm"%R)
print("Resistance Rf for the R-C Phase shift oscillator   = %.f k-ohm"%R3)
print("Capacitance for the R-C Phase shift oscillator     = %.2f micro-F"%C)
# drain resistance and Design R-C phase shift oscillator
import math
#Variable declaration
Mu=55.0
rd=5.5                # resistane in killo ohms
fo=5.0                # resonant frequency in killo hertz
A= 29.0               # voltage gain
R=30.0                # assume Resistance in killo ohms
#Calculations
Rd= (29*rd)/(Mu-A)    # resistance in killo ohms
RC=((1/(2*math.pi*fo*10**3*math.sqrt(6)))*10**6) 
C=(RC*10**-6/(30*10**3)*10**12)
#Result
print("drain resistance                               = %.2f k-ohm"%Rd)
print("R-C time constant                              = %.f pico-sec"%(math.ceil(RC)))
print("Capacitance for the R-C Phase shift oscillator = %.f pF"%C)
#Answer for capacitance is wrong in the book
# Vf/Vo,frequency of oscillations and minimum gain
import math
#Variable declaration
Beta=1.0/29
#Calculations
VfVo= (Beta+1)
#Result
print("Voltage gain = %f"%VfVo)
print("\nf=1/(2*%pi*R*C*sqrt(6)) frequency of oscillations")
print("\nAs gain is more than one oscillations will be sustained")
# design wein bridge oscillator
import math
#Variable declaration
Vcc=15.0                           # collector voltage
f=10.0                             # frequency of oscillation in killo hertz
I=1.0                              # current in millo ampere
#Calculations
Vo=Vcc-1                           # maximum output voltage
x=Vo/I                             # resistance in killo ohms
R4=x/3                             # resistance in killo ohms
R3= 2*R4                           # resistance in killo ohms
R4_s = 4.7                         # Standard value
R3_s = 10                          # Standard value 
A= (1+(R3_s/R4_s))                   # amplifier gain
R=R4_s                               # resistance in killo ohms
C=(1/(2*math.pi*f*10**3*R*10**3))*10**9
#Result
print("Amlifier gain   = %.2f"%(math.floor(A*100)/100))
print("resistance R4   = %.1f k-ohm (use 4.7 k-ohm standard value)"%R)
print("resistance R3   = %.1f k-ohm (use 10 k-ohm standard value)"%(math.ceil(R3*10)/10))
print("Capacitance     = %.2f nF"%(math.floor(C*100)/100))
#print("this is name as example 7.27 in the book" )
# sustained oscillations and output frequency
import math
#Variable declaration
R4=5.1                     # resistance in killo ohms
R3=12.0                    # resistance in killo ohms
C=1.0                      # capacitance in nano farad
#Calculations
A= (1+(R3/R4))        # amplifier gain
R=R4                       # resistance in killo ohms
fo= (1/(2*math.pi*C*10**-9*R*10**3))*10**-3
#Result
print("Amlifier gain is %.2f. It is greater than 1 so circuit will oscillate."%A)
print("Oscillation frequency = %.1f kHz"%fo)
# design wein bridge oscillator
import math
#Variable declaration
Vcc=10.0             # collector voltage
f=10.0               # frequency of oscillation in killo hertz
I=500.0              # current in micro ampere
#Calculations
Vo=Vcc-1             # maximum output voltage
x=(Vo/I)*10**3       # resistance in killo ohms
R4=x/3               # resistance in killo ohms
Rf= 2*R4             # resistance in killo ohms
R4_s = 5.6           # standard value
R=R4_s               # resistance in killo ohms
C=(1/(2*math.pi*f*10**3*R*10**3))*10**12
#Resulr
print("Resistance R  = R1 = %.f k-ohm(uswe 5.6k as standard value)"%R)
print("resistance Rf = %.f k-ohm"%Rf)
print("Capacitance   = %.f nF(use 2700 nF as standard value)"%C)
print("Theoretical example")
print("Theoretical example")
# Design R-C phase shift oscillator
import math
#Variable declaration
Vce=5.0                  # in volts
RE=1.0                   # emitter reistsance in killo ohms
Vbe=0.7                  # in volts
Ie=1.0                   # emitter current in mA
Re=1.0                   # EMITTER RESISTANCE IN KILLO OHMS
f=100.0                  # oscillaor frequency in killo hertz
hfe=100.0
hie=1.0                  # in killo ohms
Vc=5.0                   # in volts
Ic=1.0                   # current in mili ampere
Vcc=20.0                 # in volts
R=10.0                   # resistane in killo ohms
#Calculations
Rc=(Vcc-Vce-Ie*Re)/(Ic)  # collector resistance in killo ohms is
k= Rc/R
C= ((1/(2*math.pi*R*10**3*f*10**3*math.sqrt(6+(4*1.4)))))*10**12
R3= R-hie                # resistance in kiilo ohms
Vb= (Vbe+Ie*Re)          # voltage at base
R2=R 
I2=Vb/R2                 # in mA
V2=(Vcc-R2*I2)           # voltage drop across R2
IR1= (I2+(1.0/100))      # CURRENT ACROOS R1
R1= V2/(IR1) 
#Result
print("Emitter resistance   = %.f  k-ohm"%Re)
print("collector resistance = %.f k-ohm"%Rc)
print("resistance R         = %.f k-ohm"%R)
print("Capacitance          = %.1f pF"%C)
print("resistance(R3)       = %.f k-ohm"%R3)
print("resistance(R2)       = %.f k-ohm"%R2)
print("resistance(R1)       = %.f k-ohm"%R1)
#Answer for Resistance (R1) is wrong in the book
# Design R-C phase shift oscillator
import math
#Variable declaration
rd=40.0                  # resistane in killo ohms
fo=1.0                   # resonant frequency in killo hertz
gm= 5000.0               # in killo mh
R=10.0                   # assume Resistance in killo ohms
Av=29.0                  # VOLTAGE GAIN
Vdd=12.0                 # drain voltage
#Calculations
C=((1/(2*math.pi*fo*10**3*R*10**3*math.sqrt(6)))*10**9)# C in nano farad
Rl= (Av/gm*10**-6)*10**9 # load resistance in killo ohms
Rl = math.ceil(Rl)
Rd= ((Rl*rd)/(rd-Rl))    # drain resistance in killo ohms
#Result
print("Drain Resistance                               = %.2f k-ohm"%Rd)
print("Capacitance for the R-C Phase shift oscillator = %.1f nF"%C) 
# design wein bridge oscillator
import math
#Variable declaration
R=100.0                         # ASSUME RESSITANCE IN KILO OHMS
fo1=10.0                        # tunned frequency in killo hertz
fo2=100.0                       # tunned frequency in  hertz
#Calculations
C1= (1/(2*math.pi*R*10**3*fo1*10**3))*10**9  # tunned capacitance
C2= (1/(2*math.pi*R*10**3*fo2))*10**9        # tunned capacitance
#Result
print("Tunned capacitance C1 range of tunned circuit = %.3f nF"%C1)
print("Tunned capacitance C2 range of tunned circuit = %.1f nF"%C2)
#Answer slightly different than book
# resonant frequency and quality factor
import math
#Variable declaration
Cs=0.06                   # capacitance of tunned circuit in pico farad
Ls=0.5                    # series INDUCTANCE of tunned circuit in henry
Cp=1.0                    # parallel capacitance in pico farad
Rs=5.0                    # SERIES RESISTANCE IN KILLO OHMS
#Calculations
fs=((1/(2*math.pi*math.sqrt(Ls*Cs*10**-12)))*10**-3)               # series tunned frequency in killo hertz
fp=(((1/(2*math.pi))*math.sqrt((1+Cs/Cp)/(Ls*Cs*10**-12)))*10**-3) # parralel tunned frequency in killo hertz
Pc= ((fp-fs)/fs)*100      # percentage by which series resonant frequency exceeds the parallel resonant frequency
Qs= round((2*math.pi*fs*10**3*Ls)/(Rs*10**3))                           # quality factor with series resonant frequency
Qp= round((2*math.pi*fp*10**3*Ls)/(Rs*10**3))                           # quality factor with parallled resonant frequency
#Result
print("Series tunned frequency   = %.1f kHz"%fs)
print("Quality factor with series  resonant frequency is %.f"%Qs)
print("\nParallel tunned frequency = %.f kHz"%fp)
print("Quality factor with paralled resonant frequency is %.f"%Qp)