AC Nodal and Mesh Analysis
A sensor interface has two sinusoidal sources at the same frequency, an excitation and a quadrature reference shifted by , feeding a small network of resistors, a capacitor and an inductor. You need the voltage at two internal nodes, amplitude and phase. In the time domain this is a set of coupled differential equations. In sinusoidal steady state it is the same linear system you solved in Node-Voltage Analysis and Mesh-Current Analysis, with complex numbers: replace every element by its impedance (Impedance and Admittance), every source by its phasor (Sinusoids and Phasors), and solve.
Why the DC methods carry over
Kirchhoff's laws hold at every instant. If every voltage and current is a sinusoid at one frequency , KCL at a node, , becomes for all , which forces . The same argument gives KVL for phasors. Together with for every element, the phasor circuit obeys exactly the rules of a resistive circuit; only the arithmetic is complex.
So the recipe is:
- Check that every source has the same frequency (otherwise use superposition, AC Thevenin, Norton and Superposition).
- Convert sources to phasors (one convention: here RMS) and elements to impedances at that .
- Write nodal equations () or mesh equations () by inspection, exactly as for DC.
- Solve with complex arithmetic, convert results to polar form, and if needed back to time functions.
The admittance matrix of a network of R, L and C (no dependent sources) is still symmetric; it is no longer positive definite, and at special frequencies it can become nearly singular, which is how resonance shows up in a matrix (Linear Systems).
Worked example: two sources, two methods
Given: the circuit above at (): , (RMS), , , , , .
Find: the node voltages and , by nodal analysis, then check by mesh analysis.
Solve (nodal). Impedances: , . In admittances, and . KCL at b and c (leaving = positive):
In matrix form, in mS and mA:
The diagonal entries are the sums of the admittances touching each node, the off-diagonal entries minus the admittance between them, as in the DC case. Solving (Cramer's rule by hand is tedious but possible; the script below does it) gives
Solve (mesh). With clockwise mesh currents, the mesh impedance matrix is again built by inspection: self-impedances on the diagonal, minus shared impedances off the diagonal. drives mesh 1 forward; mesh 3 enters at its + terminal, so appears with a minus sign:
which gives , , .
Check: and reproduce the nodal results. Note : the middle mesh carries more current than the source mesh, because the capacitor and the inductor partly cancel each other's reactance in it. Nodal analysis needed a system and mesh analysis a one, so nodal was the better choice here.
In Python
import numpy as np
def pol(z, unit="V"):
return f"{abs(z):7.4f} {unit} at {np.degrees(np.angle(z)):+8.3f} deg"
w = 2 * np.pi * 1e3
R1, R2, R3 = 100.0, 50.0, 100.0
ZC = 1 / (1j * w * 1e-6) # C1 = 1 uF
ZL = 1j * w * 10e-3 # L1 = 10 mH
V1 = 10.0 # rms phasor, 0 deg
V2 = 5.0 * np.exp(-1j * np.pi / 2) # rms phasor, -90 deg
# nodal: unknowns Vb, Vc (admittances in S)
Y = np.array([[1/R1 + 1/ZC + 1/ZL, -1/ZL],
[-1/ZL, 1/ZL + 1/R2 + 1/R3]])
i = np.array([V1 / R1, V2 / R3])
Vb, Vc = np.linalg.solve(Y, i)
print("nodal: Vb =", pol(Vb), "| Vc =", pol(Vc))
# mesh: three clockwise mesh currents (impedances in ohm)
Z = np.array([[R1 + ZC, -ZC, 0],
[-ZC, ZC + ZL + R2, -R2],
[0, -R2, R2 + R3]])
e = np.array([V1, 0, -V2])
I1, I2, I3 = np.linalg.solve(Z, e)
for k, I in enumerate((I1, I2, I3), 1):
print(f"mesh: I{k} =", pol(I * 1e3, "mA"))
print("mesh: Vb =", pol((I1 - I2) * ZC), "| Vc =", pol((I2 - I3) * R2))
print("methods agree:", np.allclose([Vb, Vc], [(I1 - I2) * ZC, (I2 - I3) * R2]))nodal: Vb = 4.5261 V at +12.417 deg | Vc = 3.5731 V at -54.720 deg
mesh: I1 = 56.6396 mA at -9.894 deg
mesh: I2 = 72.3862 mA at -31.207 deg
mesh: I3 = 29.3233 mA at +45.268 deg
mesh: Vb = 4.5261 V at +12.417 deg | Vc = 3.5731 V at -54.720 deg
methods agree: True
np.linalg.solve works on complex matrices with no change at all: the same call as in DC nodal analysis.
Cross-check with SPICE
ngspice's .ac analysis solves exactly this phasor problem. A sweep with one point (ac lin 1 1k 1k) gives the single-frequency answer; source lines take AC magnitude phase with the phase in degrees. vm() is the magnitude and vp() the phase, which ngspice reports in radians, so the deck converts it.
cat > acnodal.cir <<'EOF'
* AC nodal example at 1 kHz: two sources, R, C, L
V1 a 0 AC 10 0
R1 a b 100
C1 b 0 1u
L1 b c 10m
R2 c 0 50
R3 c d 100
V2 d 0 AC 5 -90
.control
ac lin 1 1k 1k
let phb = 180/pi*vp(b)
let phc = 180/pi*vp(c)
print vm(b) phb vm(c) phc
.endc
.end
EOF
ngspice -b acnodal.cir 2>&1 | grep -E '^(vm|phb|phc)'vm(b) = 4.526139e+00
phb = 1.241662e+01
vm(c) = 3.573095e+00
phc = -5.47197e+01
Four significant figures agree with NumPy. SPICE does not know whether you mean RMS or peak: the answer has whatever convention the source values have.
Interactive: the netlist lab
At the lab reads and ; , . Sweep : the reactances of and change in opposite directions, so both node voltages change in amplitude and phase. At every frequency the lab solves the same kind of complex nodal system, just with new matrix entries.
Guided lab: one source on the bench
Hand calculation. Two phase-locked generators are rare on a student bench, so build the network with switched off: connect 's free end to ground. Drive node a from one generator at , peak. The script with V1 = 5.0 and V2 = 0 gives and (peak values, since the source is given as a peak).
Simulation. In the deck set V1 a 0 AC 5 0 and V2 d 0 AC 0, and in the Python script V1 = 5.0 and V2 = 0: SPICE and Python must agree before you touch hardware.
What you would measure. Channel 1 on node a, channel 2 on b, then on c, all probe grounds on the circuit ground. Expect b at about peak, leading the source by ( earlier), and c at about peak, lagging by ( later). With 5 % capacitors and 10 % inductors (whose winding resistance, perhaps to , also adds in series with ) expect deviations of several percent in amplitude and a few degrees in phase; add the measured winding resistance to the model and the agreement should improve to the resistor tolerance.
Hazards and safe setup. Function generator only, peak. The highest current, in , is under peak; resistor dissipation stays below . All scope grounds on the same node, because they are tied together and to earth inside the scope.
Pitfalls
- Degrees in
np.exp. Phasor angles must be converted withnp.deg2radbefore use. - ngspice phases in radians.
vp()returns radians; convert, or usecph()and convert as well. - Mixed RMS and peak sources. Both sources in one circuit must use the same convention.
- Different-frequency sources cannot share one phasor solve.
- Forgetting that the matrix is complex. Building it with
np.zeros((2, 2))and then assigning complex entries silently drops the imaginary parts (NumPy warns and casts); start fromnp.zeros((2, 2), dtype=complex)or build it as above.
Practice
- Redo the nodal solution with (so goes to ground) and : what is ?
- In the mesh matrix, which entries change if is replaced by a capacitor?
- A circuit has 6 nodes (including ground), 8 branches and no current sources. How many equations does nodal analysis need, and how many does mesh analysis need (planar circuit)?
Answer
- Linearity: the bench result scaled by 2, (RMS if is RMS).
- Every entry containing : , , and ; becomes .
- Nodal: equations (fewer if voltage sources fix some nodes). Mesh: equations.
Test yourself
In AC nodal analysis, what is the off-diagonal entry when only an inductor joins nodes b and c?
Two sources in a circuit run at 1 kHz and 2 kHz. How do you find the steady-state response?
- one phasor solve with both sources
- solve at each frequency separately and add the time functions
- average the frequencies
- it cannot be found
ngspice prints vp(b) = 2.167e-01 after an AC analysis. What phase is that in degrees?
Why is the admittance matrix of an R, L, C network symmetric?
- because all impedances are real
- because each two-terminal element adds the same to both and
- because the frequency is fixed
- it is never symmetric