# Q factor of coil
import math
#Variable declaration
fr= 400.0*10**3 #resonance frequency
C = 400.0*10**-12 #tuned capacitance
R = 10.0 #resistance of coil
n = 40.0 #Cp=nC
#Calculations
Cp=n*(100.0/400.0)*10**-12
L=(1.0/(4*(math.pi**2)*(fr**2)*(C+Cp)))
Q=2*math.pi*fr*(L/R)
#Result
print("Inductance:\nL = %f mH"%(L*1000))
print("Observed Q-factor:")
print("Q = %.2f "%Q)
# Aanswer do not match with the book
# truncation error
import math
#Variable declaration
fs=50*10**3 #sampling rate
delt=2.0 #summation interval
f=50.0 #signal frequency
#Calculations
n=(fs/delt) #value of samples for 2s
maxer1=100.0/(2*n) #max error for synchronous case
maxer2=(100.0/(2*fs*delt*math.sin((2*math.pi*f)/fs)))
#Result
print("max error for synchronous case:")
print("maxer1 = %.3f%% \n"%maxer1)
print("max error for asynchronous case:")
print("maxer2 = %.2f%% "%maxer2)
# find ratio errror and phase angle
import math
#Variable declaration
#assume no iron loss and magnetizing current=1% of 10A, i.e 0.01A
Xs=1.884 #reactance of secondary
Rs=0.5 #resistance of secondary
Xm=2.0 #reactance of meter
Rm=0.4 #reactance of meter
Im=0.01 #magnetizing current
n2=10
n1=1
#Calculations
B=math.atan((Xs+Xm)/(Rs+Rm))
#nominal ratio (n2/n1)=10/1
R=n2+((Im*math.sin(B))/n1) #actual impedance
R1=0.0097 #practical impedance
perer=(R1/R)*100 #percentage error
theta=((Im*math.cos(B))/n2)
#Result
print("percentage error = %.3f%% \n"%perer)
print("phase angle:")
print("theta = %.5f rad"%(math.floor(theta*10**5)/10**5))
# inductor Q factor and resistance
import math
#Variable declaration
Vc=100.0 #voltage across capacitor
Vi=12.0 #input voltage
f=100.0 #frequency of operation
Vl=100.0 #Vc=Vl at resonance
Ir=5.0 #current at resonance
#Calculations
Q=(Vc/Vi) #Q-factor
Xl=(Vl/Ir) #inductive reactance
L=(Xl/(2*math.pi*f)) #inductance
Rl=(Xl/Q) #resistance
#Result
print("Inductance of coil:")
print("L = %.1f mH\n"%(L*1000))
print("Q-factor:")
print("Q = %.2f\n"%Q)
print("Resistance of coil:")
print("Rl = %.1f ohm"%Rl)
# actual Q factor and resistance
import math
# Variable declaration
#when switch is open
C1=0.011*10**-6 #capacitance-1
Q1=10.0 #Q-factor-1
#when switch is closed
C2=0.022*10**-6 #capacitance-2
Q2=100.0 #Q-factor-2
#Calculations
Qac=((Q1*Q2)/(Q1-Q2))*((C1-C2)/C1) #actual Q-factor
Rp=((Q1*Q2)/(Q2-Q1))*(1/(2*math.pi*C2)) #parallel resistance
#Result
print("actual Q-factor:")
print("Qac = %.2f \n"%Qac)
print("parallel resistance:")
print("Rp = %.f M-ohm"%(Rp/10**6))
# find Q factor
import math
#Variable declaration
Cr=0.01*10**-6 #capacitance at resonance
Cu=0.014*10**-6 #capacitance at upper half
Cl=0.008*10**-6 #capacitance at lower half
#Calculations
Qac=((2*Cr)/(Cu-Cl)) #actual Q-factor
#Result
print("actual Q-factor:")
print("Qac = %.2f "%Qac)
# find lag
import math
#Variable declaration
V=10.0 #v=10sin6280t
I=1.0 #current peak
P=3.1 #active power
#Calculations
phi=math.acos((P*2)/V) #phase in radian
w=6280.0 #v=10sin6280t
lag=(phi/w) #lag
#Result
print("lag = %.2f ms"%(lag*10**3))
# find truncation error
import math
#Variable declaration
V=4.0 #peak voltage
I=0.4 #peak current
f=1*10**3 #operating frequency
fs=40*10**3 #sampling rate
delt=2.2 #time interval
#Calculations
phi=((2*math.pi*f)/fs) #phase
Et=(V*I*phi)/(4*math.pi*f*delt*math.sin(phi))
#Result
print("truncation error:")
print("Et = %.1f * 10^-6 "%(Et*10**6))
# find frequency of PF meter
import math
#Variable declaration
ar=1.0 #gain of rectifier
nc=40.0 #turns ratio (1:40)
Vm=4.0 #peak load voltage
PF=0.85 #power factor
#Calculations
f=(1/math.pi)*ar*Vm*nc*PF #frequency
#Result
print("frequency of digital power meter:")
print("f = %.1f Hz"%f)
# calculate ratio error and phase angle
import math
#Variable declaration
Rp=94.0 #primary resistance
Xp=64.3 #primary reactance
Rs=0.85*10**2 #secondary resistance
Im=31*10**-3 #magnetizing current
PF=0.4 #power factor
n=10.0 #PT ratio
Is=1.0 #load current
Vs=110.0 #n=(Vp/Vs)
#Calculations
B=math.acos(PF)
beta = math.floor(math.sin(B)*10)/10
R=Rp+Rs #total resistance
nerr=n+((((Is/n)*((R*PF)+(Xp*beta)))+Im*Xp)/Vs)
theta=((PF*(Xp/n))-(beta*(R/n))-(Im*Rp))/(Vs*n)
#Result
print("ratio error:")
print("nerr = %.3f\n"%nerr)
print("phase angle:")
print("theta = %.3f"%theta)
#Answer for theta do not match with the book
# calculate ratio error and phase angle
import math
#Variable declaration
n=20.0 #(Vs/Is)
Is=5.0 #n=(Vs/Is)
Vs=100.0 #n=(Vs/Is)
N=0.25 #resistance to reactance ratio
Bur=15.0 #burden of CT=15VA (rating)
IL=0.13 #iron loss
Im=1.3 #magnetizing current
#Calculations
V=(Bur/Is) #voltage rating
B=math.atan(N) #cos(B)-> power factor
#B=B*(180/math.pi) #conversion into degree
I=(Bur/Vs) #current rating
I1=(IL/I)
Rac=0.23 #actual value
R=n+((I1*math.cos(B)+Im*math.sin(B))/Is)
theta=((Im*math.cos(B)-I1*math.sin(B))/Vs)
nerr=-(Rac/R)*100 #ratio error
# Result
print("ratio error:")
print("nerr = %.3f%%\n "%nerr)
print("phase angle \n")
print("theta = %.4f° "%theta)