* PM_K-1 Stage 2 : DAC reconstruction filter (2nd-order Sallen-Key low-pass)
*
* The PCM5102A is a delta-sigma DAC: its analog output carries the audio plus
* shaped high-frequency quantization noise WAY above the audio band. A gentle
* low-pass cleans that residue before it reaches the pro output stage. We want it
* dead flat to 20 kHz and rolling off above ~80 kHz (Butterworth, Q~0.7).
*
* Unity-gain Sallen-Key, equal R. Target fc ~75 kHz with R=1.5k, C1=2.2n, C2=1n.
* Run:  ngspice -b ../eda/sim/stage2_recon.cir

.title Stage2 DAC reconstruction filter

.param R=1.5k
.param Ca=2.2n
.param Cb=1n

Vin in 0 AC 1
R1 in a   {R}
R2 a  vp  {R}
Ca a  out {Ca}      ; feedback cap
Cb vp 0   {Cb}      ; cap to ground
Eop out 0 vp out 1e6   ; unity-gain follower op-amp (-in tied to out)

.ac dec 100 100 2meg
.control
run
meas ac g_1k  find vdb(out) at=1k
meas ac g_20k find vdb(out) at=20k
meas ac f_3db when vdb(out)=-3
echo
echo "  passband @1kHz : $&g_1k dB"
echo "  @20kHz (audio edge) : $&g_20k dB   (want ~0 dB = flat)"
echo "  -3dB corner : $&f_3db Hz   (well above audio; attenuates DAC HF residue)"
wrdata ../eda/sim/plots/stage2_recon.data vdb(out)
.endc
.end
