Algorithmcore
Small-signal noise analysis
Also called AC noise analysis, adjoint noise analysis.
Sums the thermal, shot and flicker noise of every device at an output, using one adjoint solve per frequency as in Rohrer, Nagel, Meyer and Weber.
- Time
- O(D + F (S + K)) worst
- Space
- O(n^2 + K) extra
- Where
- D = the cost of the DC operating point; F = the number of frequency points; K = the number of noise sources; S = the cost of one sparse LU factorization and solve of the complex MNA matrix; n = the number of MNA unknowns
- Model
- Real RAM
- Properties
- deterministicexactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Ronald A. Rohrer, Laurence W. Nagel, Robert G. Meyer, L. Weber, 1971
Small-signal noise analysis computes the spectral density of the random noise at a circuit output: it linearizes the circuit at its DC operating point, gives every resistor, junction and transistor channel a noise current source, and adds the power that each source delivers to the output. It belongs to the circuit simulation half of the logic and circuit simulation sub-area. The key step, due to Rohrer, Nagel, Meyer and Weber (1971), is one solve with the transposed MNA matrix per frequency, which gives the transfer from every source to the output at once.
In plain words
Every resistor hisses, because the electrons in it move at random with the heat. Every diode crackles, because current crosses a junction in single charges. Transistors do both and also make a slow rumble that is strong at low frequencies. An amplifier amplifies all of these together with the signal, so its output is never perfectly clean.
The simulator wants to know how loud that hiss is at the output, frequency by frequency, and which device makes most of it. Each tiny noise source travels to the output through the circuit, which makes it louder or softer. The sources are independent, so their powers simply add. The trick is to find how strongly every source reaches the output with one calculation instead of one calculation per source: run the circuit backwards from the output once, and read off every answer.
The problem
The circuit is in modified nodal analysis form, , with . At the operating point the small-signal matrices are and , as in AC small-signal analysis, and at the frequency the complex MNA matrix is with .
Noise source is a current that leaves node and enters node , with a one-sided power spectral density in , computed from the operating point. The standard sources are:
| element | source | density |
|---|---|---|
| resistor | thermal | |
| junction with current | shot | |
| MOSFET in saturation | channel thermal | |
| MOSFET or junction | flicker |
Here is Boltzmann's constant, the temperature, the electron charge and the transconductance at the operating point. The thermal density is Nyquist's result. The factor is the long-channel value that ngspice uses in its level-1 MOSFET. The flicker coefficients and are fitted to measurements of each process and are not derived; and come from the geometry. The current and come from the device model, whose parameters are fitted too: for the Shichman-Hodges model of the example, , and .
Input: the circuit, an output vector (the output is , usually a node voltage) and the frequencies . Output: the output noise density in and the share of each source in it. The sources are assumed mutually uncorrelated.
The algorithm
NOISE(circuit, f_1..f_F, ℓ)- 1
x₀ ← the DC operating point; G ← ∂f/∂x and C ← ∂q/∂x at x₀ - 2
list the noise sources (p_k, q_k, S_k) with S_k evaluated at x₀ - 3
for i = 1, ..., F - 4
Yᵀ ← (G + j2πf_i C)ᵀ, factored by sparse complex LU - 5
solve Yᵀ z = ℓ ▷ the adjoint system, one solve - 6
for every source k: share_k ← |z_{q_k} − z_{p_k}|² S_k(f_i) - 7
S_out(f_i) ← Σ_k share_k - 8
return S_out(f_1..f_F) and the shares
The transfer from source to the output is , where is the KCL right side of a unit current from to . The direct method solves once per source. Line L5 instead solves once with , and then for every . The transpose is the plain transpose, not the conjugate transpose. In circuit terms is the matrix of the adjoint network, the circuit with every controlled source turned around, driven by a unit current at the output; this is the same transposed solve as in adjoint sensitivity analysis, and the factors of serve for it, .
The output noise is often referred to the input: divide by , the squared gain from the signal source to the output from an AC analysis. The total noise in a band is the integral of over the band, and its root is the RMS noise voltage.
Example
A divider. from a quiet source to the output and from the output to ground. Each resistor injects into the output node, whose impedance is , so : the thermal noise of the parallel resistance.
kT/C. Put a capacitor across the output of a resistor from a grounded source. The output impedance is , and the integral of over all is , whatever is. For 1 pF at 300 K that is 64.4 µV RMS.
The common-source amplifier. This is the amplifier of the AC analysis page: an n-channel MOSFET with , V and , its gate at a quiet 0.8 V source, kΩ to V, fF from the drain to ground and fF from the gate to the drain. The flicker parameters are and (fitted values), with . At the operating point A, S and S.
Three sources reach the drain through the same impedance , since the gate is held by an ideal source:
The white part is , so the channel makes 68.1% of the white noise and 31.9%. The flicker term equals the white part at the corner frequency kHz. The implementation gives:
| frequency | output (nV/√Hz) | referred to the input (nV/√Hz) | flicker share |
|---|---|---|---|
| 1 Hz | 16333 | 5222 | 1.000 |
| 100 Hz | 1634 | 522.4 | 0.999 |
| 10 kHz | 170.8 | 54.6 | 0.915 |
| 100 kHz | 71.76 | 22.94 | 0.518 |
| 1 MHz | 52.40 | 16.76 | 0.097 |
| 10 MHz | 47.66 | 16.01 | 0.011 |
| 100 MHz | 14.76 | 15.92 | 0.001 |
| 1 GHz | 1.543 | 14.30 | 0.000 |
The output falls above the 31.0 MHz pole. Referred to the input, the white floor is nV/√Hz; it falls at the highest frequencies because the gain there includes the feedthrough of . The white output noise integrated over all frequencies is 347.6 µV RMS, against 198.6 µV for alone: the transistor adds noise beyond that of a resistor.
Correctness
The proof in proofs/correctness.md shows that line L5 gives every transfer exactly, . For mutually uncorrelated sources the cross terms of the output autocorrelation vanish, so the output density is by the filter rule of the power spectral density and the Wiener-Khinchin theorem, which are cited. It also derives the kT/C integral. The source densities and the small-signal model are models, not theorems; the proof states where they enter.
The tests check, with measured tolerances:
- The divider against and each share against , to relative.
- The RC integral, by the midpoint rule with 64 points on , against for from 100 Ω to 1 MΩ, to relative. The substitution makes the integrand constant, so the rule is exact up to rounding and the test checks the density at every point.
- The amplifier against the formula above at 45 frequencies from 1 Hz to 100 GHz, to relative, and the flicker share at the corner, .
- A diode biased by a current from 1 µA to 1 mA against ; at 1 mA this is 0.463 nV/√Hz.
- 40 random networks (seed 81) of 3 to 7 nodes with resistors, capacitors, an inductor and controlled sources: the adjoint result matches the direct sum, one forward solve per source, within a relative difference of (measured worst case). Solving with in place of gives an error above 0.1% in 33 of the 40, because the controlled sources make unsymmetric.
Proof: One adjoint solve gives the output noise of every uncorrelated sourcefull
We use the notation of the page. The small-signal circuit at the operating point has the real matrices and , and at the frequency , with , its complex MNA matrix is , assumed nonsingular. Noise source is a current that leaves node and enters node (node 0 is ground). Its one-sided power spectral density is . The output is . The algorithm solves and returns
with .
Lemma 1 (the injection vector). A current that leaves node and enters node adds to the right side of the MNA equations, where (with ).
Proof. The node rows of MNA are KCL in the form "the sum of the currents that leave the node through the elements equals the current that the sources put into it". The source puts into node and takes from node , so it adds to row and to row . It adds no element current and no branch row.
Lemma 2 (the transfer of each source). The transfer function from to the output is .
Proof. With only source active at the phasor , the small-signal circuit is by Lemma 1, so the output phasor is , and . Since (the transpose, not the conjugate transpose),
So one solve with gives every , and the cost of each is one subtraction. This is the identity and nothing more. In circuit terms is the matrix of the adjoint network, which turns every controlled source around, and is the response of the adjoint network to a unit source at the output (see the adjoint sensitivity page and Tellegen's theorem); the proof above does not need that reading.
Lemma 3 (the sum of uncorrelated sources). Let be zero-mean, jointly wide-sense stationary processes, mutually uncorrelated, for , with spectral densities . Let for stable real impulse responses with frequency responses . Then .
Proof. The autocorrelation of is
The terms with vanish because the sources are uncorrelated. The term with is the autocorrelation of , so . The spectral density is the Fourier transform of the autocorrelation (the Wiener-Khinchin theorem), which is linear, so . Each term is by the filter rule of the power spectral density, which we cite.
The rule holds for one-sided densities as well as for two-sided ones, since both sides of the identity are even in and the one-sided density is twice the two-sided one at .
Theorem (correctness). If the noise sources are mutually uncorrelated, the value that the algorithm returns is the spectral density of the output noise of the small-signal circuit, and the share of source is .
Proof. The small-signal circuit is linear and time invariant, so the output noise is , where is the impulse response whose transform is the transfer of Lemma 2. Lemma 3 gives the sum, and Lemma 2 shows that the algorithm computes each exactly as .
What is not proved. Three steps are models, and the proof does not cover them.
- The source densities. for a resistor is Nyquist's result, for a junction is the shot-noise formula, for a long-channel MOSFET in saturation and for its flicker noise are device-model formulas with fitted and . They are cited on the page.
- The linearization. The noise is small, so the circuit is replaced by its small-signal model at , as in AC analysis. Noise that moves the operating point, or mixes with a large signal, is outside this model.
- Independence. Sources in different devices are uncorrelated by the physics of the model. Correlated sources, such as the induced gate noise and the channel noise of one transistor, need the cross spectrum, and the sum of Lemma 3 then gains the terms .
The kT/C result. For a resistor from a grounded source to a node with a capacitor to ground, for the resistor current injected into the node, so
with the substitution . The total does not depend on . The test on the page computes the integral from the densities that the algorithm returns.
Complexity
The operating point is computed once, at cost . Each frequency costs one factorization and one solve, , plus per source in lines L6 and L7, so the total is . The direct method costs , where is the cost of one extra solve with the factors, so it is slower by a factor that grows with . The implementation uses dense elimination; on an RC ladder its CPU time per frequency, measured with time.process_time, was 5.3 times less than the direct method's with 18 sources, 12 times less with 38 and 38 times less with 78. The extra space is the factors and one adjoint vector, plus the shares.
Properties
- One solve for all sources. The cost per frequency hardly depends on the number of noise sources.
- Exact for the linear model. Up to rounding, the result is the output density of the small-signal circuit with the given source densities.
- A breakdown by source. The shares come free and tell the designer which device to change.
- Powers add, not amplitudes. Uncorrelated sources add in . Two equal sources give times the noise voltage of one, not twice.
Variants and improvements
- Input-referred noise and noise figure. Divide by the squared gain from an AC analysis, or compare with the noise of the source resistance.
- Correlated sources. Two sources in one device with a cross spectrum add the terms ; the adjoint still gives every .
- Integrated noise. Integrate over a band, as in the kT/C example. A model reduced by Padé via Lanczos can give the transfer functions at many frequencies cheaply.
- Periodic and cyclostationary noise. Mixers and switched circuits are linearized around a periodic steady state from harmonic balance or shooting, and noise is folded between sidebands.
- Oscillator phase noise. In an oscillator the noise accumulates in the phase, which the small-signal model cannot describe; phase noise analysis treats it.
When to use it
Use noise analysis for the noise floor, input-referred noise, noise figure and signal-to-noise ratio of amplifiers, filters, references and receivers that work around a fixed bias point. Do not use it for oscillators, for circuits that switch, or for noise large enough to change the operating point; use phase noise analysis or a transient analysis with noise there.
Pitfalls
- The transpose, not the conjugate transpose. is complex symmetric for RLC circuits but not with controlled sources; solving with , or with , gives wrong transfers. The random test measures this.
- Fitted noise parameters. and are fitted per process, and the factor is the long-channel value. The flicker corner and the low-frequency noise are only as good as the fit.
- Noiseless sources. Ideal sources and controlled sources make no noise. A bias network built from them can hide noise that a real one would add.
- One-sided and two-sided densities. is one-sided, over . Mixing it with a two-sided density from another tool gives a factor of 2.
- The operating point. The densities and transfers depend on , like every small-signal result.
- Flicker at zero frequency. The density has no finite integral down to ; integrate from a stated low frequency.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/circuit-noise-analysis/. The authors are listed in prov/P2C0RA.jsonl.
"""Small-signal noise analysis with one adjoint solve per frequency.
The circuit is in MNA form f(x) + d/dt q(x) = u(t), x = (e_1..e_n, j_1..j_m),
node 0 is ground. Each noise source is a current between two nodes with a
one-sided power spectral density S(f) in A^2/Hz, computed at the DC operating
point. The output noise density at a frequency is sum_k |H_k|^2 S_k(f), where
H_k is the transfer from source k to the output; all H_k come from one solve
with the transposed matrix.
"""
import math
import sim3dense
BOLTZMANN = 1.380649e-23 # J/K, exact in the SI
CHARGE = 1.602176634e-19 # C, exact in the SI
class NoConvergence(RuntimeError):
pass
def _level1(k, vt, lam, vgs, vds):
"""Shichman-Hodges current for vds >= 0 and its partials (i, gds, gm)."""
vov = vgs - vt
if vov <= 0:
return 0.0, 0.0, 0.0
if vds < vov:
a = vov * vds - vds * vds / 2
return k * a * (1 + lam * vds), k * (vov - vds) * (1 + lam * vds) + k * a * lam, k * vds * (1 + lam * vds)
return k / 2 * vov * vov * (1 + lam * vds), k / 2 * vov * vov * lam, k * vov * (1 + lam * vds)
def mosfet_eval(kind, k, vt, lam, vd, vg, vs):
"""Current d -> s, its partials (gd, gg, gs) in (vd, vg, vs), and gm >= 0."""
if kind == "p":
i, gd, gg, gs, gm = mosfet_eval("n", k, vt, lam, -vd, -vg, -vs)
return -i, gd, gg, gs, gm
if vd < vs:
i, gd, gg, gs, gm = mosfet_eval("n", k, vt, lam, vs, vg, vd)
return -i, -gs, -gg, -gd, gm
i, gds, gm = _level1(k, vt, lam, vg - vs, vd - vs)
return i, gds, gm, -gds - gm, gm
class Netlist:
"""MNA netlist; the stamps follow the modified nodal analysis page."""
def __init__(self, nodes, temperature=300.0):
self.n, self.m, self.el = nodes, 0, []
self.kt = BOLTZMANN * temperature
@property
def size(self):
return self.n + self.m
def resistor(self, p, q, r, noisy=True):
self.el.append(("R", p, q, 1.0 / r, noisy))
def capacitor(self, p, q, c):
self.el.append(("C", p, q, c))
def inductor(self, p, q, l):
self.el.append(("L", p, q, l, self.m))
self.m += 1
def vsource(self, p, q, dc=0.0, ac=0.0):
self.el.append(("V", p, q, (dc, ac), self.m))
self.m += 1
def isource(self, p, q, dc=0.0, ac=0.0):
"""Moves its current out of p and into q. Noiseless."""
self.el.append(("I", p, q, (dc, ac)))
def vccs(self, p, q, c, d, g):
"""Current g (e_c - e_d) out of p and into q. Noiseless."""
self.el.append(("G", p, q, (c, d, g)))
def mosfet(self, kind, d, g, s, k, vt, lam, kf=0.0, af=1.0, cox_l2=1.0):
"""Level-1 MOSFET. k, vt, lam, kf and af are fitted; cox_l2 is Cox Leff^2."""
self.el.append(("M", d, g, s, (kind, k, vt, lam, kf, af, cox_l2)))
def diode(self, a, c, i_s, n=1.0, kf=0.0, af=1.0):
"""Junction diode from a to c; i_s, n, kf and af are fitted."""
self.el.append(("D", a, c, (i_s, n, kf, af)))
def _diode(self, v, i_s, n):
nvt = n * self.kt / CHARGE
vmax = 40 * nvt
if v <= vmax:
e = math.exp(v / nvt)
return i_s * (e - 1), i_s * e / nvt
e = math.exp(40.0)
return i_s * (e * (1 + (v - vmax) / nvt) - 1), i_s * e / nvt
def evaluate(self, x):
"""f(x), G = df/dx, q(x), C = dq/dx."""
N = self.size
f, q = [0.0] * N, [0.0] * N
G = [[0.0] * N for _ in range(N)]
C = [[0.0] * N for _ in range(N)]
def e(node):
return x[node - 1] if node else 0.0
def two(vec, mat, p, qn, cur, partials):
"""Current cur leaving p and entering qn, with partials {node: d cur}."""
for r, s in ((p, 1), (qn, -1)):
if r:
vec[r - 1] += s * cur
for node, d in partials:
if node:
mat[r - 1][node - 1] += s * d
for el in self.el:
kind = el[0]
if kind in "RC":
p, qn, val = el[1], el[2], el[3]
vec, mat = (f, G) if kind == "R" else (q, C)
two(vec, mat, p, qn, val * (e(p) - e(qn)), ((p, val), (qn, -val)))
elif kind in "LV":
p, qn, k = el[1], el[2], self.n + el[4]
for r, s in ((p, 1), (qn, -1)):
if r:
f[r - 1] += s * x[k]
G[r - 1][k] += s
G[k][r - 1] += s
f[k] += e(p) - e(qn)
if kind == "L":
q[k] -= el[3] * x[k]
C[k][k] -= el[3]
elif kind == "G":
p, qn, (c, d, g) = el[1], el[2], el[3]
two(f, G, p, qn, g * (e(c) - e(d)), ((c, g), (d, -g)))
elif kind == "M":
d, g, s, (mk, k, vt, lam, *_rest) = el[1], el[2], el[3], el[4]
i, gd, gg, gs, _ = mosfet_eval(mk, k, vt, lam, e(d), e(g), e(s))
two(f, G, d, s, i, ((d, gd), (g, gg), (s, gs)))
elif kind == "D":
a, c, (i_s, n, _, _) = el[1], el[2], el[3]
i, gdd = self._diode(e(a) - e(c), i_s, n)
two(f, G, a, c, i, ((a, gdd), (c, -gdd)))
return f, G, q, C
def sources(self, which):
u = [0.0] * self.size
for el in self.el:
if el[0] == "V":
u[self.n + el[4]] += el[3][which]
elif el[0] == "I":
if el[1]:
u[el[1] - 1] -= el[3][which]
if el[2]:
u[el[2] - 1] += el[3][which]
return u
def noise_sources(self, x0):
"""List of (name, p, q, S) with S a function of f in A^2/Hz (one-sided)."""
kt, out = self.kt, []
def e(node):
return x0[node - 1] if node else 0.0
for idx, el in enumerate(self.el):
if el[0] == "R" and el[4]:
g = el[3]
out.append((f"R{idx} thermal", el[1], el[2], lambda f, g=g: 4 * kt * g))
elif el[0] == "M":
d, g, s, (mk, k, vt, lam, kf, af, cox_l2) = el[1], el[2], el[3], el[4]
i, _, _, _, gm = mosfet_eval(mk, k, vt, lam, e(d), e(g), e(s))
out.append((f"M{idx} thermal", d, s, lambda f, gm=gm: 4 * kt * 2 / 3 * abs(gm)))
if kf:
out.append((f"M{idx} flicker", d, s,
lambda f, a=kf * abs(i) ** af / cox_l2: a / f))
elif el[0] == "D":
a, c, (i_s, n, kf, af) = el[1], el[2], el[3]
i, _ = self._diode(e(a) - e(c), i_s, n)
out.append((f"D{idx} shot", a, c, lambda f, i=i: 2 * CHARGE * abs(i)))
if kf:
out.append((f"D{idx} flicker", a, c, lambda f, b=kf * abs(i) ** af: b / f))
return out
def dc_operating_point(net, tol=1e-12, max_iter=200):
"""Newton on f(x) = u_DC, with node voltage steps limited to 0.1 V."""
x, u = [0.0] * net.size, net.sources(0)
for _ in range(max_iter):
f, G, _, _ = net.evaluate(x)
dx = sim3dense.solve(G, [a - b for a, b in zip(u, f)])
big = max([abs(d) for d in dx[: net.n]] + [0.0])
scale = min(1.0, 0.1 / big) if big > 0 else 1.0
x = [a + scale * d for a, d in zip(x, dx)]
if scale == 1.0 and max(abs(d) for d in dx) <= tol * (1 + max(abs(v) for v in x)):
return x
raise NoConvergence("DC operating point")
def _injection(net, p, q):
"""KCL right side of a unit current out of p and into q."""
a = [0.0] * net.size
if p:
a[p - 1] -= 1.0
if q:
a[q - 1] += 1.0
return a
def noise_analysis(net, freqs, out):
"""Output noise density (V^2/Hz for a voltage output) at each frequency in Hz.
Returns (x0, totals, contributions) where contributions[i] maps each
source name to its share of totals[i].
"""
x0 = dc_operating_point(net) # @line L1
_, G, _, C = net.evaluate(x0)
srcs = net.noise_sources(x0) # @line L2
totals, parts = [], []
for fr in freqs: # @line L3
w = 2 * math.pi * fr
yt = [[complex(G[j][i], w * C[j][i]) for j in range(net.size)] for i in range(net.size)] # @line L4
z = sim3dense.solve(yt, [complex(o) for o in out]) # @line L5
share = {}
for name, p, q, s in srcs: # @line L6
h = (z[q - 1] if q else 0) - (z[p - 1] if p else 0)
share[name] = abs(h) ** 2 * s(fr)
totals.append(sum(share.values())) # @line L7
parts.append(share)
return x0, totals, parts # @line L8
def noise_direct(net, freqs, out):
"""Reference: one forward solve per noise source and frequency, then the sum."""
x0 = dc_operating_point(net)
_, G, _, C = net.evaluate(x0)
srcs = net.noise_sources(x0)
totals = []
for fr in freqs:
w = 2 * math.pi * fr
y = [[complex(G[i][j], w * C[i][j]) for j in range(net.size)] for i in range(net.size)]
tot = 0.0
for _, p, q, s in srcs:
xk = sim3dense.solve(y, [complex(v) for v in _injection(net, p, q)])
tot += abs(sum(o * v for o, v in zip(out, xk))) ** 2 * s(fr)
totals.append(tot)
return totals
def transfer(net, freqs, out):
"""AC transfer from the AC sources to the output (for input-referred noise)."""
x0 = dc_operating_point(net)
_, G, _, C = net.evaluate(x0)
b = net.sources(1)
res = []
for fr in freqs:
w = 2 * math.pi * fr
y = [[complex(G[i][j], w * C[i][j]) for j in range(net.size)] for i in range(net.size)]
xk = sim3dense.solve(y, [complex(v) for v in b])
res.append(sum(o * v for o, v in zip(out, xk)))
return res
def unit(net, node):
v = [0.0] * net.size
v[node - 1] = 1.0
return v
sim3dense.py 70 lines
# SPDX-License-Identifier: MIT
# Shared helper of the sim3 eda pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Small dense linear algebra for Fraction, float or complex entries.
The circuit pages of group sim3 use this module as a reference solver and for
the small dense systems inside their tests. It holds no sparse method and no
circuit method. Matrices are lists of rows.
"""
from fractions import Fraction
class SingularMatrixError(ValueError):
"""The matrix has no inverse (a zero pivot in exact arithmetic)."""
def _exact(x):
return Fraction(x) if isinstance(x, int) else x
def solve(a, b, tol=0.0):
"""Solve a x = b by Gaussian elimination with partial pivoting.
With Fraction entries the result is exact. b is a vector or a matrix
(a list of rows); the result has the same shape.
"""
n = len(a)
m = [[_exact(x) for x in row] for row in a]
vec = not (b and isinstance(b[0], list))
rhs = [[_exact(x)] for x in b] if vec else [[_exact(x) for x in row] for row in b]
for k in range(n):
p = max(range(k, n), key=lambda i: abs(m[i][k]))
if abs(m[p][k]) <= tol:
raise SingularMatrixError(f"zero pivot in column {k}")
m[k], m[p] = m[p], m[k]
rhs[k], rhs[p] = rhs[p], rhs[k]
for i in range(k + 1, n):
if m[i][k] != 0:
f = m[i][k] / m[k][k]
for j in range(k, n):
m[i][j] -= f * m[k][j]
for j in range(len(rhs[i])):
rhs[i][j] -= f * rhs[k][j]
x = [[0] * len(rhs[0]) for _ in range(n)]
for i in range(n - 1, -1, -1):
for j in range(len(rhs[0])):
s = rhs[i][j] - sum(m[i][k] * x[k][j] for k in range(i + 1, n))
x[i][j] = s / m[i][i]
return [r[0] for r in x] if vec else x
def transpose(a):
return [list(r) for r in zip(*a)]
def matvec(a, x):
return [sum(aij * xj for aij, xj in zip(row, x)) for row in a]
def matmul(a, b):
bt = transpose(b)
return [[sum(x * y for x, y in zip(row, col)) for col in bt] for row in a]
def identity(n, one=1):
return [[one if i == j else 0 * one for j in range(n)] for i in range(n)]
def inverse(a):
return solve(a, identity(len(a)))
test_circuit_noise_analysis.py 150 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/circuit-noise-analysis/. The authors are listed in prov/P2C0RA.jsonl.
import math
import random
import sim3dense
from circuit_noise_analysis import (
BOLTZMANN,
CHARGE,
Netlist,
noise_analysis,
noise_direct,
transfer,
unit,
)
KT = BOLTZMANN * 300.0
# Level-1 MOSFET: K, VT and LAM are fitted model parameters, and so are the
# flicker coefficients KF and AF. COX_L2 = Cox Leff^2 for Cox = 8.6 mF/m^2 and
# Leff = 1 um is a geometry value. These are typical teaching values.
K, VT, LAM = 200e-6, 0.5, 0.05
KF, AF, COX_L2 = 1e-28, 1.0, 8.6e-15
VDD, RD, CL, CGD, VG = 1.8, 50e3, 100e-15, 5e-15, 0.8
def cs_amp(kf=KF):
net = Netlist(3) # node 1 supply, 2 drain (output), 3 gate (input)
net.vsource(1, 0, VDD)
net.vsource(3, 0, VG, 1.0)
net.resistor(1, 2, RD)
net.mosfet("n", 2, 3, 0, K, VT, LAM, kf, AF, COX_L2)
net.capacitor(3, 2, CGD)
net.capacitor(2, 0, CL)
return net
def test_divider_is_the_thermal_noise_of_the_parallel_resistance():
for r1, r2 in ((1e3, 1e3), (1e3, 3e3), (47e3, 2.2e3)):
net = Netlist(2)
net.vsource(1, 0, 1.0)
net.resistor(1, 2, r1)
net.resistor(2, 0, r2)
_, (s,), (share,) = noise_analysis(net, [1e3], unit(net, 2))
rp = r1 * r2 / (r1 + r2)
assert abs(s - 4 * KT * rp) < 1e-12 * s
# each resistor contributes 4kT/R_i times (R1 || R2)^2
assert abs(share["R1 thermal"] - 4 * KT / r1 * rp * rp) < 1e-12 * s
assert abs(share["R2 thermal"] - 4 * KT / r2 * rp * rp) < 1e-12 * s
def test_rc_total_noise_is_kt_over_c_for_every_r():
c = 1e-12
for r in (1e2, 1e4, 1e6):
net = Netlist(2)
net.vsource(1, 0, 0.0)
net.resistor(1, 2, r)
net.capacitor(2, 0, c)
fc = 1 / (2 * math.pi * r * c)
# f = fc tan(theta) maps [0, inf) onto [0, pi/2); midpoint rule
m = 64
thetas = [(i + 0.5) * (math.pi / 2) / m for i in range(m)]
_, dens, _ = noise_analysis(net, [fc * math.tan(t) for t in thetas], unit(net, 2))
total = sum(s * fc / math.cos(t) ** 2 for s, t in zip(dens, thetas)) * (math.pi / 2) / m
assert abs(total - KT / c) < 1e-9 * KT / c
def test_common_source_amplifier_against_hand_analysis():
net = cs_amp()
fs = [10 ** (k / 4) for k in range(0, 45)]
x0, dens, parts = noise_analysis(net, fs, unit(net, 2))
vov = VG - VT
a = K / 2 * vov**2 * RD
vds = (VDD - a) / (1 + a * LAM)
assert abs(x0[1] - vds) < 1e-12
gm = K * vov * (1 + LAM * vds)
gds = K / 2 * vov**2 * LAM
idd = K / 2 * vov**2 * (1 + LAM * vds)
white = 4 * KT / RD + 8 / 3 * KT * gm
for f, s in zip(fs, dens):
w = 2 * math.pi * f
z2 = 1 / abs(1 / RD + gds + 1j * w * (CL + CGD)) ** 2
hand = (white + KF * idd ** AF / (f * COX_L2)) * z2
assert abs(s - hand) < 1e-12 * hand
# at the flicker corner the flicker share is one half of the device noise
corner = KF * idd / (COX_L2 * white)
_, (s,), (share,) = noise_analysis(net, [corner], unit(net, 2))
assert abs(share["M3 flicker"] / s - 0.5) < 1e-12
# input-referred white noise is the output noise over the gain squared
_, (s,), _ = noise_analysis(cs_amp(0.0), [1e3], unit(net, 2))
(h,) = transfer(cs_amp(0.0), [1e3], unit(net, 2))
assert abs(s / abs(h) ** 2 - white / gm**2) < 1e-6 * white / gm**2
def test_diode_shot_noise():
for ib in (1e-6, 1e-4, 1e-3):
net = Netlist(1)
net.isource(0, 1, ib) # bias current into the anode
net.diode(1, 0, 1e-14) # the saturation current is a fitted value
x0, (s,), _ = noise_analysis(net, [1e4], unit(net, 1))
nvt = KT / CHARGE
gd = 1e-14 * math.exp(x0[0] / nvt) / nvt
assert abs(s - 2 * CHARGE * ib / gd**2) < 1e-9 * s
# gd is close to ib / VT, so the density is close to 2 q VT^2 / ib
assert abs(s / (2 * CHARGE * nvt**2 / ib) - 1) < 1e-7
def random_network(rng, n):
net = Netlist(n)
for _ in range(2 * n):
p, q = rng.sample(range(n + 1), 2)
net.resistor(p, q, rng.uniform(0.5, 10))
net.capacitor(p, q, rng.uniform(0.1, 2))
for i in range(1, n + 1):
net.resistor(i, 0, 20.0)
for _ in range(n):
p, q, c, d = rng.sample(range(n + 1), 4)
net.vccs(p, q, c, d, rng.uniform(-1.0, 1.0))
p, q = rng.sample(range(1, n + 1), 2)
net.inductor(p, q, rng.uniform(0.1, 2))
net.vsource(1, 0, 0.0)
return net
def test_adjoint_equals_direct_summation_on_random_networks():
rng = random.Random(81)
wrong = 0
for _ in range(40):
n = rng.randint(3, 7)
net = random_network(rng, n)
out = [0.0] * net.size
out[rng.randrange(1, n)] = 1.0
fs = [rng.uniform(0.001, 1.0) for _ in range(3)]
_, adj, _ = noise_analysis(net, fs, out)
ref = noise_direct(net, fs, out)
for a, b in zip(adj, ref):
assert abs(a - b) <= 1e-10 * b
# solving with Y instead of its transpose gives wrong gains when Y is not symmetric
_, G, _, C = net.evaluate([0.0] * net.size)
w = 2 * math.pi * fs[0]
y = [[complex(G[i][j], w * C[i][j]) for j in range(net.size)] for i in range(net.size)]
z = sim3dense.solve(y, [complex(o) for o in out])
bad = 0.0
for _, p, q, s in net.noise_sources([0.0] * net.size):
h = (z[q - 1] if q else 0) - (z[p - 1] if p else 0)
bad += abs(h) ** 2 * s(fs[0])
if abs(bad - ref[0]) > 1e-3 * ref[0]:
wrong += 1
assert wrong >= 30
History
Johnson measured the thermal noise of resistors in 1928, and Nyquist derived its density from thermodynamics in the same issue of the Physical Review. Rohrer, Nagel, Meyer and Weber (1971) gave the method of this page: one analysis of the interreciprocal adjoint network yields the transfer from every uncorrelated noise source to the output, so the work no longer grows with the number of sources. SPICE2 (Nagel, 1975) included a noise analysis, and the ngspice simulator still solves the AC system and then the adjoint system once per frequency and sums the contribution of every generator.
References
- Ronald Rohrer, Laurence Nagel, Robert Meyer and L. Weber, Computationally efficient electronic-circuit noise calculations, IEEE Journal of Solid-State Circuits 6(4), 204 to 213, 1971, the interreciprocal adjoint network, which gives the transfer from every noise source to the output with one analysis
- H. Nyquist, Thermal agitation of electric charge in conductors, Physical Review 32(1), 110 to 113, 1928, the thermal noise of a resistor from thermodynamics, the density 4kTR for the voltage
- J. B. Johnson, Thermal agitation of electricity in conductors, Physical Review 32(1), 97 to 109, 1928, the measurement of the thermal noise of resistors
- ngspice source code, src/spicelib/analysis/nevalsrc.c, the function NevalSrc, which multiplies 2 q |I| (shot noise) or 4 k T G (thermal noise) by the squared magnitude of the adjoint voltage across the source
- ngspice source code, src/spicelib/devices/mos1/mos1noi.c, the channel thermal noise 4 k T (2/3) |gm| and the flicker noise KF |Id|^AF / (f Cox Leff^2) of the level-1 MOSFET
- ngspice source code, src/spicelib/analysis/noisean.c, the frequency loop, which solves the AC system and then the adjoint system once per frequency and sums the contributions of every generator
- Laurence W. Nagel, SPICE2, A Computer Program to Simulate Semiconductor Circuits, Memorandum UCB/ERL M520, University of California, Berkeley, May 1975, the noise analysis of SPICE2; the section was not checked
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag P2C0RA Edit this page History Report an error Markdown