* Q of a parallel RLC tank from its -3 dB bandwidth.
* R=316.23, L=1u, C=1n -> Q = R*sqrt(C/L) = 10, fo = 5.03 MHz.
Iac in 0 AC 1
R1 in 0 316.23
L1 in 0 1u
C1 in 0 1n
.ac dec 2000 1e6 30e6
.control
  run
  meas ac zmax MAX vm(in)              $ peak impedance = R, at fo
  let thr = zmax/sqrt(2)               $ -3 dB level
  meas ac flo WHEN vm(in)=thr RISE=1   $ lower skirt
  meas ac fhi WHEN vm(in)=thr FALL=1   $ upper skirt
  let Q = sqrt(flo*fhi)/(fhi-flo)      $ Q = fo / bandwidth
  print Q
.endc
.end
