# Chapter 7: Nonlinear Circuits¶

## Example 7.1, Page 215¶

In [3]:
#Variable declaration
R=10*10**6;          #in Ohm

#Calculations&Results
T=R*C;          #discharge Time
print "T = %.1fS"%T;
Vled=2.5;       #in V
Vsat=13;            #in V
Rl=500;         #in Ohm
Iled=(Vsat-Vled)/Rl*10**3;
print "Iled = %.f mA"%Iled;

T = 0.1S
Iled = 21 mA


## Example 7.2, Page 222¶

In [6]:
import math
import matplotlib.pyplot as plt
import numpy
%matplotlib inline

#Variable declaration
R2=1.5*10**3;          #in Ohm
R1=10*10**3;          #in Ohm
Vcc=15;         #in V
Vpm=1;         #in V

#Calculations&Results
Vofst=Vcc*R2/(R1+R2);
print "Voffset = %0.2f V"%Vofst;
Vc=Vofst+Vpm;
print "Vc = %0.2f V"%Vc;
Rl=10*10**6;          #in Ohm
T=Rl*C;          #discharge Time
print "T = %0.2f S"%T;
Vinp=1.96;
Vinm=5.96;
Vind=Vinp-Vinm;
print "Vin_diff =% 0.0f V"%Vind;
#Graph
t=numpy.linspace(0,5);
f=1;        #1kHz
Vin=2*numpy.sin(f*numpy.pi*t);
Vin1=Vin**2-1;
Vout=Vin1+2.96;

plt.plot(t,Vout,'b')
plt.plot(t,Vin1,'g')
plt.title("Green Input  signal & Blue Output signal")
plt.xlabel("t")
plt.ylabel("Vin");
plt.grid();
plt.show()

Voffset = 1.96 V
Vc = 2.96 V
T = 0.10 S
Vin_diff =-4 V


## Example 7.3, Page 226¶

In [7]:
import numpy

#Variable declaration
Rf=20*10**3;          #in Ohm
Ri=10*10**3;          #in Ohm
Av=-Rf/Ri;
Vin=4;          #in V

#Calculations&Results
Vout=Av*Vin;
print "Vout = %0.0f V(peak)"%Vout;
Vzener=5.1;          #in V

Vlimit=(Vzener+0.7);
print "Vlimit +_%.1f V"%Vlimit;

Vout = -8 V(peak)
Vlimit +_5.8 V


## Example 7.4, Page 229¶

In [8]:
import matplotlib.pyplot as plt
import numpy
%matplotlib inline

#Variable declaration
Vz=3.9;         #in V
Rf=20000.;           #in Ohm
Ri=5000;           #in Ohm
Ra=10000;           #in Ohm

#Calculations&Results
Vbreak=Vz+0.7;
print "Vbreak = +_ %.2f V"%Vbreak;

Av=-Rf/Ri;
print "Av = %.2f "%Av;

Av2=(-Rf*Ra/(Rf+Ra))/Ri;
print "Av2 = %.2f "%Av2;
#Graph
t=list(range(-4,5));
L=len(t);

def f():
x1=[]
for i in range(0,L):
if t[i]<-1.15:
x2=Av2*t[i]+3.0705;
x1.append(x2)

elif t[i]<1.15:
x2=Av*t[i] ;
x1.append(x2)

elif t[i]>1.15:
x2=Av2*t[i]-3.0705 ;
x1.append(x2)

return x1

z = f()
plt.plot(t,z);
plt.title('Transfer Characteristics')
plt.xlabel('Vin')
plt.ylabel('Vout')
plt.grid();
plt.show()

Vbreak = +_ 4.60 V
Av = -4.00
Av2 = -1.33


## Example 7.5, Page 231¶

In [10]:
import matplotlib.pyplot as plt
%matplotlib inline

#Variable declaration
Vz1=1;         #in V
Vz2=2.2;         #in V
Rf=12000;           #in Ohm
Ri=10000;           #in Ohm
R2=15000;           #in Ohm
R1=20000;           #in Ohm

#Calculations&Results
Vbreak1=Vz1+0.7;
print "Vbreak1_in = +_ %.2f V"%Vbreak1;
Vbreak2=Vz2+0.7;
print "Vbreak2_in = +_ %.2f V"%Vbreak2;

Av=-Rf/Ri;
print "Av %.1f "%Av;
Av1=-Rf*(Ri+R1)/(R1*Ri);
print "Av1 %.1f "%Av1;

Av2=-Rf*(Ri*R1+R1*R2+R2*Ri)/(R1*Ri*R2);
print "Av2 = %.1f "%Av2;
Vbreak1_out=Av*Vbreak1
Vbreak2_out=Vbreak1_out+Av2*(Vbreak2-Vbreak1);
print "Vbreak1_out = %.2f V "%Vbreak1_out;
print "Vbreak2_out = %.2f V"%Vbreak2_out;
#graph
t=list(range(-5,6));
L=len(t);

