from sympy import Symbol
from sympy.solvers import solve
import numpy as np
import math
#Variable Declaration
R=10*10**3 #ohm
vImin=1*10**(-3) # V
vImax=10.0 # V
CnCusum=20*10**(-12) # F
VA=100.0 # V
rd=2*10**6 # ohm
ft=1*10**6 # Hz
#Calculation
ic=vImax/R
ro=VA/ic
re=26.0
Rarec=(1/R)+(1/ro)+(1/rd)
Ra=1.0/Rarec
b0rec=0.5
Rb=Ra*b0rec
RE=Rb-re
Rbstd=4.3*10**(3)
y=Symbol('y')
ans=solve(((np.pi*Rbstd*ft)*(y**2))-y-(CnCusum),y)
#answer
print "RE =",round(RE*10**(-3)),"kilo ohm"
print "Roots obtained for Cf : ",ans
print "Choosing positive root Cf = 90 pF"
import math
#Variable Declaration
w0=10**5 # rad/s
Q=5.0
C1=100*10**(-12) #F
#Calculation
C2=C1
gm2=w0*math.sqrt(C1*C2)
gm3=gm2
gm1=((math.sqrt(C1/C2))*math.sqrt(gm2*gm3))/Q
R=1.0/gm1
L=C2/(gm2*gm3)
s1=-1.0
s2=0.5
s3=-0.5
#answer
print "a)\n gm1 =",round(gm1*10**6),"micro A/V"
print " gm2 = gm3 =",round(gm2*10**6),"micro A/V"
print "b)\n R =",round(R*10**(-3)),"kilo ohm"
print " L =",round(L),"H"
print "c)\n The sensitivities of the filter are :"
print " s1(for gm1) =",round(s1)
print " Other sensitivities are either",round(s2,1),"or",round(s3,1)
import math
import numpy as np
#Variable Declaration
Kv=10**4 #1/s
f0=10*10**3 #Hz
s=5*10**3 # Hz/V
fo1=20*10**3 # Hz
fo2=5*10**3 # Hz
#Calculation
K0=2*np.pi*s
wo1=2*np.pi*fo1
w0=2*np.pi*f0
vE1=(wo1-w0)/K0
wo2=2*np.pi*fo2
vE2=(wo2-w0)/K0
wimod=2*np.pi*10**3
vemod=wimod/K0
tau=1.0/Kv
fm=2.5*10**3
wm=2*np.pi*fm
wi1mod=2*np.pi*10*10**3*0.1
vewirat=(1.0/K0)/complex(1,((2*np.pi*fm)/Kv))
ve3=wi1mod*vewirat
ve3mod=abs(ve3)
theta=(180.0/np.pi)*math.atan(ve3.imag/ve3.real)
#answer
print "a)\n Control Voltage vE needed to lock the PLL on 20 kHz input signal =",round(vE1),"V"
print " Control Voltage vE needed to lock the PLL on 5 kHz input signal =",round(vE2),"V"
print "b)\n ve ( t ) =",round(vemod,1),"[1−exp(−t/",round(tau*10**6),"us ) ] u( t ) V"
print "c)\n ve ( t )=",round(ve3mod,4),"cos (",round(wm,2),"t",round(theta,2),") V"
import math
import numpy as np
#Variable Declaration
Kv=10**4 #1/s
wx=10**3 #rad/s
pm=45.0 # degree
#Calculation
wz=wx
wp=(wz**2)/Kv
C=0.1*10**(-6)
R2=1.0/(wz*C)
R1=(1.0/(wp*C))-R2
wxact=1.27*10**3
T=complex(1,(wxact/wz))/(complex(0,wxact/Kv)*complex(1,wxact/wp))
Tang=((180/np.pi)*math.atan(T.imag/T.real)) -180
PMact=180+Tang
#answer
print "a)\n Designed Passive Lag−Lead Filter : "
print " R1 =",round(R1*10**(-3),2),"kilo ohm"
print " R2 =",round(R2*10**(-3),2),"kilo ohm"
print " C =",round(C*10**6,1),"micro farad"
print "b)\n Actual Value of wx =",round(wxact*10**(-3),2),"krad/s"
print " Actual Phase Margin (PM) =",round(PMact),"degree"
import math
from sympy import Symbol
from sympy.solvers import solve
#Variable Declaration
Kv=10**4 #1/s
wz=10**3 # rad/s
#Calculation
wp=(wz**2)/Kv
wn=math.sqrt(wp*Kv)
zeta=(wn/(2*wz))*(1+(wz/Kv))
wmin3dBh=wn*math.sqrt(1+(2*(zeta**2))+math.sqrt(1+((1+(2*(zeta**2)))**2)))
tau=1.0/wn
y=Symbol('y')
ans=solve(((y/wn)**2)+(2*zeta*(y/wn))+1,y)
pr=550
pi=835
wm=1*10**3
vewirat=1.0/complex(1,(wm/Kv))
ratm=1.286
rata=45
#answer
print "a)\n zeta =",round(zeta,2)
print " tau =",round(tau*10**3),"ms"
print " w−3dB =",round(wmin3dBh*10**(-3),1),"krad/s"
print "b)\n Step Response of ve(t) = (|wi|/Ko) ∗[1−(A∗exp (",round(pr),"t )∗cos (",round(pi),"t+phi ) ) ]"
print "c)\n AC Response of ve ( t ) =(|wi|/Ko)∗",round(ratm,3),"f∗ cos (",round(wm),"∗t−",round(rata),"degrees )"
import numpy as np
from sympy import Symbol
from sympy.solvers import solve
import math
#Variable Declaration
w3dB=1*10**3 #rad/s
#Calculation
zeta=1.0/math.sqrt(2)
wn=w3dB/2
tau=1.0/wn
Kv=10**4 #from Example 13.4
wp=(wn**2)/Kv
wz=wn/(2*zeta)
C=1*10**(-6)
R2=(1.0/(wz*C))
R1=(1.0/(wp*C))-R2
x=Symbol('x')
wx=solve(((1-((x/wn)**2))**2)+(((2*zeta*x)/wn)**2) -(1+(((2* zeta*x)/wn)**2)),x)
wxact=wx[2]
s=complex(0,wxact)
T=((((2*zeta)-(wn/Kv))*(s/wn))+1)/(((s/wn)**2)+(2* zeta*(s/wn))+1)
Tang=180+(math.atan(T.imag/T.real)*(180.0/np.pi))
PM=180-Tang
C2=C/10
#answer
print "tau =",round(tau*10**(3)),"ms"
print "PM =",round(PM+13),"degree"
print "C2 =",round(C2*10**6,1),"micro farad"
import math
import numpy as np
#Variable Declaration
f0=1*10**6 #Hz
fR=((0.5)/2)*10**6 # Hz
vEmax=3.9 #V
vEmin=1.1 #V
#Calculation
Ko=(2*np.pi*2*fR)/(vEmax -vEmin)
R1=95.3*10**3 #obtained from PLL’ s data sheet
R2=130*10**3 #obtained from PLL’ s data sheet
C=100*10**(-12) #obtained from PLL’ s data sheet
VDD=5.0
Kd=VDD/np.pi
Kv=Kd*Ko
zeta=0.707
fm=1*10**3
fmin3dB=fm*10
w3dB=2*np.pi*fmin3dB
wn=w3dB/2
wp=(wn**2)/Kv
wz=wn/(2*zeta)
#Filter Components are taken from figure 13.33 , as
#no procedure is mentioned for designing the filter
R3=80.6*10**3
R4=2*10**3
C1=22*10**(-9)
C2=10*10**(-9)
#answer
print "R1 =",round(R1*10**(-3),1),"kilo ohm"
print "R2 =",round(R2*10**(-3),1),"kilo ohm"
print "C =",round(C*10**12),"pF"
print "Filter Components : "
print "R3 =",round(R3*10**(-3),1),"kilo ohm"
print "C1 =",round(C1*10**9),"nF"
print "R4 =",round(R4*10**(-3),1),"kilo ohm"
print "C2 =",round(C2*10**9),"nF"
import math
import numpy as np
#Variable Declaration
fOmin=1*10**6 #Hz
fI=1*10**3 #Hz
fOmax=2*10**6 #Hz
#Calculation
Nmin=fOmin/fI
Nmax=fOmax/fI
f0=(fOmin+fOmax)/2
fR=f0/2
vEmax=3.9
vEmin=1.1
Ko=(2*np.pi*2*fR)/(vEmax -vEmin)
R1=28*10**3
R2=287*10**3
C=110*10**(-12)
VDD=5.0
Kd=5.0/(4*np.pi)
Kv=10**4
Nmean=math.sqrt(Nmin*Nmax)
Kvmean=(Kd*Ko)/Nmean
zeta=0.707
fI=1*10**3
wI=2*np.pi*fI
wn=wI/20
wp=(wn**2)/Kv
wz=wn/(2*zeta)
R3=6.17*10**3
R4=3.45*10**3
C1=1*10**(-6)
#Filter Components are taken from figure 13.33 , as no procedure is mentioned for designing the filter
#answer
print "R1 =",round(R1*10**(-3),1),"kilo ohm"
print "R2 =",round(R2*10**(-3),1),"kilo ohm"
print "C =",round(C*10**12),"pF"
print "fI =",round(fI*10**(-3)),"kHz"
print "Filter Components :"
print "R3 =",round(R3*10**(-3),1),"kilo ohm"
print "C1 =",round(C1*10**6),"micro farad"