TExcelTAD
Home › Circuit Theory & Network Analysis › DC Sweeps, Sensitivity and Tolerance Analysis

DC Sweeps, Sensitivity and Tolerance Analysis

A divider that gives exactly 3.000 V3.000\ \text{V} on paper gives 2.99 V2.99\ \text{V} on one board and 3.02 V3.02\ \text{V} on the next, because real resistors are ±1 %\pm 1\,\% parts and the supply is only good to half a percent. If that voltage is an ADC reference, every reading inherits the error. The questions an engineer must answer are: how does the output depend on each part (sensitivity), how far can it go in the worst case, and how far does it go on a typical board (statistics). This lesson answers all three with ngspice sweeps and a few lines of NumPy, and links them back to the nodal solution you already know how to write.

The circuit

+ - V1 5 V +-0.5 % R1 10 kOhm 1 % R2 15 kOhm 1 % ADC REF input out 3.000 V nominal

The output is a plain divider (Voltage and Current Dividers):

Vout=V1R2R1+R2=5 V⋅1525=3.000 VV_\text{out} = V_1 \frac{R_2}{R_1 + R_2} = 5\ \text{V} \cdot \frac{15}{25} = 3.000\ \text{V}

DC sweeps

A DC sweep repeats the operating-point solution while one source or component steps through a range. In ngspice it is the dc command: dc V1 0 5 1 steps V1V_1 from 0 to 5 V in 1 V steps; dc R2 14.85k 15.15k 0.15k steps a resistor. The sweep shows linearity at a glance and is the first tool for "what if this part changes".

bash · try it yourself
cat > sweep.cir <<'EOF'
* ADC reference divider: sweep the supply, then R2 over its 1 % band
V1 in 0 DC 5
R1 in out 10k
R2 out 0 15k
.control
dc V1 0 5 1
print v(out)
dc R2 14.85k 15.15k 0.15k
print v(out)
.endc
.end
EOF
ngspice -b sweep.cir 2>&1 | awk '/^Index/ || /^[0-9]+\t/ {print $1, $2, $3}'
Index v-sweep v(out)
0 0.000000e+00 0.000000e+00
1 1.000000e+00 6.000000e-01
2 2.000000e+00 1.200000e+00
3 3.000000e+00 1.800000e+00
4 4.000000e+00 2.400000e+00
5 5.000000e+00 3.000000e+00
Index res-sweep v(out)
0 1.485000e+04 2.987928e+00
1 1.500000e+04 3.000000e+00
2 1.515000e+04 3.011928e+00

The supply sweep is a straight line of slope 0.60.6: a linear circuit. The resistor sweep moves the output by about ±12 mV\pm 12\ \text{mV} for ±1 %\pm 1\,\% in R2R_2, so R2R_2's tolerance alone is worth about ±0.4 %\pm 0.4\,\% of the output.

Sensitivity

The normalised sensitivity of an output yy to a parameter xx is the percentage change of yy per percentage change of xx:

Sxy=∂y/y∂x/x=xy∂y∂xS_x^y = \frac{\partial y / y}{\partial x / x} = \frac{x}{y} \frac{\partial y}{\partial x}

For the divider, differentiating Vout=V1R2/(R1+R2)V_\text{out} = V_1 R_2 / (R_1 + R_2):

SV1=1,SR2=R1R1+R2=0.4,SR1=−R1R1+R2=−0.4S_{V_1} = 1, \qquad S_{R_2} = \frac{R_1}{R_1 + R_2} = 0.4, \qquad S_{R_1} = -\frac{R_1}{R_1 + R_2} = -0.4

So 1 %1\,\% in R2R_2 moves the output by 0.4 %0.4\,\%, in agreement with the sweep (12 mV/3 V12\ \text{mV}/3\ \text{V}). Sensitivities tell you where to spend money: here a better supply matters more than better resistors. Note that SR1+SR2=0S_{R_1} + S_{R_2} = 0: scaling both resistors together changes nothing, which is why matched resistor networks (one package, tracking temperature coefficients) make excellent dividers.

