* High-pass summer transient testbench .param freq=50k .param VA=1 .param VO=0 .include ../netlists/highpass_summer.sp * pass some parameters to control script: .csparam freq=freq .csparam VA=VA .control * Calculate transient simulation settings * (Here the csparam can be directly used * in expressions with the "let" command) let period={1/freq}; let tstop = 10*period; let tstep = 0.1*period; * Initialize output data vectors: let gain = 0*unitvec(6) let outofs= 0*unitvec(6) * Define experimental settings as indicated in * Procedure 2(A)(i--iv) * negative values need to be in parentheses compose v1dc values 0 0 0 1 (-1) (-2) compose v2ofs values 0 1 2 0 0 0 * Use a FOREACH LOOP to run each case foreach idx 0 1 2 3 4 5 * Grab parameters from their vectors: set VI=v1dc[$idx] set VO=v2ofs[$idx] * Change the settings of sinusoidal source V2, * and DC source V1, and repeat the simulation: alter V1 DC $VI alter @V2[sin] = [ $VO $&VA $&freq ] * Run transient simulation * (here the "$&" expansion is used so the * settings are given as strings) tran $&tstep $&tstop * Measure gain: meas tran vopp PP v(nout) from=0 to=$&tstop; meas tran vipp PP v(n2) from=0 to=$&tstop; * Measure output offset: meas tran voavg AVG v(nout) from=0 to=$&tstop; * Save the measurements in the output data vectors: let gain[$idx] = vopp/vipp let outofs[$idx]= voavg * Plot results: let a=v1dc[$idx] let b=v2ofs[$idx] set fname=plots/proc2a_{$idx}.svg plot v(nout) v(n2) title 'V1=$&a,V2(offset)=$&b' hardcopy $fname v(nout) v(n2) title 'V1=$&a,V2(offset)=$&b' end * foreach * Print the output vectors: print v1dc v2ofs outofs gain .endc .end