# Chapter 10: Integrators and Differentiators¶

## Example 10.1, Page 354¶

In [1]:
import math

#Variable declaration
t=0;
Ri=10000;           #in Ohm
Rf=100000;           #in Ohm

#Calculations
#Vout(t)=-1/(Ri*C)*int(Vi(t))dt
Flow=1/(2*math.pi*Rf*C);

#Result
print "Flow is %.0f Hz"%Flow;

Flow is 159 Hz


## Example 10.2, Page 356¶

In [2]:
import sympy
from sympy import Symbol,integrate,sin,pi
#Variable declaration
Ri = 10*10**3  #ohms
C = 10*10**-9  #F

#Calculations
t = Symbol('t')
Vout = 1/(Ri*C)*integrate(sin(2*pi*5000*t))

#Result
print "Vout = ",Vout
#Answer varies due to use of Sympy library

Vout =  -1.0*cos(10000*pi*t)/pi


## Example 10.4, Page 359¶

In [3]:
import math

#Variable declaration
Rf=400000.;           #in Ohm

#Calculations&Results
flow=1./(2*math.pi*Rf*C);
print "Flow = %.1f Hz"%flow
Ri=15000;           #in Ohm
#integration
def integrand(t):
return .6
exact=-2.5432596188;
Vout=(-1.*I)/(Ri*C);
print "Vout(t) = %.1f V"%Vout;#Result

Flow = 19.9 Hz
Vout(t) = 2.0 V


## Example 10.5, Page 365¶

In [7]:
import numpy
import matplotlib.pyplot as plt
import math
from scipy.misc import derivative
%matplotlib inline

#Variable declaration
Ri=100;           #in Ohm
Rf=5000;           #in Ohm

#Calculations&Results
fhf=1/(2*math.pi*Rf*Cf);
fh_in=1/(2*math.pi*Ri*Ci);
print "Fhigh(f dbk)=%.0f Hz"%fhf;
print "Fhigh(in)=%.0f Hz"%fh_in;
#graph is drawn taking function sin(t)
t=numpy.linspace(0,15);
Vi=2*numpy.sin(2*t);
z = numpy.diff(-1.885*Vi)#,1.0,dx=1e-6)

plt.plot(2*Vi)
plt.plot(z)
plt.title("Partial Differentiator of sin(t)")
plt.xlabel("t")
plt.ylabel("V");
plt.grid();
plt.show()

Fhigh(f dbk)=318310 Hz
Fhigh(in)=159155 Hz


## Example 10.6, Page 368¶

In [8]:
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
from sympy import Symbol
from sympy.mpmath import diff
%matplotlib inline

#Variable declaration
f=4;            #in KHz
T=1./f;         # in uS
S=6./125*10**6;

#Calculations&Results
from sympy import Symbol
t = Symbol('t')
Vin = S*t
print "Vin(t) = ",Vin;
Rf=5000;           #in Ohm
dy = diff(lambda x:Vin*x,1.0)
Vout=-Rf*C*dy;
print "Vout = ",Vout,"V"

t=np.linspace(0,5*np.pi);
plt.plot(t,signal.square(3*t));
plt.title('Output Waveform')
plt.xlabel('t')
plt.ylabel('V')
plt.show()

Vin(t) =  48000.0*t
Vout =  -2.400000000000000115012166457262310359510593*t V


## Example 10.7, Page 370¶

In [5]:
import numpy
import matplotlib.pyplot as plt
from sympy.mpmath import diff

#Variable declaration
Rf=5000;           #in Ohm

#Calculations&Results
Vin = 5*10**6
from sympy import Symbol
t = Symbol('t')
print "Vin(t) = %.0f*t"%Vin;
dy = diff(lambda x:Vin*x,1.0)
Vout=-Rf*C*dy;
print "Vout = %.1f V"%Vout

Vin(t) = 5000000*t
Vout = -250.0 V


## Example 10.8, Page 370¶

In [6]:
import math
import numpy
from sympy.mpmath import diff

#Variable declaration
Ri=250;           #in Ohm
Rf=40000;           #in Ohm

#Calculations&Results
fhf=1/(2*math.pi*Rf*Cf);
fh_in=1/(2*math.pi*Ri*Ci);
print "Fhigh(f dbk)=%.0f Hz"%fhf;
print "Fhigh(in)=%.0f Hz"%fh_in;

S=10;           #in V/S
step=1;
print "For slope",S
Vin=10;
dy = diff(lambda t:Vin*t,1.0)
Vout=-Rf*Ci*dy;
print "Vout(t) = %.1f V"%Vout;
#
Slope=-4/0.2;           #in V/S
step=1;
print "\nFor slope",Slope
Vin=20;
dy = diff(lambda t:Vin*t,1.0)
Vout2=-Rf*Ci*dy;
print "Vout(t) = %.1f V"%Vout2;

Fhigh(f dbk)=1989 Hz
Fhigh(in)=1273 Hz
For slope 10
Vout(t) = -0.2 V

For slope -20.0
Vout(t) = -0.4 V