#Example 8.1
#In the circuit of figure 8-4(a), R1=100 ohm,R2=56 kilo Ohm, Vin=V pp sine wave
#and the opamp is type 741 with supply voltages 15 V, -15 V.
#Determine the threshold voltages Vul and Vut and draw the output waveform.
from __future__ import division #to perform decimal division
%matplotlib inline
import math
import array
import numpy as np
#Variable declaration
R1=100
R2=56*10**3
vin=1 #Input voltage in volt
pos_Vsat=14 #Positive saturation voltage in volt
neg_Vsat=-14 #Negative saturation voltage in volt
Vut=(R1/(R1+R2))*(pos_Vsat) #Upper threshold voltage
#calculation
Vut=(R1/(R1+R2))*(pos_Vsat) #Upper threshold voltage
Vlt=(R1/(R1+R2))*(neg_Vsat) #Lower threshold voltage
t=np.arange(0,2*math.pi,0.1)
vut=0.5*np.sin(t)
subplot(211)
plt.plot(t,vut)
plt.ylabel('Vin')
plt.xlabel('t')
plt.title(r'$Input voltage$')
import matplotlib.pyplot as plt
t1=math.asin(0.025/0.5)
t2=math.pi-math.asin(-0.025/0.5)
t3=2*math.pi
x=[0,t1,t2,t3]
y=[-14,14,-14,14]
plt.subplot(212)
plt.step(x,y) #Plotting square wave
plt.title('Output Waveform')
plt.xlabel('t')
plt.ylabel('Vo')
#result
plt.show()
#Example 8.2
#In the circuit of figure 8-7(a), Vin=500 mV peak 60-Hz sinewave, R=100 ohm.
#IN3826 zener with Vz=5.1 V and the supply voltages= 15 V, -15V.
#Determine the output voltage swing.Assume that the voltage drop across
#the forward biased zener=0.7V.
%matplotlib inline
from __future__ import division #to perform decimal division
import numpy as np
import matplotlib.pyplot as plt
import math
import array
#Variable declaration
vin=5*10**-3
R=100
Vd1=-0.7 # Output voltage during positive half-cycle of the input
Vd2=5.1 # Output voltage during negative half-cycle of the input
#calculation
t=np.arange(0,2*math.pi,0.1)
vut=0.5*np.sin(t)
subplot(211)
plt.plot(t,vut)
plt.ylabel('Vin')
plt.xlabel('t')
plt.title(r'$Input voltage$')
t1=math.pi
t2=2*math.pi
x=[0,t1,t2]
y=[-0.7,-0.7,5.1]
subplot(2,1,2)
plt.step(x,y)
plt.title('Output Waveform')
plt.xlabel('t')
plt.ylabel('Vo')
#result
print "#Since zener diode is forward biased"
print "Output voltage during positive half-cycle of the input is",Vd1,"V"
print "Output voltage during negative half-cycle of the input is",Vd2,"V"
plt.show()
#Example 8.3
#The V..F converter of figure 8-12 is initially adjusted for a 10 kHz full scale
#output frequency.Determine the output frequencies Fo and Fo/2 if the output
#signal Vin=2 V.
%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib.pyplot import subplot
from __future__ import division #to perform decimal division
import math
import array
#Variable declaration
Vin=2 # Input voltage
Fo1=2*10**3 # Output freq Fo when Vin=2V
Fo2=1*10**3 # Output freq Fo/2 when Vin=2V
#calculation
import array
v=array.array('i',(0 for i in range(0,50)))
count=1
for i in range(1,50): #for 5 cycles
if count<4:
v[i]=5
else:
v[i]=0
if count<10:
count=count+1
else:
count=1
plt.subplot(211)
plt.plot(v)
plt.title('Output Waveform')
plt.xlabel('t(microsec)')
plt.ylabel('Pulse freq output,Fo(V)')
import matplotlib.pyplot as plt
for i in range(1,50): #for 5 cycles
if count<10:
v[i]=5
else:
v[i]=0
if count<20:
count=count+1
else:
count=1
plt.subplot(2,1,2)
plt.plot(v)
plt.title('Output Waveform')
plt.xlabel('t(microsec)')
plt.ylabel('Pulse freq output,Fo(V)')
plt.show()
#result
print "Output freq Fo is ",Fo1,"Hz"
print "Output freq Fo/2 is",Fo2,"Hz"
#Example 8.4
#The F/V converterof figure 8-14(a) is initially adjusted for Vo=2.8V at Fin max
#of 10 kHz. Determine the output voltage Vo if fin= 1 kHz.
#Variable decclaration
Vo=2.8 #At Finmax of 10kHz
#Calculation
Vo1=Vo/10 #Output voltage at Fin=1kHz
#Result
print "Output voltage is",Vo1,"Volts"
#Example 8.5
#In the circuit of figure 8-25(a), Vin=200 mV peak to peak sine wave at 100 Hz.
#Briefly describe the operation of the circuit and draw the output waveform.
%matplotlib inline
import matplotlib.pyplot as plt
from __future__ import division #to perform decimal division
import numpy as np
import math
import array
#Variable declaration
Vin=100*10**-3 # Input voltage
#calculation
t=np.arange(0,math.pi,0.1) #time scale
v=Vin*np.sin(t)
import matplotlib.pyplot as plt
plt.xlim(0,2*math.pi)
plt.ylim(0,0.1)
plt.plot(t,v)
plt.ylabel('Vin')
plt.xlabel('t')
plt.title(r'$Input voltage$')
#result
plt.show()