Sub topic 9
Difference amplifier
A difference amplifier subtracts one input voltage from another and scales the result. It uses one op amp and four resistors. This chapter derives its output equation, finds the resistor condition for a pure difference, and shows how resistor mismatch lets some common-mode signal through. It assumes you know the virtual short (the inverting and non-inverting inputs sit at the same voltage under negative feedback), the inverting and non-inverting gain formulas, voltage dividers, and superposition.
The circuit
The four resistors are connected as follows:
- V1 drives the inverting input through R1.
- Rf connects the output back to the inverting input.
- V2 drives the non-inverting input through R2.
- R3 connects the non-inverting input to ground.
Deriving the output
Two facts do all the work. The input pins draw no current, and negative feedback forces V- = V+.
- The non-inverting input is a plain voltage divider, because no current enters the pin: V+ = V2 · R3 / (R2 + R3).
- The virtual short gives V- = V+. Call this common voltage Vx.
- No current enters the inverting pin, so the current through R1 continues through Rf: (V1 − Vx) / R1 = (Vx − Vout) / Rf.
- Solve for Vout: Vout = Vx (1 + Rf/R1) − V1 (Rf/R1).
- Substitute Vx:
Vout = V2 · [R3 / (R2 + R3)] · (1 + Rf/R1) − V1 · (Rf/R1)
This is the general result. It holds for any resistor values, and it is the formula the difference_output function below implements.
Cross-check with superposition
The circuit is linear, so you can treat each source alone.
- With V2 = 0 (grounded), the non-inverting input is at 0 V. The circuit is an inverting amplifier for V1, so the contribution is −(Rf/R1) V1.
- With V1 = 0, the circuit is a non-inverting amplifier with gain (1 + Rf/R1). Its input is the divided voltage V2 · R3/(R2 + R3).
Adding the two contributions gives the same equation. If superposition and the node equation disagree on a problem, one of them has an algebra error.
The condition for a pure difference
The output is a true difference only if both inputs get the same gain magnitude. Let k = Rf/R1 and require R3/R2 = k. Then:
- R3 / (R2 + R3) = k / (1 + k)
- (k / (1 + k)) · (1 + k) = k
So Vout = k (V2 − V1). The condition is the matched ratio Rf/R1 = R3/R2. The usual design choice is R2 = R1 and R3 = Rf, which leaves one gain-setting ratio and keeps the two input paths identical.
| Design | Resistors | Result |
|---|---|---|
| Unity difference | R1 = R2 = Rf = R3 | Vout = V2 − V1 |
| Gain of 2 | R1 = R2 = 10 kΩ, Rf = R3 = 20 kΩ | Vout = 2 (V2 − V1) |
| Ratios mismatched | Rf/R1 ≠ R3/R2 | Vout contains a term in V1 + V2 |
When the ratios do not match, the output includes a common-mode term, covered below.
Checking the formula numerically
The Python function evaluates the general equation. The example uses R1 = R2 = 10 kΩ and Rf = R3 = 20 kΩ, so the gain is 2.
def difference_output(v1, v2, r1, rf, r2, r3):
"""Four-resistor difference amp.
V1 drives the inverting input through r1, rf is the feedback resistor,
V2 drives the non-inverting input through r2, r3 goes from that input to ground.
"""
return v2 * (r3 / (r2 + r3)) * (1 + rf / r1) - v1 * (rf / r1)
# Matched ratios: rf/r1 = r3/r2 = 2
print(difference_output(1.0, 3.0, 10e3, 20e3, 10e3, 20e3)) # about 4.0 = 2 * (3 - 1)You can confirm it in SPICE by modeling the op amp as a high-gain voltage-controlled voltage source (VCVS). The operating point should show V(out) just under 4 V, because the model gain is finite.
* Difference amplifier, ideal op amp modeled as a high-gain VCVS
V1 in1 0 DC 1
V2 in2 0 DC 3
R1 in1 inv 10k
Rf inv out 20k
R2 in2 non 10k
R3 non 0 20k
E1 out 0 non inv 100k
.op
.endCommon-mode rejection and resistor mismatch
Split the inputs into a differential part and a common-mode part:
- Vd = V2 − V1
- Vcm = (V1 + V2) / 2
Let Gp = [R3/(R2+R3)](1 + Rf/R1) be the gain from V2, and Gn = Rf/R1 the gain magnitude from V1. Writing V2 = Vcm + Vd/2 and V1 = Vcm − Vd/2 gives:
Vout = (Gp − Gn) · Vcm + [(Gp + Gn) / 2] · Vd
So the differential gain is Ad = (Gp + Gn)/2 and the common-mode gain is Acm = Gp − Gn. With matched ratios, Gp = Gn and Acm = 0. The common-mode rejection ratio is CMRR = |Ad / Acm|, usually quoted in decibels as 20 log10 of that ratio.
The next script computes these numbers for a gain-of-10 stage whose R3 is 1% low.
import math
def gains(r1, rf, r2, r3):
gp = (r3 / (r2 + r3)) * (1 + rf / r1) # gain from V2
gn = rf / r1 # gain magnitude from V1
return gp, gn
gp, gn = gains(10e3, 100e3, 10e3, 99e3) # R3 is 1% low
ad = (gp + gn) / 2
acm = gp - gn
print(round(ad, 4)) # about 9.9954
print(round(acm, 5)) # about -0.00917
print(round(20 * math.log10(abs(ad / acm)), 1)) # about 60.7 dBA single 1% error in R3 gives a CMRR near 61 dB. A 1 V common-mode signal appears at the output as about 9 mV of error, which a 1 mV differential signal cannot be separated from. The worst case with all four resistors at tolerance t is approximately CMRR ≈ (1 + k) / (4t). For k = 10 and 1% resistors that is 11 / 0.04 ≈ 275, or about 49 dB.
Practical gotchas
- Unequal input resistances. V1 sees R1, because the inverting node is a virtual short. V2 sees R2 + R3. Unless the design is symmetric, the two sources load differently.
- Source resistance breaks matching. A sensor with 500 Ω of output resistance adds to R1 or R2 on its side only. That shifts the ratio and degrades CMRR. Buffer high-impedance sources with voltage followers before the difference stage.
- Common-mode range. The op amp output must handle Gp · V2 − Gn · V1 at every moment. Large common-mode voltages can saturate it even if the difference is tiny. Check each node against the supply rails. For example, a 10 V common-mode signal at a gain of 10 asks for 100 V of swing if the ratios are even slightly off.
- Gain adjustment. Making only Rf variable changes Rf/R1 but not R3/R2, so it breaks the matching condition. Change Rf and R3 together, or use a dual-gang trimmer. Do not trim a single resistor to set gain.
- Finite op amp gain. A real AOL adds a small gain error of order (1 + k)/AOL. The SPICE result near 4 V rather than exactly 4 V comes from this effect.
Exercise
Design a difference amplifier with a gain of 4 using R1 = 10 kΩ. Choose R2, Rf, and R3. Then find Vout for V1 = 2.0 V and V2 = 2.5 V.
Show answer
Set Rf/R1 = 4, so Rf = 40 kΩ. Match the ratios with R2 = R1 = 10 kΩ and R3 = Rf = 40 kΩ, so R3/R2 = 4. Then Vout = 4 (V2 − V1) = 4 × 0.5 V = 2.0 V.
Exercise
A difference amplifier has R1 = R2 = 10 kΩ and Rf = R3 = 100 kΩ, except that R3 is actually 101 kΩ. Find the common-mode gain Acm, and say whether it is positive or negative.
Show answer
Gp = [101 / 111] × 11 = 10.00901, and Gn = 10. Acm = Gp − Gn ≈ +0.009, which is positive because R3 is high. A 1 V common-mode input produces about +9 mV at the output.