def f():
x1=[]
for i in range(0,L):
if t[i]<-2.9:
x2=Av2*t[i]-3;
x1.append(x2)
elif t[i]<-1.15:
x2=Av1*t[i]-0.67;
x1.append(x2)
elif t[i]<1.15:
x2=Av*t[i] ;
x1.append(x2)
elif t[i]<2.9:
x2=Av1*t[i]+0.67 ;
x1.append(x2)
elif t[i]>2.9:
x2=Av2*t[i]+3;
x1.append(x2)

return x1
z = f()
plt.plot(t,z);
plt.title('Transfer Characteristics')
plt.xlabel('Vin')
plt.ylabel('Vout')
plt.show()

Vbreak1_in = +_ 1.70 V
Vbreak2_in = +_ 2.90 V
Av -2.0
Av1 -2.0
Av2 = -3.0
Vbreak1_out = -3.40 V
Vbreak2_out = -7.00 V


## Example 7.6, Page 232¶

In [11]:
import matplotlib.pyplot as plt
%matplotlib inline

#Variable declaration
Vz1=1;         #in V
Vz2=2.2;         #in V
Rf=10000;           #in Ohm
Ri=10000;           #in Ohm

#Calculations&Results
Vzp=3-0.7;
print "Vz+in = %.2f V"%Vzp;
Vzm=-(4-0.7);
print "Vz_in = %.2f V"%Vzm;
#Ra||Rf=8k
Ra=8000*Rf/(Rf-8000);
Av2=0.8;
Av1=1;
#graph
t=list(range(-50,50));
L=len(t);

def f():
x1=[]
for i in range(0,L):
if t[i]<-40:
x2=0.8*t[i]-8;
x1.append(x2)
elif t[i]<30+0.01:
x2=1*t[i];
x1.append(x2)

elif t[i]>30:
x2=0.8*t[i]+5.5;
x1.append(x2)
return x1
z = f()
plt.plot(t,z);
plt.title('Transfer Characteristics')
plt.xlabel('Vin')
plt.ylabel('Vout')
plt.show()

Vz+in = 2.30 V
Vz_in = -3.30 V


## Example 7.7, Page 241¶

In [12]:
import matplotlib.pyplot as plt
import math
import numpy
from scipy import signal
%matplotlib inline

#Variable declaration
Vi=5;         #in V
Vsat=13;         #in V
R2=2000;           #in Ohm
R1=20000;           #in Ohm

#Calculations
Vupper=Vsat*R2/R1;
Vlower=-Vsat*R2/R1;
print "Vupperthreshold = %.1f V"%Vupper;
print "Vlowerthreshold = %.1f V"%Vlower;
#t=list(range(0,20));
t = numpy.linspace(0,20)
f=0.1;
x3=1*numpy.sin(2*f*numpy.pi*t);
A=math.asin(Vupper);
k=math.atan(A)

x4=(2*f*math.pi*t-2*f*math.pi*k)
plt.figure(1)
plt.subplot(211)
plt.plot(t,x3)
plt.xlabel('time n--->');
plt.ylabel('Vout--->');
plt.grid()
plt.subplot(212)
plt.plot(t,signal.square(x4),'g');
plt.xlabel('time n--->');
plt.ylabel('Vout--->');
plt.title('Input(Blue) / Output(Green)');
plt.grid();
plt.show()

Vupperthreshold = 1.0 V
Vlowerthreshold = -2.0 V


## Example 7.8, Page 250¶

In [13]:
import math

#Variable declaration
Vin=1;         #in V
T=300;          #in Kelvin
Ri=50000;           #in Ohm
Is=30*10**-9;                #in Amp

#Calculations&Results
#Vout=-0.0259*math.ln(Vin/RiIs)
Vout=-0.0259*math.log1p(Vin/(Ri*Is))
print "Vout when Vin=1V is %.4f V"%Vout;
#for Vin=0.5V
Vin1=0.5;         #in V
Vout1=-0.0259*math.log1p(Vin1/(Ri*Is))
print "Vout when Vin=0.5V is %.4f V"%Vout1;
#for Vin=2V
Vin2=2;         #in V
Vout2=-0.0259*math.log1p(Vin2/(Ri*Is))
print "Vout when Vin=2V is %.4f V"%Vout2;

Vout when Vin=1V is -0.1684 V
Vout when Vin=0.5V is -0.1505 V
Vout when Vin=2V is -0.1864 V


## Example 7.9, Page 253¶

In [14]:
import numpy
import matplotlib.pyplot as plt
%matplotlib inline

#Variable declaration
K=0.1;
t=numpy.linspace(0,0.5);

#Calculations
Vin=2*numpy.sin(2*60*numpy.pi*t);
Vout=K*Vin**2;

#Results
plt.plot(t,Vout)
plt.plot(t,Vin)
plt.title(" Input(Green)  signal &  Output (Blue)signal")
plt.xlabel("t")
plt.ylabel("V");
plt.show()
#output appears different due to use of python poltting libraries