Ch-6 : Frequency response, bode plots and resonance

Pg: 255 Ex: 6.1

In [1]:
from math import pi, cos, sin, atan, sqrt
# given V_in(t)=2*cos(2000*pi*t+A), A=40*pi/180
w=2000*pi#      #omega
f=w/(2*pi)#      #frequency
A=40*pi/180#      #40 degrees = %0.2f radians
#equation of straight line of H_magnitude vs f is x+1000*y-4000=0
H_max=(4000-f)/1000#      #magnitude of H(traansfer function)
#equation of straight line of H_phase angle vs f is 6000*y=pi*x (phase angle = %0.2f radians)
H_phi=pi*f/6000#      #phase angle of H
H=H_max*complex(cos(H_phi),sin(H_phi))
V_in=2*complex(cos(A),sin(A))#      #input voltage phasor
V_out=H*V_in#      #output voltage phasor
V_out_R=(V_out.real)#      #real part
V_out_I=(V_out.imag)#      #imaginary part
V_out_max=sqrt((V_out_R**2)+(V_out_I**2))#      #peak value
V_out_phi=atan(V_out_I/V_out_R)
print 'peak value of Vout = %0.2f volts'%V_out_max
print 'phase angle of Vout = %0.2f degrees'%(V_out_phi*180/pi)
print 'with frequency equal to = %0.2f'%f
peak value of Vout = 6.00 volts
phase angle of Vout = 70.00 degrees
with frequency equal to = 1000.00

Pg: 257 Ex: 6.2

In [2]:
from __future__ import division
from math import pi, cos, sin, atan, sqrt

#given V_in(t)=3+2*cos(2000*pi*t)+cos(4000*pi*t-A), A=70*pi/180
#the three parts of V_in(t) are V_in_1=3, V_in_2=2*cos(2000*pi*t),V_in_3=cos(4000*pi*t-A)

#first component V_1
V_in_1=3
f_1=0#      #as omega is zero
#equation of straight line of H_magnitude vs f is x+1000*y-4000=0
H_1_max=(4000-f_1)/1000#      #magnitude of H(traansfer function)
#equation of straight line of H_phase angle vs f is 6000*y=pi*x (phase angle = %0.2f radians)
H_1_phi=pi*f_1/6000#      #phase angle of H
H_1=H_1_max*complex(cos(H_1_phi),sin(H_1_phi))
V_out_1=H_1*V_in_1
V_out_1_R=(V_out_1).real#      #real part
V_out_1_I=(V_out_1).imag#      #imaginary part
V_out_1_max=sqrt((V_out_1_R**2)+(V_out_1_I**2))#      #peak value
V_out_1_phi=atan(V_out_1_I/V_out_1_R)#      #phase angle

#second component V_in_2
V_in_2=2*complex(cos(0),sin(0))#      #V_in_2 phasor
w=2000*pi#      #omega
f_2=w/(2*pi)#      #frequency
#equation of straight line of H_magnitude vs f is x+1000*y-4000=0
H_2_max=(4000-f_2)/1000#      #magnitude of H(traansfer function)
#equation of straight line of H_phase angle vs f is 6000*y=pi*x (phase angle = %0.2f radians)
H_2_phi=pi*f_2/6000#      #phase angle of H
H_2=H_2_max*complex(cos(H_2_phi),sin(H_2_phi))
V_out_2=H_2*V_in_2
V_out_2_R=(V_out_2).real#      #real part
V_out_2_I=(V_out_2).imag#      #imaginary part
V_out_2_max=sqrt((V_out_2_R**2)+(V_out_2_I**2))#      #peak value
V_out_2_phi=atan(V_out_2_I/V_out_2_R)#      #phase angle

#third component
A=-70*pi/180#      #-70 degrees = %0.2f radians
V_in_3=complex(cos(A),sin(A))#      #V_in_3 phasor
w=4000*pi#      #omega
f_3=w/(2*pi)#      #frequency
#equation of straight line of H_magnitude vs f is x+1000*y-4000=0
H_3_max=(4000-f_3)/1000#      #magnitude of H(traansfer function)
#equation of straight line of H_phase angle vs f is 6000*y=pi*x (phase angle = %0.2f radians)
H_3_phi=pi*f_3/6000#      #phase angle of H
H_3=H_3_max*complex(cos(H_3_phi),sin(H_3_phi))
V_out_3=H_3*V_in_3
V_out_3_R=(V_out_3).real#      #real part
V_out_3_I=(V_out_3).imag#      #imaginary part
V_out_3_max=sqrt((V_out_3_R**2)+(V_out_3_I**2))#      #peak value
V_out_3_phi=atan(V_out_3_I/V_out_3_R)#      #phase angle

