TExcelTAD
Home › Analog Electronics: Diodes, Transistors & Op-Amps › Integrators and Differentiators

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.

integrator with leak resistor differentiator with series Rs - + vin R 10 kOhm C 100 nF Rf 1 MOhm (leak) out - + vin Rs 1 kOhm C 10 nF R 10 kOhm out

The integrator

The inverting input is a virtual ground, so the input current is vin/Rv_\text{in}/R, and it all flows into the capacitor. The capacitor's voltage is 0−vout0 - v_\text{out}:

vinR=−Cdvoutdt⇒vout(t)=−1RC∫0tvin dτ+vout(0)\frac{v_\text{in}}{R} = -C\frac{dv_\text{out}}{dt} \quad\Rightarrow\quad v_\text{out}(t) = -\frac{1}{RC}\int_0^t v_\text{in}\,d\tau + v_\text{out}(0)

In the frequency domain the feedback impedance is 1/(jωC)1/(j\omega C), so

H(jω)=−1jωRC,∣H∣=fuf,fu=12πRCH(j\omega) = -\frac{1}{j\omega RC}, \qquad \lvert H \rvert = \frac{f_u}{f}, \quad f_u = \frac{1}{2\pi RC}

a −20 dB/decade-20\ \text{dB/decade} line through 0 dB0\ \text{dB} at the unity-gain frequency fuf_u, with a constant phase of +90∘+90^\circ (an inversion and a −90∘-90^\circ integration). A square wave of amplitude ±V\pm V and half-period T/2T/2 gives straight ramps of slope ∓V/(RC)\mp V/(RC), a triangle of peak-to-peak amplitude VT/(2RC)V T/(2RC).

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 RfR_f across CC. The circuit becomes an inverting first-order low-pass with DC gain −Rf/R-R_f/R and corner fL=1/(2πRfC)f_L = 1/(2\pi R_f C); above about 10fL10 f_L it integrates. The DC error is now the offset times 1+Rf/R1 + R_f/R, finite.
  • A reset switch across CC (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 CC at the input and RR in feedback, the input current is C dvin/dtC\,dv_\text{in}/dt:

vout=−RCdvindt,H(jω)=−jωRCv_\text{out} = -RC\frac{dv_\text{in}}{dt}, \qquad H(j\omega) = -j\omega RC

The gain rises at +20 dB/decade+20\ \text{dB/decade} without limit. That has two consequences. Noise and interference, which have the most energy at high frequency, are amplified most. And the feedback fraction β=1/(1+jωRC)\beta = 1/(1 + j\omega RC) 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

fring≈fT⋅12πRCf_\text{ring} \approx \sqrt{f_T \cdot \frac{1}{2\pi RC}}

where fTf_T is the op-amp's gain-bandwidth product. The cure is a small resistor RsR_s in series with CC: above 1/(2πRsC)1/(2\pi R_s C) the input looks resistive, the gain levels off at R/RsR/R_s, and the feedback zero restores the phase margin. A small capacitor across RR adds a further roll-off. A practical differentiator is a differentiator only below those corners.

Worked example

Given: an integrator with R=10 kΩR = 10\ \text{k}\Omega, C=100 nFC = 100\ \text{nF} and a leak Rf=1 MΩR_f = 1\ \text{M}\Omega, driven by a ±1 V\pm 1\ \text{V} square wave at 500 Hz500\ \text{Hz}; the op-amp has an input offset of 1 mV1\ \text{mV}.

Find: fuf_u, fLf_L, the triangle's amplitude, and the output offset with and without the leak resistor.

Solve:

RC=10 kΩ⋅100 nF=1 ms,fu=12π⋅1 ms=159 HzfL=12π⋅1 MΩ⋅100 nF=1.59 HzΔvout=VRC⋅T2=1 V1 ms⋅1 ms=1 Vpp(±0.5 V)Vout,offset=1 mV⋅(1+1 MΩ10 kΩ)=101 mV(with the leak)\begin{aligned} RC &= 10\ \text{k}\Omega \cdot 100\ \text{nF} = 1\ \text{ms}, \qquad f_u = \frac{1}{2\pi \cdot 1\ \text{ms}} = 159\ \text{Hz} \\ f_L &= \frac{1}{2\pi \cdot 1\ \text{M}\Omega \cdot 100\ \text{nF}} = 1.59\ \text{Hz} \\ \Delta v_\text{out} &= \frac{V}{RC}\cdot\frac{T}{2} = \frac{1\ \text{V}}{1\ \text{ms}} \cdot 1\ \text{ms} = 1\ \text{V}_\text{pp} \quad (\pm 0.5\ \text{V}) \\ V_\text{out,offset} &= 1\ \text{mV} \cdot \left(1 + \frac{1\ \text{M}\Omega}{10\ \text{k}\Omega}\right) = 101\ \text{mV} \quad \text{(with the leak)} \end{aligned}

Without the leak the offset ramps the output at 1 mV/1 ms=1 V/s1\ \text{mV}/1\ \text{ms} = 1\ \text{V/s} until it hits a rail.

Check: 500 Hz500\ \text{Hz} is more than 300300 times fLf_L, so the leak barely bends the ramps (the simulations below stay within about 1 % of ±0.5 V\pm 0.5\ \text{V}). The units of VT/(2RC)V T/(2RC) are V⋅s/s=V\text{V} \cdot \text{s}/\text{s} = \text{V}.

In Python: a lossy integrator and a ringing differentiator

python · try it yourself
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 0.999 Vpp0.999\ \text{V}_\text{pp}, centred within 2 mV2\ \text{mV} of zero. The plain differentiator has a closed-loop pole pair with Q≈25Q \approx 25 at the predicted frequency: any edge makes it ring for dozens of cycles. 1 kΩ1\ \text{k}\Omega in series with CC turns the pair into two real poles.

Cross-check with SPICE: taming the differentiator

Both differentiators get a 1 kHz1\ \text{kHz}, 2 Vpp2\ \text{V}_\text{pp} triangle, whose slope is ±4 V/ms\pm 4\ \text{V/ms}, so the ideal output is a square of ±RC⋅4 V/ms=±0.4 V\pm RC \cdot 4\ \text{V/ms} = \pm 0.4\ \text{V}. The op-amp is the macro-model written for this course (GBW=1 MHz\text{GBW} = 1\ \text{MHz}).

bash · try it yourself
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 1.10 V1.10\ \text{V}, almost three times the 0.4 V0.4\ \text{V} it should hold, and 0.4 ms0.4\ \text{ms} after the edge it still reads −0.31 V-0.31\ \text{V} instead of −0.40 V-0.40\ \text{V}. The version with RsR_s gives the clean ±0.400 V\pm 0.400\ \text{V} square.

Interactive: square in, triangle out

The integrator of the worked example, with the op-amp as E1 out 0 0 n 100k (gain 10510^5, no rails or bandwidth limit: ee-netlist has no op-amp element). The square starts at −1 V-1\ \text{V} for half a segment, so the triangle comes out centred from the first cycle.

-1010246810t (ms)VV(in)V(out)at t = 10.00 msV(in)-1.00 VV(n)3.57 nVV(out)-357 uVI(Vin)100 uAI(R1)-100 uAI(C1)-100 uAI(Rf)357 pAI(E1)-100 uA

At t=0.5 mst = 0.5\ \text{ms} the lab shows V(out)=498.7 mVV(\text{out}) = 498.7\ \text{mV} and at 1.5 ms1.5\ \text{ms} −491.3 mV-491.3\ \text{mV}; the leak's sag is the 11 to 2 %2\ \% shortfall from ±0.5 V\pm 0.5\ \text{V}. Halve R1R_1 and the triangle doubles.

Guided lab: triangle generator and differentiator

Hand calculation. Integrator as in the worked example: ±0.5 V\pm 0.5\ \text{V} triangle from a ±1 V\pm 1\ \text{V}, 500 Hz500\ \text{Hz} square. Differentiator (C=10 nFC = 10\ \text{nF}, R=10 kΩR = 10\ \text{k}\Omega, Rs=1 kΩR_s = 1\ \text{k}\Omega) on a 1 kHz1\ \text{kHz}, 2 Vpp2\ \text{V}_\text{pp} triangle: ±0.4 V\pm 0.4\ \text{V} square.

Simulation. The Python run, the SPICE deck and the lab.

What you would measure. General-purpose op-amp on a ±12 V\pm 12\ \text{V} current-limited split supply (50 mA50\ \text{mA} limit), 100 nF100\ \text{nF} decoupling, film capacitors (5 %), 1 % resistors. Integrator: expect a triangle of 1.0 Vpp±6 %1.0\ \text{V}_\text{pp} \pm 6\ \% (capacitor and resistor tolerance), centred within tens of millivolts of zero; remove RfR_f and watch the trace walk off to a rail within seconds. Differentiator: first without RsR_s (watch the ringing on each corner of the output square, near 40 kHz40\ \text{kHz} for a 1 MHz1\ \text{MHz} op-amp; faster op-amps ring faster), then with RsR_s. Measure the flat parts with the scope cursors: ±0.40 V±6 %\pm 0.40\ \text{V} \pm 6\ \%.

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 RfR_f 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 RsR_s and a feedback capacitor.
  • Forgetting the sign. Both basic circuits invert.

Practice

  1. Design an integrator with fu=1 kHzf_u = 1\ \text{kHz} and C=10 nFC = 10\ \text{nF}. What triangle amplitude does a ±2 V\pm 2\ \text{V}, 2 kHz2\ \text{kHz} square give?
  2. An integrator has R=100 kΩR = 100\ \text{k}\Omega, C=1 μFC = 1\ \mu\text{F} and no leak. The op-amp's input bias current of 50 nA50\ \text{nA} flows into the capacitor. How fast does the output drift?
  3. A differentiator uses R=100 kΩR = 100\ \text{k}\Omega, C=1 nFC = 1\ \text{nF} and a 10 MHz10\ \text{MHz} op-amp. Near what frequency does it ring?
Answer
  1. R=1/(2π⋅1 kHz⋅10 nF)=15.9 kΩR = 1/(2\pi \cdot 1\ \text{kHz} \cdot 10\ \text{nF}) = 15.9\ \text{k}\Omega (E24 16 kΩ16\ \text{k}\Omega, RC=160 μsRC = 160\ \mu\text{s}). Δv=2 V⋅250 μs/160 μs=3.1 Vpp\Delta v = 2\ \text{V} \cdot 250\ \mu\text{s}/160\ \mu\text{s} = 3.1\ \text{V}_\text{pp}.
  2. dv/dt=I/C=50 nA/1 μF=0.05 V/sdv/dt = I/C = 50\ \text{nA}/1\ \mu\text{F} = 0.05\ \text{V/s}: the rail is reached in a few minutes.
  3. fd=1/(2π⋅100 kΩ⋅1 nF)=1.59 kHzf_d = 1/(2\pi \cdot 100\ \text{k}\Omega \cdot 1\ \text{nF}) = 1.59\ \text{kHz}; 10 MHz⋅1.59 kHz=126 kHz\sqrt{10\ \text{MHz} \cdot 1.59\ \text{kHz}} = 126\ \text{kHz}.

Test yourself

An integrator has R=10 kΩR = 10\ \text{k}\Omega and C=100 nFC = 100\ \text{nF}. A constant input of +0.5 V+0.5\ \text{V} makes the output…

  1. rise at 500 V/s500\ \text{V/s}
  2. fall at 500 V/s500\ \text{V/s}
  3. fall at 5 V/s5\ \text{V/s}
  4. stay at −0.5 V-0.5\ \text{V}

Why does a practical integrator have a resistor across its capacitor?

  1. To raise its bandwidth
  2. To give finite DC gain so offsets and bias currents cannot drive it to a rail
  3. To make it non-inverting
  4. To protect the capacitor

The magnitude response of an ideal differentiator…

  1. falls at 20 dB/decade
  2. is flat
  3. rises at 20 dB/decade
  4. rises at 40 dB/decade

What does a small resistor in series with a differentiator's input capacitor do?

  1. It sets the DC gain
  2. It limits the high-frequency gain to R/RsR/R_s and adds a zero that restores phase margin, stopping the ringing
  3. It removes the inversion
  4. It increases the noise