Electronic – How to plot sliding average in ltspice

ltspice

I would like to plot a sliding average of some voltages and currents. Ideally I would just add a new trace with some expression, but all expressions that I found so far only operate on single values.

Are there any expressions (like absdelay for B sources) that would do the trick?

Best Answer

Summary
To plot the the moving (sliding) average use .MEAS,.PARAM and .STEP LTSpice directives (see the detailed explanation below). As a quick partial solution, use zoom in and Ctrl+Click on a plot title to show the average value (only a single value, not plot) for the selected abscissa range.

Solution. Plotting moving average for a signal

Suppose there is a following set-up and one needs to know the moving average of V(out):

enter image description here

Step 1: create the directive

Create the following SPICE directive (Edit -> Spice Directive):

.param t=0
.step param t 100n 900n 100n
.param S=100n
.meas tran Moving_Average avg(v(out)) TRIG time VAL=n-S/2 TARG time VAL=n+S/2

Comment for the directive:

1st line: define a time variable t.
2nd line: Step t from 100ns to 900 ns with the step 100ns.
3rd line: Set the moving average span: 100 ns.
4th line: Syntax: Moving_Average - the name of the newly created variable to be calculated (put here whatever you like).
TRIG time VAL=t-S/2 - start of averaging.
TARG time VAL=t+S/2 - end of averaging.
E.g. if t=300 ns, averaging spans from 250 ns till 350 ns (300 +/- 100/2).

Step 2: run simulation, open the log file and plot the moving average

Run simulation

enter image description here

Open the Spice Error Log (View -> Spice Error Log), right click on any place and select Plot Stepped Measured Data

enter image description here

See the moving average plotted

enter image description here

Quick partial solution (see average value for a specified time range)

Suppose one has a chart like this:

enter image description here

And wishes to calculate an average value during [0.7us,0.8us].

Step 1: Specify the time range.

Double click on the abscissa axis and specify the needed range. Alternatively use Zoom to Rectangle tool (magnifier button in the top bar).

enter image description here

Step 2: Calculate the average

Ctrl + left mouse click on a chart title (bold green title V(out) in the picture) to see the average value for the specified range.

enter image description here