Worst case and statistics

Worst-case analysis sets every parameter to the end of its tolerance band that pushes the output the same way. To first order the relative error is

Δyy∣wc=∑k∣Sk∣ tk=1⋅0.5 %+0.4⋅1 %+0.4⋅1 %=1.3 %\frac{\Delta y}{y}\bigg|_\text{wc} = \sum_k \lvert S_k \rvert\, t_k = 1 \cdot 0.5\,\% + 0.4 \cdot 1\,\% + 0.4 \cdot 1\,\% = 1.3\,\%

Statistical analysis assumes the errors are independent. If each part's error has standard deviation σk\sigma_k (a common assumption for a tolerance band is σ=t/3\sigma = t/3), the output's relative standard deviation is the root-sum-square

σyy=∑kSk2σk2=(0.5/3)2+2(0.4/3)2 %≈0.25 %\frac{\sigma_y}{y} = \sqrt{\sum_k S_k^2 \sigma_k^2} = \sqrt{(0.5/3)^2 + 2 (0.4/3)^2}\ \% \approx 0.25\,\%

and ±3σ≈±0.75 %\pm 3\sigma \approx \pm 0.75\,\% covers about 99.7 % of boards, versus ±1.3 %\pm 1.3\,\% for the worst case. Monte Carlo analysis checks this by simulating many random boards; it needs no linearisation, so it also works when sensitivities change across the band.

Worked example

Given: V1=5 V±0.5 %V_1 = 5\ \text{V} \pm 0.5\,\%, R1=10 kΩ±1 %R_1 = 10\ \text{k}\Omega \pm 1\,\%, R2=15 kΩ±1 %R_2 = 15\ \text{k}\Omega \pm 1\,\%.

Find: the worst-case range of VoutV_\text{out} exactly, and compare with the linear estimate.

Solve: the output is highest for high V1V_1, low R1R_1, high R2R_2:

Vmax=5.025 V⋅15.159.9+15.15=3.0391 V,Vmin=4.975 V⋅14.8510.1+14.85=2.9611 VV_\text{max} = 5.025\ \text{V} \cdot \frac{15.15}{9.9 + 15.15} = 3.0391\ \text{V}, \qquad V_\text{min} = 4.975\ \text{V} \cdot \frac{14.85}{10.1 + 14.85} = 2.9611\ \text{V}

Check: +1.30 %+1.30\,\% and −1.30 %-1.30\,\%, the linear estimate to three figures. The ngspice corner run below confirms both extremes.

bash · try it yourself
cat > corners.cir <<'EOF'
* Worst-case corners: V1 +-0.5 %, R1 and R2 +-1 %
V1 in 0 DC 5
R1 in out 10k
R2 out 0 15k
.control
foreach v 4.975 5.025
  foreach a 9.9k 10.1k
    foreach b 14.85k 15.15k
      alter V1 dc = $v
      alter R1 = $a
      alter R2 = $b
      op
      echo "V1=$v R1=$a R2=$b v(out)=
amp;v(out)" end end end .endc .end EOF ngspice -b corners.cir 2>&1 | grep '^V1='
V1=4.975 R1=9.9k R2=14.85k v(out)=2.985
V1=4.975 R1=9.9k R2=15.15k v(out)=3.00883
V1=4.975 R1=10.1k R2=14.85k v(out)=2.96107
V1=4.975 R1=10.1k R2=15.15k v(out)=2.985
V1=5.025 R1=9.9k R2=14.85k v(out)=3.015
V1=5.025 R1=9.9k R2=15.15k v(out)=3.03907
V1=5.025 R1=10.1k R2=14.85k v(out)=2.99083
V1=5.025 R1=10.1k R2=15.15k v(out)=3.015

