Integrators and Differentiators
Put a capacitor where the feedback resistor of an inverting amplifier was, and the circuit integrates: a constant input becomes a ramp, a square wave becomes a triangle. Integrators are inside function generators, dual-slope ADCs, charge amplifiers for piezo sensors and the "I" of every analog PI controller. Swap the resistor and the capacitor and you get a differentiator, which turns a ramp into a step. Both are a two-line derivation with the golden rules, and both misbehave in a real circuit in instructive ways: the ideal integrator has infinite DC gain and drifts into a rail, and the ideal differentiator rings or oscillates. This lesson derives them, then fixes them.
The integrator
The inverting input is a virtual ground, so the input current is , and it all flows into the capacitor. The capacitor's voltage is :
In the frequency domain the feedback impedance is , so
a line through at the unity-gain frequency , with a constant phase of (an inversion and a integration). A square wave of amplitude and half-period gives straight ramps of slope , a triangle of peak-to-peak amplitude .
Why the ideal integrator fails, and the leak resistor
At DC the capacitor is open and the op-amp runs open-loop. Any DC at the input, including the op-amp's own offset voltage and bias current (Real Op-Amps: DC Errors), is integrated for ever, and within seconds the output sits at a rail. Two cures:
- A leak resistor across . The circuit becomes an inverting first-order low-pass with DC gain and corner ; above about it integrates. The DC error is now the offset times , finite.
- A reset switch across (a MOSFET or a relay) that zeroes the integrator before each measurement, as in a dual-slope ADC or a sample-and-integrate front end.
The differentiator
With at the input and in feedback, the input current is :
The gain rises at without limit. That has two consequences. Noise and interference, which have the most energy at high frequency, are amplified most. And the feedback fraction falls with frequency exactly where the op-amp's own gain falls, so the loop gain has two poles close together and a phase margin near zero (Stability and Compensation). The closed-loop response peaks sharply near
where is the op-amp's gain-bandwidth product. The cure is a small resistor in series with : above the input looks resistive, the gain levels off at , and the feedback zero restores the phase margin. A small capacitor across adds a further roll-off. A practical differentiator is a differentiator only below those corners.
Worked example
Given: an integrator with , and a leak , driven by a square wave at ; the op-amp has an input offset of .
Find: , , the triangle's amplitude, and the output offset with and without the leak resistor.
Solve:
Without the leak the offset ramps the output at until it hits a rail.
Check: is more than times , so the leak barely bends the ramps (the simulations below stay within about 1 % of ). The units of are .
In Python: a lossy integrator and a ringing differentiator
import numpy as np
from scipy import signal
R, C, Rf = 10e3, 100e-9, 1e6
H = signal.TransferFunction([-Rf / R], [Rf * C, 1])
t = np.linspace(0, 0.6, 600001)
u = np.where(((t - 0.5e-3) % 2e-3 < 1e-3) & (t >= 0.5e-3), 1.0, -1.0)
_, y, _ = signal.lsim(H, u, t)
last = t > 0.598
print(f"after 0.6 s: triangle from {y[last].min():.4f} V to {y[last].max():.4f} V")
# differentiator: loop A(s) * beta(s) with a 1 MHz GBW single-pole op-amp
A0, wp, Rd, Cd = 1e5, 2 * np.pi * 10, 10e3, 10e-9
for Rs in [0.0, 1e3]:
den = np.polyadd(np.polymul([1 / wp, 1], [(Rd + Rs) * Cd, 1]),
A0 * np.array([Rs * Cd, 1]))
p = np.roots(den)
if abs(p[0].imag) > 0:
q = abs(p[0]) / (-2 * p[0].real)
print(f"Rs = {Rs:6.0f} Ohm: complex poles at {abs(p[0])/2/np.pi/1e3:.1f} kHz, Q = {q:.1f}")
else:
print(f"Rs = {Rs:6.0f} Ohm: real poles at {np.sort(-p.real)[0]/2/np.pi/1e3:.1f} and "
f"{np.sort(-p.real)[1]/2/np.pi/1e3:.1f} kHz, no ringing")
print(f"estimate sqrt(fT * fd) = {np.sqrt(1e6 / (2*np.pi*Rd*Cd))/1e3:.1f} kHz")after 0.6 s: triangle from -0.5013 V to 0.4977 V
Rs = 0 Ohm: complex poles at 39.9 kHz, Q = 24.9
Rs = 1000 Ohm: real poles at 20.0 and 72.4 kHz, no ringing
estimate sqrt(fT * fd) = 39.9 kHz
In steady state the leaky integrator's triangle is , centred within of zero. The plain differentiator has a closed-loop pole pair with at the predicted frequency: any edge makes it ring for dozens of cycles. in series with turns the pair into two real poles.
Cross-check with SPICE: taming the differentiator
Both differentiators get a , triangle, whose slope is , so the ideal output is a square of . The op-amp is the macro-model written for this course ().
cat > dif.cir <<'EOF'
* differentiators driven by a 1 kHz, 2 Vpp triangle
.subckt OA inp inn out
G1 0 n1 inp inn 1m
R1 n1 0 100meg
C1 n1 0 159.2p
E1 out 0 n1 0 1
.ends
Vin in 0 PULSE(-1 1 0 0.5m 0.5m 1n 1m)
* plain: C into the virtual ground, R feedback
C1 in n1 10n
R1 n1 o1 10k
X1 0 n1 o1 OA
* stabilised: 1k in series with C
Rs in m 1k
C2 m n2 10n
R2 n2 o2 10k
X2 0 n2 o2 OA
.control
tran 0.2u 3m
meas tran pk1 max v(o1) from=1m to=3m
meas tran pk2 max v(o2) from=1m to=3m
meas tran flat1 find v(o1) at=1.4m
meas tran flat2 find v(o2) at=1.4m
.endc
.end
EOF
ngspice -b dif.cir 2>&1 | grep -E '^(pk|flat)'pk1 = 1.098987e+00 at= 1.512329e-03
pk2 = 3.999968e-01 at= 3.000000e-03
flat1 = -3.053591e-01
flat2 = -3.999960e-01
The plain differentiator overshoots to , almost three times the it should hold, and after the edge it still reads instead of . The version with gives the clean square.
Interactive: square in, triangle out
The integrator of the worked example, with the op-amp as E1 out 0 0 n 100k (gain , no rails or bandwidth limit: ee-netlist has no op-amp element). The square starts at for half a segment, so the triangle comes out centred from the first cycle.
At the lab shows and at ; the leak's sag is the to shortfall from . Halve and the triangle doubles.
Guided lab: triangle generator and differentiator
Hand calculation. Integrator as in the worked example: triangle from a , square. Differentiator (, , ) on a , triangle: square.
Simulation. The Python run, the SPICE deck and the lab.
What you would measure. General-purpose op-amp on a current-limited split supply ( limit), decoupling, film capacitors (5 %), 1 % resistors. Integrator: expect a triangle of (capacitor and resistor tolerance), centred within tens of millivolts of zero; remove and watch the trace walk off to a rail within seconds. Differentiator: first without (watch the ringing on each corner of the output square, near for a op-amp; faster op-amps ring faster), then with . Measure the flat parts with the scope cursors: .
Hazards and safe setup. Low-voltage current-limited supply only; keep the generator output within the rails; switch the supply on before the generator.
Pitfalls
- Building an integrator with no DC feedback. It saturates from its own offset; add or a reset.
- Electrolytic capacitors in the feedback path. They leak, drift and are polarised; use film (C0G ceramic for small values).
- Differentiating noisy signals. Gain proportional to frequency turns small high-frequency noise into large spikes. Limit the band with and a feedback capacitor.
- Forgetting the sign. Both basic circuits invert.
Practice
- Design an integrator with and . What triangle amplitude does a , square give?
- An integrator has , and no leak. The op-amp's input bias current of flows into the capacitor. How fast does the output drift?
- A differentiator uses , and a op-amp. Near what frequency does it ring?
Answer
- (E24 , ). .
- : the rail is reached in a few minutes.
- ; .
Test yourself
An integrator has and . A constant input of makes the output…
- rise at
- fall at
- fall at
- stay at
Why does a practical integrator have a resistor across its capacitor?
- To raise its bandwidth
- To give finite DC gain so offsets and bias currents cannot drive it to a rail
- To make it non-inverting
- To protect the capacitor
The magnitude response of an ideal differentiator…
- falls at 20 dB/decade
- is flat
- rises at 20 dB/decade
- rises at 40 dB/decade
What does a small resistor in series with a differentiator's input capacitor do?
- It sets the DC gain
- It limits the high-frequency gain to and adds a zero that restores phase margin, stopping the ringing
- It removes the inversion
- It increases the noise