meas / measure
Measure results, as .meas
General form
meas [op|dc|ac|tran|tf|noise] name measurement meas
Measure a value from the results of an analysis: the time a waveform crosses a level, the delay between two events, an average or RMS value, and so on. The result is stored as a vector called name in the plot, so it can be printed, plotted, used in expressions, used by later measurements, or used as the goal of optimise. measure is the same command.
The analysis type is optional. If it is given, the current plot must be of that type. With no arguments, meas runs the circuit's .meas cards again on the current plot.
A .meas (or .measure) card in the circuit takes the same arguments, with the analysis type first:
.meas tran risetime TRIG v(out) VAL=0.1 RISE=1 TARG v(out) VAL=0.9 RISE=1
The cards are run automatically on the results of each analysis of the matching type, and each prints its result, for example
risetime=2.19669e-06 FROM 1.10594e-06 TO 3.30263e-06
A measurement that can't be made (a level that is never crossed, say) prints FAILED with the reason, and no vector is stored.
A meas command, including one in a .control block, measures the current plot once. Only .meas cards are run again after later analyses, including each run done by optimise and each step of .step. So a result that optimise uses as its goal must come from a .meas card.
In batch mode
In batch mode (spice -b), a circuit with .meas cards is run even if it has no .print, .plot or .four cards, and each card prints its result as the analysis finishes. All the vectors of an analysis that a .meas card is for are saved, since the measurement may use any of them.
A .print card can name measurement results as well as circuit nodes. The results are printed as single values, after any columns for nodes:
.ac dec 10 100 10k .meas ac gain1k FIND vdb(out) AT=1k .print ac vdb(out) gain1k
As with any .print card, the analysis type must come first: .print gain1k on its own is not valid. .print cards are only used in batch mode; interactively, use print.
Point measurements
FIND expr AT x- The value of expr at x on the plot's scale (time, frequency or the dc sweep).
FIND expr WHEN lhs=rhs [modifiers]- The value of expr when lhs crosses rhs.
DERIV expr AT xDERIV expr WHEN lhs=rhs [modifiers]- The derivative of expr with respect to the scale, at x or at the crossing.
WHEN lhs=rhs [modifiers]- The scale value (for example the time) at which lhs crosses rhs.
FIND expr- For an operating point analysis: the value of expr.
PARAM expr- The value of an expression, which may use the results of earlier measurements, for example
PARAM risetime/delay.
Range measurements
AVG | MAX | MIN | PP | RMS | INTEG expr [FROM x1] [TO x2]- The average, maximum, minimum, peak-to-peak value, RMS value or integral of expr between x1 and x2 (by default, the whole plot).
P2Pis the same asPP. MAX and MIN also print where the extreme occurs. AVG | MAX | MIN | PP | RMS | INTEG expr TRIG cond TARG cond- The same, over the range between two events.
TRIG cond TARG cond- The difference in the scale between the two events: a delay, rise time or period.
Conditions and modifiers
A condition cond after TRIG or TARG is one of
lhs=rhs lhs VAL=rhs AT=x
The first two forms mean the same thing: the event is where lhs crosses the level rhs. VAL= gives that level. It is the usual way to write a TRIG or TARG condition, and it can only be used there: after WHEN, write lhs=rhs. The third form makes the event a fixed point x on the scale. For example,
.meas tran tpd TRIG v(in) VAL=0.6 RISE=1 TARG v(out) VAL=0.55 FALL=1
measures from the first time v(in) rises through 0.6V to the first time v(out) then falls through 0.55V. The result is the difference in time, TARG minus TRIG.
A condition is followed by optional modifiers, which also apply after WHEN:
TD=x- Ignore crossings before x.
RISE=n,FALL=n,CROSS=n- Use the nth rising, falling or any crossing. The default is the first crossing.
RISE=LAST(orFALL=LAST,CROSS=LAST)- Use the last such crossing.
All values may be expressions. Keywords are not case sensitive, and the = after a keyword is optional. For ac results, values are compared, and taken in range functions, by magnitude; FIND and DERIV return complex results.
Examples
For an RC low pass with a time constant of 1µs, driven by a 1V pulse, and an ac response with a 159Hz corner (from examples/meas_demo.cir):
* 10%-90% rise time: tau*ln(9) = 2.197us .meas tran risetime TRIG v(2) VAL=0.1 RISE=1 TARG v(2) VAL=0.9 RISE=1 * 50% delay, input to output: tau*ln(2) = 0.693us .meas tran delay TRIG v(1)=0.5 RISE=1 TARG v(2)=0.5 RISE=1 * The output 1us after the edge: 1-exp(-1) = 0.632 .meas tran v2 FIND v(2) AT=2u * When the output falls through 0.5 .meas tran tfall WHEN v(2)=0.5 FALL=1 * The slope 1us after the edge: exp(-1)/tau = 3.68e5 V/s .meas tran slope DERIV v(2) AT 2u * Averages over one period of the 50% duty cycle input: 0.5 and 0.707 .meas tran vavg AVG v(1) FROM 0 TO 100u .meas tran vrms RMS v(1) FROM 0 TO 100u .meas tran vpp PP v(2) * A measurement of measurements: ln(9)/ln(2) = 3.17 .meas tran ratio PARAM risetime/delay * The -3dB frequency, and the response there .meas ac f3db WHEN vdb(11)=-3.0103 .meas ac atf3db FIND v(11) AT f3db
Running this prints
f3db: vdb(11)=-3.0103 AT 159.155 atf3db: v(11)=(-3.0103dB,-44.9977deg) AT 159.155 risetime=2.19669e-06 FROM 1.10594e-06 TO 3.30263e-06 delay=6.9318e-07 FROM 1.0005e-06 TO 1.69368e-06 v2: v(2)=0.631995 AT 2e-06 tfall: v(2)=0.5 AT 5.16947e-05 slope: d(v(2))/d(time)=368218 AT 2e-06 vavg: AVG(v(1))=0.50001 FROM 0 TO 0.0001 vrms: RMS(v(1))=0.707111 FROM 0 TO 0.0001 vpp: PP(v(2))=1 FROM 0 TO 0.0001 ratio: risetime/delay=3.16901
and the results are vectors in each analysis's plot:
setplot tran1 print risetime delay ratio
With .step, each measurement gives one value per step, and the results are tabulated at the end of the run.