In [1]:

```
from math import log10
#Variable declaration
#(i)
A_v=30; #Voltage gain
#(ii)
A_p=100; #Power gain
#Calculations
#(i)
A_v_dB=20*log10(A_v); #Voltage gain, dB
A_p_dB=10*log10(A_p); #Power gain, dB
#Results
print("(i) Voltage gain in dB=%.2fdB"%A_v_dB);
print("(ii) Power gain in dB=%ddB"%A_p_dB);
```

In [2]:

```
#(i)
A_p_dB=40.0; #Power gain in dB
A_p_b=A_p_dB/10; #Power gain in bel
A_p=10**A_p_b; #Power gain in number
#Result
print("(i) Power gain in number=%d"%A_p);
#(ii)
A_p_dB=43.0; #Power gain in dB
A_p_b=A_p_dB/10; #Power gain in bel
A_p=round(10**A_p_b,-4); #Power gain in number
#Result
print("(ii) Power gain in number=%d"%A_p);
```

In [3]:

```
from math import log10
#Variable declaration
Av_1=100.0; #Voltage gain of stage 1
Av_2=200.0; #Voltage gain of stage 2
Av_3=400.0; #Voltage gain of stage 3
#Calculations
Av_1_dB=20*log10(Av_1); #Voltage gain of stage 1, dB
Av_2_dB=20*log10(Av_2); #Voltage gain of stage 2, dB
Av_3_dB=20*log10(Av_3); #Voltage gain of stage 3, dB
Av_T=Av_1_dB+Av_2_dB+Av_3_dB; #Total voltage gain
#Result
print("The total voltage gain=%ddB"%Av_T);
```

In [4]:

```
from math import log10
#Variable declaration
A_p_absolute=30.0; #Absolute gain of each stage
number_of_stages=5.0; #number of stages
negative_feedback=10.0; #negative feedback, dB
#Calculations
#(i)
A_p_dB=round(10*log10(A_p_absolute),2); #Power gain of one stage. dB
A_p_T=number_of_stages * A_p_dB; #Total power gain, dB
#(ii)
A_p_resultant=A_p_T-negative_feedback; #Resultant power gain with negative feedback, dB
#Results
print("The total power gain = %.2fdB."%A_p_T);
print("The resultant power gain with negative feedback = %.2fdB."%A_p_resultant);
```

In [5]:

```
from math import log10
#Variable declaration
P_out_2kHz=1.5; #Output power at 2 kHz, W
P_out_20kHz=0.3; #Output power at 20 kHz, W
P_in=10.0; #Input power, mW
#Calculations
A_p_dB_2kHz=10*log10(P_out_2kHz*1000/P_in); #dB power gain at 2 kHz
A_p_dB_20kHz=10*log10(P_out_20kHz*1000/P_in); #dB power gain at 20 kHz
Fall_in_gain=A_p_dB_2kHz-A_p_dB_20kHz; #Fall in gain from 2kHz to 20kHz
#Results
print("The fall in gain from 2kHz to 20kHz=%.2fdB"%Fall_in_gain);
```

In [6]:

```
from math import log10
#Variable declaration
A_v=15.0; #Voltage gain, dB
V_1=0.8; #Input signal voltage, V
#Calculations
#Since, Av(in decibel)=20*log10(V_2/V_1),
V_2=V_1*(10**(A_v/20)); #Output voltage, V
#Results
print("The output voltage= %.1fV."%V_2);
```

In [7]:

```
#Variable declaration
A_0_dB=70.0; #Open circuit voltage gain, dB
A_v_dB=67.0; #Voltage gain, dB
R_out=1.5; #Output resistance, kilo ohm
#Calculations
#Since, A_0_dB-A_v_dB=20*log10(A_0/A_v)
ratio_A0_Av=round(10**((A_0_dB-A_v_dB)/20),2); #Ratio of open-circuit voltage gain to normal voltage gain
#Since, A_v/A_0 = RL/(R_out+RL)
RL=R_out/(ratio_A0_Av-1); #Load resistor, kilo ohm
#Results
print("The load resistance=%.2f kilo ohm."%RL);
#Note: The value of load resistor is calculated to be 3.6585 kilo ohm and approximated to 3.66. But, in the text it has been approximated to 3.65.
```

In [8]:

```
#Variable declaration
RL=1.0; #Load resistance, kilo ohm
A_v=40.0; #Voltage gain, dB
V_in=10.0; #Input signal voltage, mV
#Calcultaions
#(i)
#Since, A_v=20*log10(V_out/V_in)
V_out=V_in*(10**(A_v/20))/1000; #Output voltage, V
#(ii)
P_L=(V_out**2/RL); #The load power, mW
#Results
print("(i)The output voltage is %dV."%V_out);
print("(ii)The load poweris %dmW."%P_L);
```