print 'Output voltage is Vout1+Vout2+Vout3 where'
print ''
print 'FOR Vout1:'
print 'peak value = %0.2f volts'%V_out_1_max
print 'phase angle = %0.2f degrees'%(V_out_1_phi*180/pi)
print 'with frequency = %0.2f hertz'%f_1
print ''
print 'FOR Vout2:'
print 'peak value = %0.2f volts'%V_out_2_max
print 'phase angle = %0.2f degrees'%(V_out_2_phi*180/pi)
print 'with frequency = %0.2f hertz'%f_2
print ''
print 'FOR Vout3:'
print 'peak value = %0.2f volts'%V_out_3_max
print 'phase angle = %0.2f degrees'%(V_out_3_phi*180/pi)
print 'with frequency = %0.2f hertz'%f_3
Output voltage is Vout1+Vout2+Vout3 where

FOR Vout1:
peak value = 12.00 volts
phase angle = 0.00 degrees
with frequency = 0.00 hertz

FOR Vout2:
peak value = 6.00 volts
phase angle = 30.00 degrees
with frequency = 1000.00 hertz

FOR Vout3:
peak value = 2.00 volts
phase angle = -10.00 degrees
with frequency = 2000.00 hertz

Pg: 258 Ex: 6.3

In [3]:
from math import pi, cos, sin, atan, sqrt

R=1000/(2*pi)#      #resistance
C=10*10**-6#      #capacitance
f_B=1/(2*pi*R*C)#      #half-power frequency
#the three parts of V_in are V_1=5*cos(20*pi*t)+5*cos(200*pi*t)+5*cos(2000*pi*t)

#first component V_in_1
V_in_1=5*complex(cos(0),sin(0))#      #V_in_1 phasor
w_1=20*pi#      #omega
f_1=w_1/(2*pi)#      #frequency
H_1=1/(1+1J*(f_1/f_B))#      #transfer function
V_out_1=H_1*V_in_1
V_out_1_R=(V_out_1).real#      #real part
V_out_1_I=(V_out_1).imag#      #imaginary part
V_out_1_max=sqrt((V_out_1_R**2)+(V_out_1_I**2))#      #peak value
V_out_1_phi=atan(V_out_1_I/V_out_1_R)#      #phase angle

#second component V_in_2
V_in_2=5*complex(cos(0),sin(0))#      #V_in_2 phasor
w_2=200*pi#      #omega
f_2=w_2/(2*pi)#      #frequency
H_2=1/(1+1J*(f_2/f_B))#      #transfer function
V_out_2=H_2*V_in_2
V_out_2_R=(V_out_2).real      #real part
V_out_2_I=(V_out_2).imag      #imaginary part
V_out_2_max=sqrt((V_out_2_R**2)+(V_out_2_I**2))#      #peak value
V_out_2_phi=atan(V_out_2_I/V_out_2_R)#      #phase angle

#third component V_in_3
V_in_3=5*complex(cos(0),sin(0))#      #V_in_3 phasor
w_3=2000*pi#      #omega
f_3=w_3/(2*pi)#      #frequency
H_3=1/(1+1J*(f_3/f_B))#      #transfer function
V_out_3=H_3*V_in_3
V_out_3_R=(V_out_3).real      #real part
V_out_3_I=(V_out_3).imag      #imaginary part
V_out_3_max=sqrt((V_out_3_R**2)+(V_out_3_I**2))#      #peak value
V_out_3_phi=atan(V_out_3_I/V_out_3_R)#      #phase angle