alter changes a component between runs and foreach loops over values; the eight corners are every combination of the three tolerance ends. In a circuit where the sensitivities can change sign inside the band, the extremes need not be at the corners, and Monte Carlo is the safer check.

Sensitivity and Monte Carlo in Python

python · try it yourself
import numpy as np
import matplotlib.pyplot as plt

def vout(V1, R1, R2):
    return V1 * R2 / (R1 + R2)

nom = {"V1": 5.0, "R1": 10e3, "R2": 15e3}
tol = {"V1": 0.005, "R1": 0.01, "R2": 0.01}
y0 = vout(**nom)

# normalised sensitivities by a central difference of +-0.1 %
S = {}
for k in nom:
    up, dn = dict(nom), dict(nom)
    up[k] *= 1.001; dn[k] *= 0.999
    S[k] = (vout(**up) - vout(**dn)) / y0 / 0.002
    print(f"S_{k} = {S[k]:+.4f}")
wc = sum(abs(S[k]) * tol[k] for k in nom)
rss = np.sqrt(sum((S[k] * tol[k] / 3) ** 2 for k in nom))
print(f"linear worst case: +-{100 * wc:.3f} %, sigma (t/3 rule): {100 * rss:.3f} %")

rng = np.random.default_rng(2026)
n = 100_000
draw = {k: nom[k] * (1 + tol[k] / 3 * rng.standard_normal(n)) for k in nom}
y = vout(**draw)
print(f"Monte Carlo: mean {y.mean():.4f} V, sigma {1000 * y.std():.2f} mV ({100 * y.std() / y0:.3f} %)")
print(f"boards outside +-1 %: {100 * np.mean(np.abs(y / y0 - 1) > 0.01):.3f} %")

plt.hist(y, bins=80)
plt.axvline(y0 * (1 - wc), linestyle="--"); plt.axvline(y0 * (1 + wc), linestyle="--")
plt.xlabel("V_out (V)"); plt.ylabel("boards"); plt.title("100 000 random dividers; dashed: worst case")
plt.show()
S_V1 = +1.0000
S_R1 = -0.4000
S_R2 = +0.4000
linear worst case: +-1.300 %, sigma (t/3 rule): 0.252 %
Monte Carlo: mean 3.0000 V, sigma 7.55 mV (0.252 %)
boards outside +-1 %: 0.004 %

The histogram is a narrow bell well inside the worst-case lines. The Monte Carlo puts 4 boards in 100 000 outside ±1 %\pm 1\,\%. Whether that is good enough depends on how the parts are really distributed: tolerance bands are a manufacturer's guarantee, not a Gaussian, and parts sorted from a batch can sit near the band edges. Use the worst case for safety-relevant limits, statistics for yield estimates.

Interactive: the divider with a load

The ADC reference input is not infinite resistance. Add its input resistance as RLR_L in the netlist lab and sweep it: the loaded output drops, a systematic error that tolerance analysis of R1R_1 and R2R_2 alone never shows.

node voltages (to ground 0)in5.000 Vout2.982 VnetlistV1 in 0 DC 5R1 in out 10kR2 out 0 15kRL out 0 1megelement currents (node 1 to node 2 through it)V1in>0-202 uAR1in>out202 uAR2out>0199 uARLout>02.98 uA

With RL=1 MΩR_L = 1\ \text{M}\Omega the lab shows vout=2.982 Vv_\text{out} = 2.982\ \text{V}, already 0.6 %0.6\,\% low, almost half the worst-case budget; at RL=100 kΩR_L = 100\ \text{k}\Omega it falls to 2.830 V2.830\ \text{V}. A buffer or a stiffer divider fixes it.

Guided lab: measure a batch of dividers

Hand calculation. Nominal 3.000 V3.000\ \text{V}; worst case 2.9612.961 to 3.039 V3.039\ \text{V}; expected spread σ≈7.6 mV\sigma \approx 7.6\ \text{mV} if the parts behave like the t/3t/3 model.

Simulation. The two ngspice sessions and the Python Monte Carlo above.