In [9]:

```
from math import log10
#Variable declaration
P_2=40.0; #Output power, W
R=10.0; #Resistance of speaker, ohm
#Calculations
#(i)
A_p_dB=25.0; #Power gain, dB
#Since, A_p_dB=10*log10(P_2/P_1)
P_1=(P_2/10**(A_p_dB/10))*1000; #Input power, mW
#(ii)
A_v_dB=40.0; #Voltage gain, dB
#Since, P=(V**2)/R,
V_2=(P_2*R)**0.5; #Output voltage, V
#Since, A_v_dB=20*log10(V_2/V_1)
V_1=(V_2/10**(A_v_dB/20))*1000; #Input voltage, mV
#Results
print("(i)The input power=%.1fmW."%P_1);
print("(ii)The input voltage=%dmV."%V_1);
```

In [10]:

```
#Variable declaration
A_v_max=2000.0; #Maximum voltage gain
f_max=2.0; #Frequency at which maximum voltage gain occurs,kHz
A_v=1414.0; #Voltage gain at 50 Hz and 10kHz
f1=50; #Lower frequency at which gain is 1414, Hz
f2=10; #Upper frequency at which gain is 1414, kHz
#Calculation
#Since, bandwidth is the range of frequency over which gain is greater than or equal to 70.7% of maximum gain
if((A_v/A_v_max)*100 ==70.7):
print("(i)The bandwidth is from %dHz to %dkHz."%(f1,f2));
print("(ii)The lower cut-off frequency=%dHz."%f1);
print("(iii)The upper cut-off frequency=%dkHz."%f2);
```

In [11]:

```
#Variable declaration
A_v=60.0; #Voltage gain of single stage amplifier
R_C=500.0; #Collector load, ohm
R_in=1.0; #Input impedance, kilo ohm
#Calculation
#Since, there is no loading , second stage gain remains at A_v
#But, due to loading effect of input impedance of second stage, gain of first stage decreases
A_v_2=A_v; #Voltage gain of second stage
R_AC=round((R_C*R_in*1000)/(R_C+R_in*1000),0); #Effective load of first stage, ohm
A_v_1=A_v*R_AC/R_C; #Gain of first stage
A_v_T=A_v_1*A_v_2; #Total gain
#Results
print("The total gain=%d."%A_v_T);
```

In [13]:

```
#Variable declaration
Rin=1.0; #Input resistance, kilo ohm
beta=100.0; #base current amplification factor
RC=2.0; #Collector load, kilo ohm
#Calculation
#(i)
R_AC=(RC*Rin)/(RC+Rin); #Effective load on first stage, kilo ohm
A_v_1=round(beta*(R_AC/Rin),0); #Voltage gain of first stage
#(ii)
A_v_2=round(beta*RC/Rin,0); #Voltage gain of second stage
#(iii)
A_v_T=A_v_1*A_v_2; #Total voltage gain
#Results
print("(i)The voltage gain of first stage =%d."%A_v_1);
print("(ii)The voltage gain of second stage =%d."%A_v_2);
print("(iii)The total voltage gain =%d."%A_v_T);
#Note: The approximation inthe text for A_v_1=66.66 is taken as 66 but here it has been taken 67 and therefore the total voltage is 13400 instead of 13200.
```

In [14]:

```
#Variable declaration
RC=10.0; #Collector load of single stage amplifier, kilo ohm
Rin=1.0; #Input resistance, kilo ohm
beta=100.0; #base current amplification factor
RL=100.0; #Load resistor, ohm
#Calculations
R_AC=round((RC*1000)*RL/(RC*1000+RL),-1); #Effective collector load,
A_v=beta*R_AC/(Rin*1000); #Voltage gain
#Results
print("The voltage gain=%d."%A_v);
```

In [15]:

```
#Variable declaration
VCC=20.0; #Collector suppply voltage, V
R1=10.0; #resistor R1, kilo ohm
R2=2.2; #resistor R2, kilo ohm
R3=10.0; #resistor R3, kilo ohm
R4=2.2; #resistor R4, kilo ohm
RC_1=3.6; #Collector resistor of first stage, kilo ohm
RC_2=4.0; #Collector resistor of second stage, kilo ohm
RE_1=900.0; #Emitter resistor of first stage, ohm
RE_2=1.0; #Emitter resistor of second stage, kilo ohm
#Calculations
#Biasing potential for the second stage is the voltage across R4 resistor,
#so, by voltage divider rule:
VB=VCC*R4/(R3+R4); #Biasing potential for second stage,(Voltage across R4), V
print("The biasing voltage for the second stage=%.1fV."%VB);
#If coupling capacitor C_c is replaced by a wire, RC_1 and R3 become parallel
Req=round((RC_1*R3)/(RC_1+R3),2); #Equivalent resistance of R3 parallel with RC_1, kilo ohm
VB=VCC*R4/(Req+R4); #Biasing voltage if coupling capacitor is replaced by a wire, V
print("The biasing voltage after replacing coupling capacitor by wire=%.2fV."%VB);
```