print " All the values in the textbook are approximated, hence the values in this code differ from those of Textbook"
print 'Output voltage is Vout1+Vout2+Vout3 where'
print ''
print 'FOR Vout1:'
print 'peak value = %0.2f volts'%V_out_1_max
print 'phase angle = %0.2f degrees'%(V_out_1_phi*180/pi)
print 'with frequency = %0.2f hertz'%f_1
print ''
print 'FOR Vout2:'
print 'peak value = %0.2f volts'%V_out_2_max
print 'phase angle = %0.2f degrees'%(V_out_2_phi*180/pi)
print 'with frequency = %0.2f hertz'%f_2
print ''
print 'FOR Vout3:'
print 'peak value = %0.2f volts'%V_out_3_max
print 'phase angle = %0.2f degrees'%(V_out_3_phi*180/pi)
print 'with frequency = %0.2f hertz'%f_3
#we can observe that there is a clear discrimination = %0.2f output signals based on frequencies i.e, lesser the frequency lesser the effect.
 All the values in the textbook are approximated, hence the values in this code differ from those of Textbook
Output voltage is Vout1+Vout2+Vout3 where

FOR Vout1:
peak value = 4.98 volts
phase angle = -5.71 degrees
with frequency = 10.00 hertz

FOR Vout2:
peak value = 3.54 volts
phase angle = -45.00 degrees
with frequency = 100.00 hertz

FOR Vout3:
peak value = 0.50 volts
phase angle = -84.29 degrees
with frequency = 1000.00 hertz

Pg: 261 Ex: 6.4

In [4]:
H_max=-30#      #transfer function magnitude
f=60
m=20#      #low-frequency asymptote slope rate = %0.2f db/decade
#f_B must be K higher than f where K is
K=abs(H_max)/m
#(base 10)log(f_B/60)=1.5 ==>
f_B=60*10**1.5
print " All the values in the textbook are approximated, hence the values in this code differ from those of Textbook"
print 'Break frequency = %0.2f Hz'%f_B
 All the values in the textbook are approximated, hence the values in this code differ from those of Textbook
Break frequency = 1897.37 Hz

Pg: 262 Ex: 6.5

In [5]:
from math import pi, cos, sin, atan, sqrt
V_s=1*complex(cos(0),sin(0))
L=159.2*10**-3
R=100
C=0.1592*10**-6
f_o=1/(2*pi*sqrt(L*C))#      #resonant frequency
Q_s=2*pi*f_o*L/R#      #quality factor
B=f_o/Q_s#      #Bandwidth
#Approximate half-power frequencies are
f_H=f_o+(B/2)
f_L=f_o-(B/2)
#At resonance
Z_L=1J*2*pi*f_o*L#      #impedance of inductance
Z_C=-1J/(2*pi*f_o*C)#      #impedance of capacitance
Z_s=R+Z_L+Z_C
I=V_s/Z_s#      #phasor current
#voltages across diffrent elements are
#for resistance
V_R=R*I
V_R_R=(V_R).real      #real part
V_R_I=(V_R).imag      #imaginary part
V_R_max=sqrt((V_R_R**2)+(V_R_I**2))#      #peak value
V_R_phi=atan(V_R_I/V_R_R)#      #phase angle
#for inductance
V_L=Z_L*I
V_L_R=(V_L).real      #real part
V_L_I=(V_L).imag      #imaginary part
V_L_max=sqrt((V_L_R**2)+(V_L_I**2))#      #peak value
#Z_L is pure imaginary ==> V_L is pure imaginary which means V_L_phi can be +or- pi/2
if ((V_L/1J)==abs(V_L)):
    V_L_phi=pi/2
elif ((V_L/1J)==-abs(V_L)):
    V_L_phi=-pi/2


#for capacitance
V_C=Z_C*I
V_C_R=(V_C).real      #real part
V_C_I=(V_C).imag      #imaginary part
V_C_max=sqrt((V_C_R**2)+(V_C_I**2))#      #peak value
#Z_C is pure imaginary ==> V_C is pure imaginary which means V_C_phi can be +or- pi/2
if ((V_C/1J)==abs(V_C)) :
    V_C_phi=pi/2
elif ((V_C/1J)==-abs(V_C)) :
    V_C_phi=-pi/2

 
