* PM_K-1 Stage 1b : Hi-Z instrument DI buffer -- gain + flatness check
*
* An OPA1641 (JFET input, ~1e12 ohm) as a non-inverting amp. The INPUT impedance
* the instrument sees is set by the bias resistor (1 Mohm) -- which the earlier
* input_loading.cir proved is what preserves a pickup's tone. Here we just confirm
* the voltage gain:  Av = 1 + Rf/Rg.  Target +12 dB (x4) with Rf=3k, Rg=1k.
*
* Run:  ngspice -b ../eda/sim/stage1b_di.cir

.title Stage1b DI buffer gain

Vin in 0 AC 1
Eop out 0 in vm 1e6     ; ideal op-amp: +IN = in, -IN = vm
Rf  out vm 3k           ; feedback
Rg  vm  0  1k           ; gain set

.ac dec 20 10 100k
.control
run
meas ac g_1k   find vdb(out) at=1000
meas ac g_20k  find vdb(out) at=20000
let av = pow(10, g_1k/20)
echo
echo "  DI buffer gain @1kHz  : $&g_1k dB   ( x$&av )   target +12.04 dB (x4)"
echo "  DI buffer gain @20kHz : $&g_20k dB  (flat across audio band)"
echo "  Input impedance is set by the 1Mohm bias R (JFET input ~1e12 ohm) -- see input_loading.cir"
.endc
.end
