import math
##Example 2.1
v_I=120.;##(V)rms primary input
v_o=9.;##(V)peak output voltage
V_Y=0.7;##(V)diode cut in voltage
##for center-tapped transformer circuit in fig.2.6(a)
v_S=v_o+V_Y##(V)peak value of secondary voltage
print"%s %.2f %s"%('\npeak value of secondary voltage= ',v_S,' V\n')
v_S_rms=v_S/math.sqrt(2)##for a sinusoidal signal rms value of v_S
print"%s %.2f %s"%('\nrms value of v_S= ',v_S_rms,' V\n')
##let turns ratio of the primary to secondary winding be x=N1/N2
x=v_I/v_S_rms;
print"%s %.2f %s"%('\nturns ratio= \n',x,'')
##for the bridge circuit in fig.2.7(a)
v_Sb=v_o+2*V_Y;##(V)peak value of secondary voltage
print"%s %.2f %s"%('\npeak value of secondary voltage= ',v_Sb,' V\n')
v_S_rms=v_Sb/math.sqrt(2.);##for a sinusoidal signal rms value of v_S
print"%s %.2f %s"%('\nrms value of v_S= ',v_S_rms,' V\n')
##let turns ratio of the primary to secondary winding be x=N1/N2
x=v_I/v_S_rms;
print"%s %.2f %s"%('\nturns ratio=\n',x,'')
##for center tapped rectifier
PIV=2*v_S-V_Y;
print"%s %.2f %s"%('\npeak inverse voltage of a diode= ',PIV,' V\n')
##for the bridge rectifier peak inverse voltage of a diode
PIV=v_Sb-V_Y;
print"%s %.2f %s"%('\npeak inverse voltage of a diode=\n',PIV,'V')
##advantage of bridge rectifier over center tapped rectifier is it requies only half of the turns
import math
##Example 2.2
##full wave rectifier circuit with 60Hz input signal
V_M=10.;##(V)peak output voltage
R=0.01;##(MOhm)output load resistance
f=60.;##Hz
V_r=0.2;##(V)ripple voltage
C=V_M/(2.*f*R*V_r);##capacitance
print"%s %.2f %s"%('\ncapacitance= ',C,' microF\n')
import math
##Example 2.3
V_O=12.;##(V)peak output voltage
I_L=0.12;##(A)current delivered to the load
R=V_O/I_L;
print"%s %.2f %s"%('\neffective load resistance= ',R,' Ohm\n')
V_Y=0.7;##(V)diode cut in voltage
v_S=V_O+2.*V_Y;
print"%s %.2f %s"%('\npeak value of v_S= ',v_S,' V\n')
v_Srms=v_S/math.sqrt(2.);
print"%s %.2f %s"%('\nrms voltage= ',v_Srms,' V\n')
##let x=N1/N2
Vin=120.;##(V)input line voltage
x=Vin/v_Srms;
print"%s %.2f %s"%('\nturns ratio= \n',x,'')
VM=12.;##(V)
Vr=5/100.*VM;
print"%s %.2f %s"%('\nripple voltage= ',Vr,' V\n')
f=60.;##(Hz) input frequency
C=VM/(2.*R*Vr*f);
print"%s %.2f %s"%('\nfilter capacitance= ',C,' F\n')
i_Dmax=(VM/R)*(1+2*math.pi*math.sqrt(VM/(2.*Vr)));
print"%s %.2f %s"%('\npeak diode current= ',i_Dmax,' A\n')
R=0.1;##Kohm
i_Davg=(1/(2.*math.pi))*math.sqrt(2.*Vr/VM)*((VM/R)*(1.+math.pi*math.sqrt(VM/(2.*Vr))));
print"%s %.2f %s"%('\naverage diode current= ',i_Davg,' mA\n')
PIV=v_S-V_Y;
print"%s %.2f %s"%('\npeak inverse voltage= ',PIV,' V\n')
import math
##Example 2.5
rZ=4.;##(Ohm) Zener resistance
V_Lnom=9.;##(V) nominal output voltage
Izmax=0.3;##(A) maximum zener diode current
Izmin=0.03;##(A) minimum zener diode current
V_Lmax=V_Lnom+Izmax*rZ
V_Lmin=V_Lnom+Izmin*rZ
##percent regulation R
R=((V_Lmax-V_Lmin)/V_Lnom)*100.;
print"%s %.2f %s"%('\npercent regulation= ',R,' \n')
import math
##Example 2.8
R1=5.;R2=10.;##(KOhm)
V_Y=0.7;##(V)diode cut in voltage
V1=5.;V2=-5;##(V)
vt=0.;##(V)
##asssuming initially diode D1 is off
##iR1=iD2=iR2=V1-V2-V_Y/(R1+R2)
iD2=(V1-V2-V_Y)/(R1+R2);
print"%s %.2f %s"%('\ndiode current= ',iD2,'mA\n')
iR1=iD2;
vo=V1-iR1*R1;
print"%s %.2f %s"%('\noutput voltage= ',vo,' V\n')
v=vo-V_Y;##v=v'
print"%s %.2f %s"%('\nVoltage= ',v,' V\n')
vt=4.;##(V)fig.2.33
##both D1 and D2 are on
vo==vt;
vo=4.;
iD2=(V1-vo)/R1;
print"%s %.2f %s"%('\ndiode current= ',iD2,' mA\n')
iR1==iD2;
v=vo-V_Y;
print"%s %.2f %s"%('\nV= ',v,' V\n')
iR2=(v-V2)/R2;
print"%s %.2f %s"%('\niR2= ',iR2,' mA\n')
iD1=iR2-iD2;
print"%s %.2f %s"%('\ncurrent through D1= ',iD1,' mA\n')
import math
##Example 2.10
n=1.;##quantum efficiency
A=10**-2;##cm^2 junction area
p=5*10**17;##(cm^-2-s^-1) incident photon flux
e=1.6*10**-16;##charge of an electron
Iph=n*e*p*A;
print"%s %.2f %s"%('\nphotocurrent= ',Iph,' mA\n')
import math
##Example 2.11
I=0.01;##(A) diode current
V_Y=1.7;##(V) forward bias voltage drop
Vt=0.2;##(V)
R=(5.-V_Y-Vt)/I;
print"%s %.2f %s"%('\nresistance= ',R,' Ohm')