print 'Phasor voltage across Resistance'
print 'peak value = %0.2f volts'%V_R_max
print 'phase angle = %0.2f degrees'%(V_R_phi*180/pi)
print ''
print 'Phasor voltage across Inductance'
print 'peak value = %0.2f volts'%V_L_max
print 'phase angle = %0.2f degrees'%(V_L_phi*180/pi)
print ''
print 'Phasor voltage across Capacitance'
print 'peak value = %0.2f volts'%V_C_max
print 'phase angle = %0.2f degrees'%(V_C_phi*180/pi)
Phasor voltage across Resistance
peak value = 1.00 volts
phase angle = 0.00 degrees

Phasor voltage across Inductance
peak value = 10.00 volts
phase angle = 90.00 degrees

Phasor voltage across Capacitance
peak value = 10.00 volts
phase angle = -90.00 degrees

Pg: 264 Ex: 6.6

In [6]:
from math import pi, cos, sin, atan, sqrt
R=10*10**3
f_o=1*10**6
B=100*10**3
I=10**-3*complex(cos(0),sin(0))
Q_p=f_o/B#      #quality factor
L=R/(2*pi*f_o*Q_p)
C=Q_p/(2*pi*f_o*R)
#At resonance
V_out=I*R
Z_L=1J*2*pi*f_o*L
Z_C=-1J/(2*pi*f_o*C)

#across resistance
I_R=V_out/R
I_R_R=(I_R).real#      #real part
I_R_I=(I_R).imag#      #imaginary part
I_R_max=sqrt((I_R_R**2)+(I_R_I**2))#      #peak value
I_R_phi=atan(I_R_I/I_R_R)#      #phase angle

#across inductance
I_L=V_out/Z_L
I_L_R=(I_L).real      #real part
I_L_I=(I_L).imag#      #imaginary part
I_L_max=sqrt((I_L_R**2)+(I_L_I**2))#      #peak value
#Z_L is pure imaginary ==> V_L is pure imaginary which means V_L_phi can be +or- pi/2
if ((I_L/1J)==abs(I_L)):
    I_L_phi=pi/2
elif ((I_L/1J)==-abs(I_L)) :
    I_L_phi=-pi/2


#across capacitor
I_C=V_out/Z_C
I_C_R=(I_C).real#      #real part
I_C_I=(I_C).imag#      #imaginary part
I_C_max=sqrt((I_C_R**2)+(I_C_I**2))#      #peak value
#Z_C is pure imaginary ==> V_C is pure imaginary which means V_C_phi can be +or- pi/2
if ((I_C/1J)==abs(I_C)):
    I_C_phi=pi/2
elif ((I_C/1J)==-abs(I_C)) :
    I_C_phi=-pi/2


print 'Current phasor across Resistance'
print 'peak value = %0.3f amperes'%I_R_max
print 'phase angle = %0.f degrees'%(I_R_phi*180/pi)
print ''
print 'Current phasor across Inductance'
print 'peak value = %0.3f amperes'%I_L_max
print 'phase angle = %0.2f degrees'%(I_L_phi*180/pi)
print ''
print 'current phasor across capacitance'
print 'peak value = %0.3f amperes'%I_C_max
print 'phase angle = %0.2f degrees'%(I_C_phi*180/pi)
Current phasor across Resistance
peak value = 0.001 amperes
phase angle = 0 degrees

Current phasor across Inductance
peak value = 0.010 amperes
phase angle = -90.00 degrees

current phasor across capacitance
peak value = 0.010 amperes
phase angle = 90.00 degrees

Pg: 265 Ex: 6.7

In [7]:
from math import pi
#We need a high-pass filter
L=50*10**-3
#for the transfer function to be approximately constant = %0.2f passband area(from graph given = %0.2f the text), we choose
Q_s=1
f_o=1*10**3
C=1/(((2*pi)**2)*f_o**2*L)
R=2*pi*f_o*L/Q_s
print " All the values in the textbook are approximated, hence the values in this code differ from those of Textbook"
print ''
print 'The required second order circuit configuration is'
print 'Inductance = %0.2f KH'%(L*10**3)
print 'Capacitance = %0.2f mF(micro Farads)'%(C*10**6)
print 'Resistance = %0.2f ohms'%R
 All the values in the textbook are approximated, hence the values in this code differ from those of Textbook

The required second order circuit configuration is
Inductance = 50.00 KH
Capacitance = 0.51 mF(micro Farads)
Resistance = 314.16 ohms