What you would measure. Build five dividers from one bag of 10 kΩ10\ \text{k}\Omega and 15 kΩ15\ \text{k}\Omega 1 % resistors, all fed from one 5.000 V5.000\ \text{V} supply (20 mA limit). Measure V1V_1 at the board and each VoutV_\text{out} with a 5½-digit or a good 4½-digit DMM (±0.05 %\pm 0.05\,\% or so on the 10 V range). Report Vout/V1V_\text{out}/V_1 rather than VoutV_\text{out}, which removes the supply error: expect 0.60000.6000 within ±0.0048\pm 0.0048 (the ±0.8 %\pm 0.8\,\% resistor-only worst case), and usually within about ±0.002\pm 0.002. Also measure each resistor out of circuit and check that the computed ratio matches the in-circuit one.

Hazards and safe setup. 5 V, current-limited, 1 mW1\ \text{mW} in the resistors. Measure resistors out of circuit only with the supply off.

Pitfalls

  • Adding percentages as if errors were correlated gives the worst case, adding them in quadrature gives a statistical spread; say which one you quote.
  • Ignoring loading: the meter, the ADC and any next stage are resistors too.
  • Forgetting temperature: a 100 ppm/K resistor drifts 0.5 %0.5\,\% over 50 K50\ \text{K}, more than its tolerance at 25 ∘C25\,^\circ\text{C} would suggest; matched networks track.
  • Dates in SPICE output: ngspice prints a date and run statistics; filter them out (awk, grep) when you compare runs.
  • Monte Carlo without a seed is not reproducible; fix the seed in reports.

Practice

  1. Redesign the divider with R1=20 kΩR_1 = 20\ \text{k}\Omega and R2=30 kΩR_2 = 30\ \text{k}\Omega. What are the sensitivities now?
  2. Replace the 1 % resistors by 0.1 % parts. What is the linear worst case?
  3. A divider has SR2=0.9S_{R_2} = 0.9. What does that say about R1R_1 compared with R2R_2, and is such a divider sensitive to its resistors?
Answer
  1. Unchanged: SR2=R1/(R1+R2)=0.4S_{R_2} = R_1/(R_1 + R_2) = 0.4, SR1=−0.4S_{R_1} = -0.4, SV1=1S_{V_1} = 1. Only the ratio matters (the loading by RLR_L gets worse with larger values).
  2. 0.5+0.4⋅0.1+0.4⋅0.1=0.58 %0.5 + 0.4 \cdot 0.1 + 0.4 \cdot 0.1 = 0.58\,\%: the supply dominates.
  3. R1/(R1+R2)=0.9R_1/(R_1 + R_2) = 0.9, so R1=9R2R_1 = 9 R_2: a large division ratio (Vout=0.1V1V_\text{out} = 0.1 V_1). Each 1 % in a resistor moves the output 0.9 %, so high-ratio dividers need tighter resistors.

Test yourself

The normalised sensitivity Sxy=0.4S_x^y = 0.4 means…

  1. a 1 % increase of xx raises yy by about 0.4 %
  2. yy changes by 0.4 V per volt of xx
  3. xx has 0.4 % tolerance
  4. yy is 40 % of xx

Three independent errors contribute 0.5 %, 0.4 % and 0.4 % to an output. What are the worst-case and the root-sum-square values?

  1. 1.3 % and about 0.76 %
  2. 1.3 % and 1.3 %
  3. 0.5 % and 0.4 %
  4. 0.76 % and 1.3 %

Which ngspice command steps a resistor through a range of values and re-solves the operating point at each?

  1. tran R2 …
  2. dc R2 14.85k 15.15k 0.15k
  3. ac R2 …
  4. op R2

Why do SR1S_{R_1} and SR2S_{R_2} of a divider add to zero?

  1. because the supply is ideal
  2. because the output depends only on the ratio R2/R1R_2/R_1
  3. because both resistors have the same tolerance
  4. because the divider is unloaded