In [16]:

```
#Function for calculating parallel resistance
def pr(r1,r2):
return (r1*r2)/(r1+r2);
#Variable declaration
VCC=15.0; #Collector supply voltage, V
R1=22.0; #Resistor R1, kilo ohm
R2=3.3; #Resistor R2, kilo ohm
R3=5.0; #Resistor R3, kilo ohm
R4=1.0; #Resistor R4, kilo ohm
R5=15.0; #Resistor R5, kilo ohm
R6=2.5; #Resistor R6, kilo ohm
R7=5.0; #Resistor R7, kilo ohm
R8=1.0; #Resistor R8, kilo ohm
beta=200; #Base current amplification factor
RL=10.0; #Load resistor, kilo ohm
V_BE=0.7; #Base-emitter voltage, V
#Calculations
#for 2nd stage
V_R6=round(VCC*R6/(R5+R6),2); #Voltage across R6, V (voltage divider rule)
V_R8=round(V_R6-V_BE,2); #Voltage across R8, V
IE_2=round(V_R8/R8,2); #Emitter current through R8, mA (OHM's LAW)
re_2nd_stage=round(25/IE_2,1); #a.c emitter resistance for 2nd stage, ohm
#For 1st stage
V_R2=round(VCC*R2/(R1+R2),2); #Voltage across R2, V (voltage divider rule)
V_R4=round(V_R2-V_BE,2); #Voltage across R4, V
IE_1=round(V_R4/R4,2); #Emitter current through R4, mA (OHM's LAW)
re_1st_stage=round(25/IE_1,1); #a.c emitter resistance for 1st stage, ohm
#(i)
Zin_base_2nd_stage=round((beta*re_2nd_stage)/1000,2); #input resistance of transistor base of 2nd stage, kilo ohm
Zin=round(pr(pr(R5,R6),Zin_base_2nd_stage),2); #Input impedance of the 2nd stage, kilo ohm
R_AC_1st_stage=round(pr(R3,Zin),2); #Effective collector load for 1st stage, kilo ohm
A_v_1=round(R_AC_1st_stage*1000/re_1st_stage,0); #voltage gain of 1st stage
#(ii)
R_AC_2nd_stage=round(pr(R7,RL),2); #Effective collector load for 2nd stage, kilo ohm
A_v_2=round(R_AC_2nd_stage*1000/re_2nd_stage,1); #voltage gain of 2nd stage
#(iii)
A_v_overall=A_v_1*A_v_2; #overall voltage gain
#results
print("(i)The voltage gain of 1st stage=%.0f."%A_v_1);
print("(i)The voltage gain of 2nd stage=%.1f."%A_v_2);
print("(i)The overall voltage gain =%d."%A_v_overall);
```

In [17]:

```
#Variable declaration
Primary_impedance=1000.0; #Primary impedance, ohm
Load_impedance=10.0; #Load impedance, ohm
#Calculation
#since,for maximum power transfer primary impedance should be equal to output impedance
#and, impedance of secondary should be equal to load impedance
#therfore, primary_impedance/load_impedance=square of(primary to secondary turn ratio)
n=(Primary_impedance/Load_impedance)**0.5; #Primary to secondary turn ratio
#Result
print('The primary to secondary turn ratio for maximum power transfer=%d.'%n);
```

In [18]:

```
#Variable declaration
RL=16.0; #Load resistor, ohm
R_p=10.0; #Output impedance of primary, kilo ohm
Vp=10.0; #Terminal voltage of the source, V
#Calculation
#Since, for maximum power transfer, the impedance of the primary should be equal to output impedance of the source
n=(R_p*1000/RL)**0.5; #Primary to secondary turns ratio
#Since, power in a transformer remains constant,
#ratio of primary to secondary voltageis equal to primary to secondary turns ratio
Vs=Vp/n; #Voltage across the external load, V
#Result
print("The primary to secondary turns ratio=%d."%n);
print("The voltage across the external load=%.1fV."%Vs);
```

In [20]:

```
#Variable declaration
Rp=300.0; #D.C resistance of primary, ohm
RL=3.0; #Load resistance, ohm
R_out=3.0; #Ouput resistance of the transistor, kilo ohm
#Calculation
#when no signal is applied, only Rp is seen to be the load.
#But, when a.c signal is applied, RL in secondary reflects as RL*(squre of turns ratio).
#Therefore, load is seen to be Rp in series with the reflected RL in primary.
#i.e, R_out=Rp+(n**2 * RL), where n is the turns ratio
n=((R_out*1000-Rp)/RL)**0.5; #turns ratio
#Result
print("Turns ratio for maximum power transfer=%d."%n);
```

In [22]:

```
from math import pi
#Variable declaration
f=200.0; #Frequency, Hz
Z_out=10.0; #Output impedance of the transistor, kilo ohm
Z_in=2.5; #Input impedance of the next stage, kilo ohm
#Calculation
#For perfect impedance matching,
#Z_out should be equal to primary impedance
#Z_out=2*pi*f*(primary inductance)
Lp=(Z_out*1000)/(2*pi*f); #Primary inductance, H
#for the secondary side,
#Z_in should be equal to impedance of secondary
Ls=(Z_in*1000)/(2*pi*f); #Secondary inductance, H
#result
print("The primary inductance=%.0fH."%Lp);
print("The secondary inductance=%.0fH."%Ls);
```

In [23]:

```
#Variable declaration
Lp=8.0; #Primary inductance, H
Ls=2.0; #Secondary inductance, H
K=10**-5; #Inductance to turns ratio, constant
#Calculations
Np=(Lp/K)**0.5; #Primary turns
Ns=(Ls/K)**0.5; #Secondary turns
#Result
print("The primary turns=%.0f."%Np);
print("The secondary turns=%.0f."%Ns);
```

In [24]:

```
#Variable declaration
VCC=12.0; #Collector supply voltage, V
R1=100.0; #Resistor R1, kilo ohm
R2=22.0; #Resistor R2, kilo ohm
R3=22.0; #Resistor R3, kilo ohm
R4=4.7; #Resistor R4, kilo ohm
R5=10.0; #Resistor R5, kilo ohm
R6=10.0; #Resistor R6, kilo ohm
beta=125; #Base current amplification factor
V_BE=0.7; #Base-emitter voltage, V
#Calculation
#(i) D.C voltages
#For 1st stage:
V_B1=VCC*R2/(R1+R2); #Voltage at the base of 1st transistor, V (Voltage across R2, using voltage divider rule)
V_E1=V_B1-V_BE; #Emitter voltage of the 1st transistor, V
I_E1=round(V_E1/R4,2); #Emitter current of 1st transistor, mA (OHM's LAW)
I_C1=I_E1; #Collector current of 1st transistor, mA(approximately equals to emitter current)
V_C1=VCC-I_C1*R3; #Collector voltage of 1st transistor, V
#For 2nd stage:
V_B2=V_C1; #Voltage at the base of 2nd transistor, V (equals to collector voltage of 1st transistor)
V_E2=V_C1-V_BE; #Emitter voltage of the 2nd transistor, V
I_E2=V_E2/R6; #Emitter current of 2nd transistor, mA (OHM's LAW)
I_C2=I_E2; #Collector current 2nd transistor, mA(approximately equals to emitter current)
V_C2=VCC-I_C2*R5; #Collector voltage of 2nd transistor, V
print("(i) D.C voltages");
print("First stage: VB1=%.2fV , VE1=%.2fV and VC1=%.2fV"%(V_B1,V_E1,V_C1));
print("First stage: VB2=%.2fV , VE2=%.2fV and VC2=%.2fV"%(V_B2,V_E2,V_C2));
#(ii)Voltage gain
#First stage
re_1=25/I_E1; #a.c emitter resistance of 1st transistor, ohm
re_2=25/I_E2; #a.c emitter resistance of 2nd transistor, ohm
Zin_2nd_stage=beta*re_2/1000; #Input impedance of 2nd stage, kilo ohm
R_AC=R3*Zin_2nd_stage/(R3+Zin_2nd_stage); #Total a.c collector load, kilo ohm
A_v1=round(R_AC*1000/re_1,0); #Voltage gain of first stage
print("The voltage gain of first stage=%d."%A_v1);
#Second stage
R_AC=R5; #Total a.c collector load for 2nd stage, kilo ohm(Due to no loading effect, equal to R5)
A_v2=round(R5*1000/re_2,0); #Voltage gain of 2nd stage
print("The voltage gain of second stage=%d."%A_v2);
A_vT=A_v1*A_v2; #Overall voltage gain
print("Overall voltage gain=%d."%A_vT);
```

In [ ]:

```
```