Is it possible to integrate a signal in LTSpice and plot the result?


4 Answers 4


Sure, you can use the idt function, for example with a behavioral voltage source, we see the integral wrt time of a sine wave with an offset.

enter image description here

  • 2
    \$\begingroup\$ Even simpler than my suggestion, didn't know LTspice could do idt(x) like that (because I don't use LTSPice). \$\endgroup\$ Commented Aug 28, 2016 at 10:40
  • \$\begingroup\$ @FakeMoustache I'm pretty impressed with the current offering- comparing it to (expensive) commercial PSPICE vs. 100% free. Schematics are bit ugly and the interface is idiosyncratic, but no big deal. \$\endgroup\$ Commented Aug 28, 2016 at 10:43
  • \$\begingroup\$ Does it have a fixed integration constant or can it be varied? I don't use LTSpice BTW. In my sim I think you can "int(V(signal)" in the transient analysis box. \$\endgroup\$
    – Andy aka
    Commented Aug 28, 2016 at 10:44
  • \$\begingroup\$ @Andyaka You can use a multiplication factor of 1/ti. \$\endgroup\$ Commented Aug 28, 2016 at 10:47
  • \$\begingroup\$ @SpehroPefhany +1, elegant solution. Didn't know. 10x. Now, I face a dilemma which solution to choose (yours or mine). The advantage of your solution is that it is shorter (vs my three lines of code). The weakness is less flexibility: it does integration over the whole time span and doesn't allow to track "local" (over specified periods) integrals as in my solution. And your answer seems to be closer to the question wording ("integrate a signal") - this is what your solution does. \$\endgroup\$ Commented Aug 28, 2016 at 11:11

Simply use a 'B' behavioural voltage source with the integral function.


Where sig is (in this case) a node voltage signal you want to integrate.

You can gate the integral using either time or some system state. e.g. Using a node voltage called 'trigger'

V=idt( u(v(trigger)) * v(sig) )

or, using time as a gate

V=idt( (time > 1m & time < 3m) * v(sig) )

Or, using the reset parameter to reset the integral after 5 milliseconds

V=idt( (time > 1m & time < 3m) * v(sig), 0, time > 5m )

To plot the result, simply give the B source output a name and plot that name. If you want you can divide the 'voltage' by '1V' to make it unitless.

From the manual, there are two forms of integral:

1   idt(x[,ic[,a]])  Integrate x, optional initial condition ic, reset if a is true. 
2   idtmod(x[,ic[,m[,o]]]   Integrate x, optional initial condition ic, reset on reaching modulus m, offset output by o. 
  • \$\begingroup\$ The selected answer already has this. \$\endgroup\$ Commented Dec 20, 2018 at 15:19
  • 2
    \$\begingroup\$ Oops. Though mine give a little more detail. Happy to merge the answers. \$\endgroup\$
    – Jay M
    Commented Dec 21, 2018 at 13:38

Yes, it is possible to integrate a signal in LTSpice. Use .meas directive. To plot the integral use .step directive.

Below is an example of how to calculate average charge supplied by a switched capacitor circuit as well as an average current flowing in it. To calculate the charge we integrate the actual current over one period. To calculate the average current we further divide the charge by the time period value.

Suppose, there is the following switched capacitor circuit. The period of non-overlapping clock signals \${\varphi _1}\$ and \${\varphi _2}\$ is 10n (clock frequency f is 100 MHz).

enter image description here

Let’s first calculate analytically the average charge and current flowing in the system:

$${Q_{one\_period}} = C \cdot (VDD - {V_{test}}) = 100fF \cdot (1V - 0.5V) = 50fC.$$ $${R_{eff}} = {1 \over {C \cdot f}} = {1 \over {100fF \cdot 100MHz}} = 100k\Omega $$ $${I_{average\_one\_period}} = {{VDD - {V_{test}}} \over {{R_{eff}}}} = {{1V - 0.5V} \over {100k\Omega }} = 5\mu A$$

Now, let’s get these analytical results in LTSpice.

Build the following circuit:

enter image description here

Code for the LTSpice directives:

.param P=10n
.param t=5n
.step param t 10n 40n 10n
.meas tran Charge_one_period INTEG I(Test) TRIG time VAL=t-P/2 TARG time VAL=t+P/2
.meas tran Average_Current_one_period  INTEG I(Test)/P TRIG time VAL=t-P/2 TARG time VAL=t+P/2

a) P stands for integration interval, t are measurement points (10n, 20n, 30n, 40n).
b) Download link for the file cmosedu_models.txt (PMOS model P_50n used).

Now run simulation to see the actual current flowing in the circuit:

enter image description here

Not really enlightening, isn’t it?

However, if we use our directives:
View -> Spice Error Log -> RClk -> Select “Plot .step’ed .meas data” -> In an opened window RClick -> Visible waveforms and select the calculated data:

enter image description here

As one can see, the simulation result for the charge supplied and average current correspond to the analytical calculation above.

  • 2
    \$\begingroup\$ Not sure why you didn't simply use a voltage controlled current source and fed that current into a capacitor. That way you get an ideal (time) integrator instead of your not so ideal "solution". \$\endgroup\$ Commented Aug 28, 2016 at 10:21
  • 1
    \$\begingroup\$ @FakeMoustache Hi. The goal was to integrate any signal in LTSpice without modifying the circuit. You suggest to add a circuit element which may distort (or not) the simulation result. It may be a solution sometimes, I agree. The preamble to this question was that I did struggle to find how to do it (integrate in LTSpice) in the Internet, with no result. So, decided to share it after found out. \$\endgroup\$ Commented Aug 28, 2016 at 10:29
  • \$\begingroup\$ My solution also does not modify the circuit, obviously you do not understand controlled sources because these just probe a voltage and change nothing. Using a 0 (zero) Volt DC voltage source in series one can also probe the current without changing anything. More advanced simulators (like Cadence Spectre) have a post-processor which will allow you to do integration on any signal as well. LTSpice is limited in this respect so you have to use "tricks". \$\endgroup\$ Commented Aug 28, 2016 at 10:33
  • \$\begingroup\$ @FakeMoustache Yes, indeed, never used behavioral voltage sources as suggested by Spehro (how it got clear). Thanks. \$\endgroup\$ Commented Aug 28, 2016 at 11:13

Without stealing @FakeMoustache's suggestion (and since the OP didn't specify), I'll just add, along his lines, that definite integration (the basic moving-average) is also possible:


Here, integration from 0 to 1 for a 1Hz raised cosine. Note that V(b) is plotted with a 0.1V DC offset, for better comparison. As seen, both methods yield the same result (V(a) and V(b)).

Despite the larger number of elements and nodes, the second suggestion may come faster and more orecise, as the tline has a fixed delay that is not dependent on the sampling rate (i.e. the simulation timestep). Of course, given the conditions, a simple behavioural source may be more convenient -- this is, entirely, a user's choice.

  • 1
    \$\begingroup\$ Download link for the LTSpice schematic and graph for the answer above - for not very smart people, like me, to understand it at first time. \$\endgroup\$ Commented Aug 29, 2016 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.