from __future__ import division
from math import pi
fH=1 #kHz
Ap=2 #Pass band gain
print "Various design parameters are :-"
C=0.05 #micro F#Chosen for the design
print "Capacitance is %0.2f micro F " %C
R=1/(2*pi*fH*1000*C*10**-6)/1000 #kohm
print "Resistance R = %0.1f kohm " %R
#Ap=1+Rf/Ri
RfBYRi=Ap-1 #Rf=Ri here
#R=Rf||Ri
Ri=2*R #kohm
Rf=Ri #kohm
print "Resistance Ri = %0.1f kohm " %Ri
print "Resistance Rf = %0.1f kohm " %Rf
from __future__ import division
f0=800 #Hz
#For Butterworth filter : f0=fH=f_3dB
fH=f0 #Hz
f_3dB=f0 #Hz
BW=fH #Hz
print "Bandwidth = %0.2f Hz " %BW
from __future__ import division
from math import pi
fH=2 #kHz(Cutoff frequency)
Ap=1 #Pass band gain
print "Various design parameters are :-"
C=0.05 #micro F#Chosen for the design between 0.01 & 1 micro F
print "Capacitance = %0.2f micro F " %C
R=1/(2*pi*fH*1000*C*10**-6)/1000 #kohm
print "Resistance R = %0.1f kohm " %R
Rdash=R #/kohm(To eliminate the effect of offset)
print "Resistance R* = %0.1f kohm " %Rdash
from __future__ import division
from math import pi
f0=1 #kHz(Cutoff frequency)
f0dash=1.5 #kHz(Cutoff frequency)
print "Various design parameters are :-"
#For Butterworth filter
fH=f0 #kHz
fHdash=f0dash #kHz
K=f0/f0dash #ratio
R=3.2 #kohm
Rdash=K*R #kohm
print "Resistance Rdash = %0.1f kohm " %Rdash
C=0.05 #micro F#Chosen for the design
print "Capacitance = %0.2f micro F " %C
fHdash=1/(2*pi*Rdash*1000*C*10**-6)/1000 #kHz
print "Cutoff frequency is %0.1f kHz " %fHdash
from __future__ import division
from math import pi
fL=400 #Hz
Ap=2 #Pass band gain
print "Various design parameters are :-"
C=0.05 #micro F#Chosen for the design between 0.01 & 1 micro F
print "Capacitance is %0.2f micro F " %C
R=1/(2*pi*fL*C*10**-6)/1000 #kohm
print "Resistance R = %0.2f kohm " %R
#Ap=1+Rf/Ri
RfBYRi=Ap-1 #Rf=Ri here
#R=Rf||Ri
Ri=2*R #kohm
Rf=Ri #kohm
print "Resistance Ri = %0.1f kohm " %Ri
print "Resistance Rf = %0.1f kohm " %Rf
# Answer in the textbook are inaccurate.
from __future__ import division
from math import pi
fL=400 #Hz
fLdash=800 #Hz
K=fL/fLdash #ratio
print "Various parameters for retuning are :-"
R=8.2 #kohm
Rdash=K*R #kohm
print "Resistance Rdash = %0.2f kohm " %Rdash
Rf=2*Rdash #kohm
Ri=2*Rdash #kohm
print "Resistance Ri = %0.1f kohm " %Ri
print "Resistance Rf = %0.1f kohm " %Rf
from __future__ import division
from math import pi, sqrt
f0=3 #kHz(Critical frequency)
Ap=4 #Pass band gain
#For Butterworth filter using sallen key
alfa=1.414; klp=1 #constant
fH=f0 #kHz
f_3dB=f0 #kHz
print "Various design parameters are :-"
C1=0.01 #micro F#Chosen for the design
print "Capacitance C1 = %0.2f micro F " %C1
C2=alfa**2*C1/4 #micro F
print "Capacitance C2 = %0.3f micro F " %C2
C2=0.004 # micro F
R=1/(2*pi*fH*10**3*sqrt(C1*10**-6*C2*10**-6))/1000 #kohm
print "Resistance R = %0.1f kohm " %R
R=8.2 #kohm
#For offset minimization
Rdash=2*R #kohm
print "Resistance R* = %0.2f kohm " %Rdash
RfBYRi=Ap-1 #Rf=Ri here
#Ri=10 kohm chosen for design
Ri=10 #kohm
Rf=RfBYRi*Ri #kohm
print "Resistance Ri = %0.1f kohm " %Ri
print "Resistance Rf = %0.1f kohm " %Rf
from __future__ import division
from math import pi, sqrt
f0=2 #kHz(Critical frequency)
Ap=5 #dc gain
#For Butterworth filter using sallen key
alfa=1.414; klp=1 #constant
fH=f0 #kHz
f_3dB=f0 #kHz
Ap1=3-alfa #gain
RfBYRi=Ap1-1 #ratio
print "Various design parameters are :-"
C=0.05 #micro F#Chosen for the design
print "Capacitance C = %0.2f micro F " %C
R=klp/(2*pi*fH*10**3*C*10**-6)/1000 #kohm
print "Resistance R = %0.1f kohm " %R
#For offset minimization
#2*R=Rf||Ri=Rf/(RfBYRi+1)
Rf=2*R*(RfBYRi+1) #kohm
print "Resistance Rf = %0.1f kohm " %Rf
Ri=Rf/RfBYRi #kohm
print "Resistance Ri = %0.1f kohm " %Ri
#Ap=4 #dc gain in this case
Ap=4 #dc gain
Ap2=Ap/Ap1 #remainimg gain after 2nd order butterworth filter
RfdashBYRidash=Ap2-1 #ratio
#Ridash=10 #kohm chosen for design
Ridash=10 #kohm
print "Resistance Ridash = %0.2f kohm " %Ridash
Rfdash=RfdashBYRidash*Ridash #kohm
print "Resistance Rfdash = %0.f kohm " %Rfdash
from __future__ import division
from math import pi, sqrt
f0=2 #kHz(Critical frequency)
fH=f0 #kHz
f_3dB=f0 #kHz
#For Butterworth filter using sallen key
alfa=1.414; klp=1 #constant
Ap=3-alfa # band pass gain
RfBYRi=Ap-1 #ratio
print "Various design parameters are :-"
C=0.05 #micro F#Chosen for the design
print "Capacitance C = %0.2f micro F " %C
R=1/(2*pi*fH*10**3*C*10**-6)/1000 #kohm
print "Resistance R = %0.1f kohm " %R
#For offset minimization
#2*R=Rf||Ri=Rf/(RfBYRi+1)
Rf=2*R*(RfBYRi+1) #kohm
print "Resistance Rf = %0.1f kohm " %Rf
Ri=Rf/RfBYRi #kohm
print "Resistance Ri = %0.1f kohm " %Ri
#Answer in the book is not accurate. Some calculation mistake is there while working for offset minimization.
from __future__ import division
from math import pi, sqrt
f0=2 #kHz(Critical frequency)
fH=f0 #kHz
f_3dB=f0 #kHz
#For Bessel filter of 2nd order
alfa=1.73; klp=0.785 #constant
Ap=3-alfa # band pass gain
RfBYRi=Ap-1 #ratio
print "Various design parameters are :-"
C=0.05 #micro F#Chosen for the design
print "Capacitance C = %0.2f micro F " %C
R=klp/(2*pi*fH*10**3*C*10**-6)/1000 #kohm
print "Resistance R = %0.2f kohm " %R
#For offset minimization
#2*R=Rf||Ri=Rf/(RfBYRi+1)
Rf=2*R*(RfBYRi+1) #kohm
print "Resistance Rf = %0.2f kohm " %Rf
Ri=Rf/RfBYRi #kohm
print "Resistance Ri = %0.2f kohm " %Ri
# Answer in the textbook are inaccurate.
from __future__ import division
from math import pi, sqrt
f0=.12 #kHz(Cutoff frequency)
fH=f0 #kHz
#For Butterworth filter of 2nd order
alfa=1.414; klp=1 #constant
Ap=3-alfa # band pass gain
RfBYRi=Ap-1 #ratio
print "Various design parameters are :-"
C=0.33 #micro F#Chosen for the design choosing between 0.01 & 1 micro F
print "Capacitance C = %0.2f micro F " %C
R=klp/(2*pi*fH*10**3*C*10**-6)/1000 #kohm
print "Resistance R = %0.f kohm " %R
#For offset minimization
#2*R=Rf||Ri=Rf/(RfBYRi+1)
Rf=2*R*(RfBYRi+1) #kohm
print "Resistance Rf = %0.2f kohm " %Rf
Ri=Rf/RfBYRi #kohm
print "Resistance Ri = %0.f kohm " %Ri
# Answer in the textbook are inaccurate.
from __future__ import division
from math import pi, sqrt, floor
fL=20 #Hz(Cutoff frequency)
#For Butterworth filter of 2nd order
alfa=1.414; klp=1 #constant
Ap=3-alfa # band pass gain
RfBYRi=Ap-1 #ratio
print "Various design parameters are :-"
C=0.22 #micro F#Chosen for the design choosing between 0.01 & 1 micro F
print "Capacitance C = %0.2f micro F " %C
R=klp/(2*pi*fL*C*10**-6)/1000 #kohm
print "Resistance R = %0.2f kohm " %R
#For offset minimization
#R=Rf||Ri=Rf/(RfBYRi+1)
Rf=R*(RfBYRi+1) #kohm
print "Resistance Rf = %0.f kohm " %Rf
Ri=Rf/RfBYRi #kohm
Ri=floor(Ri) #kohm
print "Resistance Ri = %0.f kohm " %Ri
from __future__ import division
from math import pi, sqrt
fH=2 #kHz(Cutoff frequency)
Ap=4 #Pass band gain
print "Butterworth filter = cascading of 1st and 2nd order high pass filter."
#Butterworth polynomial is (s+1)*(s**2+s+1)
alfa=1 #for sallen key
Ap2=3-alfa #gain for 2nd order filter
Ap1=Ap/Ap2 #gain for 1st order filter
#Design parameters for 1st order filter :
print "Various design parameters for 1st order filter are :-"
C=0.01 #micro F#Chosen for the design
print "Capacitance C = %0.2f micro F " %C
R=1/(2*pi*fH*10**3*C*10**-6)/1000 #kohm
print "Resistance R = %0.2f kohm " %R
R=8.2 #kohm
#Ap1=Rf/Ri+1 with Ap1=2 we have Rf=Ri
Rf=2*R #kohm
Ri=2*R #kohm
print "Resistance Rf = %0.2f kohm & Ri = %0.2f kohm " %(Rf,Ri)
#Design parameters for 2nd order filter :
kLp=1/alfa #unitless
#Ap2=Rfdash/Ridash+1 with Ap2=2 we have Rfdash=Ridash
print "Various design parameters for 2nd order filter are :-"
C=0.033 #micro F#Chosen for the design
print "Capacitance C = %0.3f micro F " %C
R=kLp/(2*pi*fH*10**3*C*10**-6)/1000 #kohm
print "Resistance R = %0.2f kohm " %R
Rf=2*R #kohm
Ri=2*R #kohm
print "Resistance Rfdash =%0.1f kohm & Ridash = %0.1f kohm " %(Rf,Ri)
from __future__ import division
from math import pi, sqrt
fL=200 #Hz
fH=1 #kHz
Ap=4 #Pass band gain
fc=sqrt(fH*1000*fL) #Hz(Cutoff frequency)
BW=fH*1000-fL #Hz
Q=fc/BW #Quality Factor
print "Quality factor is %0.2f " %Q
print "As Q<12, it is a wide band filter."
Ap1=2 #Pass band gain for high pass section
print "Various design parameters for high pass section are :-"
C=0.033 #micro F#Chosen for the design
print "Capacitance C = %0.3f micro F " %C
R=1/(2*pi*fL*C*10**-6)/1000 #kohm
print "Resistance R = %0.1f kohm " %R
#Ap1=Rf/Ri+1 with Ap1=2 we have Rf=Ri
Rf=2*R #kohm
Ri=2*R #kohm
print "Resistance Rf = %0.f kohm & Ri = %0.f kohm " %(Rf,Ri)
Ap2=2 #Pass band gain for low pass section
print "Various design parameters for low pass section are :-"
C=0.033 #micro F#Chosen for the design
print "Capacitance C = %0.3f micro F " %C
K=fL/(fH*1000) #unitless
Rdash=K*R #kohm
print "Resistance Rdash = %0.1f kohm " %Rdash
#Ap1=Rf/Ri+1 with Ap1=2 we have Rf=Ri
Rf=2*Rdash #kohm
Ri=2*Rdash #kohm
print "Resistance Rf = %0.f kohm & Ri = %0.f kohm " %(Rf,Ri)
from __future__ import division
from math import pi, sqrt
print "Part(a)"
fc=1.2 #kHz
Q=4 #Quality Factor
Ap=10 #Pass band gain
print "Here 2*Q**2=32>AP=10, hence it can be designed using single op-amp."
print "Various design parameters are :-"
C=0.05 #micro F#Chosen for the design
print "Capacitance C = %0.2f micro F " %C
#fc/Q=1/(pi*R2*C)
R2=Q/(fc*1000)/pi/(C*10**-6)/1000 #kohm
print "Resistance R2 = %0.1f kohm " %R2
R1=R2/(2*Ap) #kohm
print "Resistance R1 = %0.2f kohm " %R1
R3=R1*1000/(4*pi**2*R1*1000*R2*1000*(C*10**-6)**2*(fc*1000)**2-1) #ohm
print "Resistance R3 = %0.2f ohm " %R3
print "Part(b)"
R3=460 #ohm
fc_new=1.5 #kHz
fc_old=1.2 #kHz
R3new=R3*(fc_old/fc_new)**2 #ohm
print "Resistance R3 should be changed from %0.2f ohm to %0.2f ohm" %(R3, R3new)
#Answer for R3 is wrong in the book
from __future__ import division
from math import pi, sqrt
fL=3 #kHz
fH=3.6 #kHz
Ap=-6 #Pass band gain
fc=sqrt(fH*fL)*1000 #Hz
BW=(fH-fL)*1000 #Hz
Q=fc/BW #Quality factor
print "Quality factor is %0.2f" %Q
print "Here 1<=Q<=12 criteria fulfills, hence it can be designed using single op-amp."
print "Various design parameters are :-"
C=0.01 #micro F#Chosen for the design
print "Capacitance C = %0.2f micro F " %C
#fc/Q=1/(pi*R2*C)
R2=1/pi/(BW)/(C*10**-6)/1000 #kohm
print "Resistance R2 = %0.f kohm " %R2
R1=-R2/(2*Ap) #kohm
print "Resistance R1 = %0.2f kohm " %R1
R3=R1*1000/(4*pi**2*R1*1000*R2*1000*(C*10**-6)**2*(fc)**2-1) #ohm
print "Resistance R3 = %0.f ohm " %R3
print "Design Verification : "
print "(i) Is 2*Q**2>|Ap| ?\n", 2*Q**2>abs(Ap)
print "For op-amp 741, GBW=1 MHz"
GBW=1 #MHz
print "Is GBW*10**6>20*Q**2*fc ?\n",GBW*10**6>20*Q**2*fc
print "2nd criteria failed. The op-amp should have higher GBW product. Use LF411"
from __future__ import division
from math import pi, sqrt
Ap=-10 #Pass band gain
Q=22 #Quality factor
fc=50 #Hz
R=60 #dB/decade(Roll off rate)
print """Roll off rate of single op-amp=20 dB/decade.
No. of stages will be 3.
Desired design can be obtained by cascading three stages."""
n=3 #no. of op-amps(as single op-amp has 20 dB/decade)
fc1=fc #Hz
fc2=fc #Hz
fc3=fc #Hz
Q1=Q*sqrt(2**(1/n)-1) #Quality factor of each stage
Q2=Q1 #Quality factor
Q3=Q1 #Quality factor
Ap1=-(-Ap)**(1/n) #Band pass gain of each stage
Ap2=Ap1 #Band pass gain
Ap3=Ap1 #Band pass gain
#Design of a single op-amp
C=0.1 #micro F#Chosen for the design
print "Various design parameters for a single stages are :"
print "Capacitance C = %0.2f micro F " %C
R2=Q1/pi/(fc)/(C*10**-6)/1000 #kohm
print "Resistance R2 = %0.f kohm " %R2
R1=-R2/(2*Ap1) #kohm
print "Resistance R1 = %.f kohm " %R1
R3=R1/(4*pi**2*R1*1000*R2*1000*(C*10**-6)**2*(fc)**2-1) #kohm
print "Resistance R3 = %0.1f ohm " %R3
#Answer for R2 is wrong in the book.
from __future__ import division
from math import pi, sqrt
fNO=50 #Hz
Q=20 #Quality Factor
print "Various design parameters are :-"
C=1 #micro F#Chosen for the design
print "Capacitance C = %0.2f micro F " %C
R=1/(2*pi*fNO)/(C*10**-6)/1000 #kohm
print "Resistance R = %0.2f kohm " %R
#Q=(RA+RB)/4/RA
RA=1 #kohm(chosen for the design)
RB=Q*4*RA-RA #kohm
print "Resistance RA = %0.f kohm " %RA
print "Resistance RB = %0.f kohm " %RB