metronome/hardware/eda/sim/plots.gp
Me Here af8e7e236b PM_K-1 hardware: render simulations as PNG plots (gnuplot) so they're viewable
Added gnuplot to the EDA container; sims now wrdata their curves and plots.gp renders 5
PNGs in hardware/eda/sim/plots/ (open in any browser/viewer):
- input_loading: instrument(1M) preserves the +16dB pickup resonance the line(25k) flattens
- stage1_cmrr: common-mode leakage, 0.1% vs 1% resistor mismatch
- stage2_recon: DAC reconstruction filter (flat to 20k, -3dB ~75k)
- stage4_driver: balanced differential response (flat across audio)
- stage1_phantom: +48V transient clamped at the op-amp input, decays to ~0
(.data intermediates git-ignored.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-31 18:39:46 -05:00

39 lines
1.7 KiB
Gnuplot

# Render the PM_K-1 ngspice simulation data to PNG plots.
# Run inside the container AFTER the sims have written their .data files:
# ./run.sh bash -lc 'cd /work/hardware/kicad; for s in ...; do ngspice -b ../eda/sim/$s.cir; done; gnuplot /work/hardware/eda/sim/plots.gp'
set terminal pngcairo size 1000,560 font "Sans,11"
set grid
set key box
P = "/work/hardware/eda/sim/plots/"
set logscale x
set xlabel "Frequency (Hz)"
set output P."input_loading.png"
set title "Input loading: line (25k) vs instrument (1M) input -- why Hi-Z preserves the pickup"
set ylabel "Level (dB)"
plot "/work/hardware/eda/sim/input_loading.csv" u 1:2 w l lw 2 t "line input (25k ohm)", \
"" u 3:4 w l lw 2 t "instrument input (1M ohm)"
set output P."stage1_cmrr.png"
set title "Stage 1 receiver: common-mode leakage vs resistor match (lower = better; perfect match ~ -inf, off scale)"
set ylabel "Output leakage (dB, Vcm = 1V)"
plot P."stage1_cmrr.data" u 1:2 w l lw 2 t "0.1% mismatch", \
"" u 3:4 w l lw 2 t "1% mismatch"
set output P."stage2_recon.png"
set title "Stage 2 DAC reconstruction filter -- flat to 20 kHz, -3 dB near 75 kHz"
set ylabel "Gain (dB)"
plot P."stage2_recon.data" u 1:2 w l lw 2 t "filter response"
set output P."stage4_driver.png"
set title "Stage 4 balanced output -- differential response (flat across the audio band)"
set ylabel "Differential gain (dB)"
plot P."stage4_driver.data" u 1:2 w l lw 2 t "hot - cold differential"
unset logscale x
set output P."stage1_phantom.png"
set title "Stage 1 protection: +48V phantom hit at the op-amp input -- clamped, then decays to ~0"
set xlabel "Time (s)"
set ylabel "Op-amp input (V)"
plot P."stage1_phantom.data" u 1:2 w l lw 2 t "V(op-amp input)"