Maker Pro
Simulating waveforms

Simulating waveforms

Simulating a PWM waveform with varying duty-cycle:
I found the following trick here: only):
Add a voltage source to your schematic. Change it to an "arbitrary behavioral voltage source" by right-clicking on the symbol while simultaneously holding down the CTRL-key. Change the Prefix from "V" (standard) to "B" (behavioral). You can alternatively add a behavioral voltage source (BV) or current source (BI) directly. Set the value to:

Add the following SPICE directives to your schematic:
.PARAM period=0.001
.PARAM sweep=0.1
.PARAM amplitude=5​
This will generate a PWM waveform with an amplitude of 5V, a frequency of 1kHz (period = 0.001 sec) and a duty cycle swept from 0%...100% within 0.1s.

SPICE help topics to look at: .PARAM, BV, BI, arbitrary behavioral voltage or current sources, voltage source

Other forms of the PWL statement:
LTSPICE IV supports many other forms of PWL statement. To explore these you will have to directly edit your statement by right-clicking on the text line with the PWL statement (not the component symbol), in the schematic editor. Some examples of alternate PWL forms for a voltage source:

• Repeating data pairs a specified number of cycles, or forever:

PWL REPEAT FOR 5 (0ms 0V 1ms 1V 2ms 1V 3ms 0V) ENDREPEAT
PWL REPEAT FOREVER (0ms 0V 1ms 1V 2ms 1V 3ms 0V) ENDREPEAT​

• A trigger expression that turns the source on as long as the expression is true:

PWL (0ms 0V 1ms 1V 2ms 1V 3ms 0V) TRIGGER V(n003)>1​

• Scaled time or source values:


These expressions are not explained in the LTSPICE manual.

Source: LT Journal of Analog Innovation, Volume 22, Number 3, October 20132 page 31

SPICE help topics to look at: See "Undocumented LTSPICE features"

Simulating arbitrary waveforms:
1) Using waveform files:
Of course, one could always approximate an arbitrary waveform by using a PWL source. But you wouldn't want to do this beyond a handful of PWL points. However, LTSPICE can import arbitrary waveforms from a .wav file. Even multi-channel signals (e.g. stereo) are supported. The results of the simulation may even be written to an output .wav file.
You could simulate a complete stereo amplifier this way.

The input from the .wav file is scaled from -1 ... 1 quantized in 16 bits. So you may have to scale up the signal using for example a voltage controlled voltage source (symbol "e" from the LTSPICE component library) with a fixed gain to be supplied by you.

This feature can be used to break up the simulation of a large circuit into smaller simulations, provided there is no feedback between the separate circuits (only unidirectional signal flow). Just run a simulation for subcircuit 1, saving the signals at the interface between subcircuit 1 and 2 in an intermediate .wav file (remember scaling!).
Now run a simulation for subcircuit 2 using the intermediate .wav file for input to the subcircuit 2. Since (in my experience) simulation time increases non-linearly with circuit complexity, this method (if applicable) may reduce the total simulation time noticeable.
Google „LTSPICE wav files“ for various in-detail instructions.

2) Using behavioral sources
A behavioral source is a voltage or current source whose output is defined by a mathematical function. See „Simulating a PWM waveform with varying duty-cycle“ for an example. More functions are listed in the LTSPICE help file.
A behavioral source can be used instead of a controlled source (see also „Avoid using controlled sources“) by setting it to the desired transfer function.

SPICE help topics to look at: voltage source, current source, BV, BI.

Simulating a surge pulse:
A surge pulse according to IEC 61000-4-5 (1.2/50 µs) may be simulated in Spice with an exponential voltage source. Add a voltage source with the parameters:
EXP(V1 V2 Td1 Tau1 Td2 Tau2)​
for example EXP(0V 1kV 0ms 0.4µs 0.0012ms 50µs)

Explanation of parameters:
  • V1 = start voltage = 0 V in the example
  • V2 = peak voltage = 1 kV for a typical differential test in the example. Change to 4 kV for a typical common mode test.
  • Td1 = rise delay time i.e. start time of surge impulse relative to start of simulation = 0 ms in the example
  • Tau1 = time constant of rising edge.
Note that the rising edge theoretically is a linear function but is being approximated by an exponential curve by the above simulation command. Therefore I have set this time constant empirically to 0.4 µs (not 1.2 µs as one might expect).
  • Td2 = fall delay time i.e. start of falling edge of the surge impulse. Td2 = 1.2 µs
  • Tau2 = time constant of falling edge. This is 50 µs for the standard surge impulse.
Note: Do not forget to include the source impedance of the surge generator (2 Ohm) plus the coupling network (e.g. 10 Ohm 9 µF or 40 Ohm 0.5 µF) to your simulation, as required by IEC 61000-4-5 for the different surge tests.

figure 1.png

Figure 1 Model for a surge generator

in case repetitive surge pulses are required, an even simpler approximation of the surge pulse by a triangular waveform may do. Add a voltage source to your schematic and set its parameters to

Pulse(V1 V2 Tdelay Trise Tfall Ton Tperiod)
for example Pulse(0 1kV 0 1.2µs 100µ2 0 5ms)

Explanation of parameters:
  • V1 = start voltage = 0 V for a surge pulse
  • V2 = peak voltage = 1 kV for a typical differential test in the example. Change to 4 kV for a typical common mode test.
  • Tdelay = delay before 1st pulse, 0 ms in the example
  • Trise = rise time of the pulse, this is 1.2 µs for a surge pulse
  • Tfall = fall time of the pulse. Since the exponential decay of the original surge pulse has a half-life time of 50 µs, the falling edge is approximated by 100 µs fall time
  • Ton = on time of the pulse. This is 0 ms since the pulse starts decaying immediately after its rising edge
  • Tperiod = period of the repetition rate, 5 ms in the example
SPICE help topics to look at: voltage source

Simulating a fast transient source:
Fast transients (sometimes also called bursts) are defined e.g. in VDE0843 (EN 50270) and other standards. Whereas the parameters of the fast transient pulses vary from standard to standard, the basic principle is the same:
Packets of high energy pulses with a very short rise time are repeatedly applied to the device under test. Between the packets there is a recovery time without pulses.
figure 2.png

Figure 2 Fast transient waveforms (from the reference below)

A simplified generator can be simulated in LTSPICE by the following circuit:

figure 3.png

Figure 3 Simplified equivalent circuit of a fast transient generator.

Theory of operation:
1. V1 charges C1 to the peak pulse voltage.
2. Vpulse operates switch S1 to generate the fast transient pulses.
3. Vpacket operates switch S2 to control the activity of Vpulse on switch S1, thus generating pulse packets of 15 ms duration and 285 ms recovery time. Therefore the duration of one complete packet is 300 ms (15 ms pulsed + 285 ms idle).

This sample circuit needs to be adapted to the special requirements of the respective standard. In particular the following parameters need to be adjusted:
  • Set V1 such that the peak impulse voltage at the output Vburst conforms with the requirements of the respective standard.
    Note that the ".IC" SPICE directive needs to be adjusted, too. A good idea would be to use a .PARAM directive instead of fixed values (Using parametric values in LTSPICE).
  • It may be required to adjust other components such as R2, R3 and C2 to conform with the requirements for a specific fast transient generator.
However, keep in mind that it is next to impossible to simulate all parasitic effects of your circuit in real life (as defined by placement and routing on the PCB, tolerances of components, manufacturing etc.). Therefore not too much effort should be put into simulating the fast transient waveform as exactly as possible. Even a quite inaccurate fast transient waveform should allow you to find the main source of failure of a circuit during EMC stress and should help to define measures to alleviate these problems - provided that you have a good understanding of EMC.

This is only a support tool to analyze problems in case of failure during EMC testing in the real world.

Simulation can never replace real testing!

Reference: (German)

SPICE help topics to look at: voltage source, .PARAM, S. (voltage controlled switch)

Simulating a noisy source:
A noisy source can be modeled by an arbitrary waveform (see above) using the random() function. The complete waveform of the source could be behaviorally modeled by a complex expression for the arbitrary waveform adding the noiseless signal and the noise into one source.

figure 4.png

Figure 4 single behavioral voltage source

Figure 4 shows a complex behavioral voltage source incorporating:
  • 1 V DC offset
  • 1 V amplitude sine with a frequency of 1oooHz
  • 1µV noise source
Since all parameters of the source are mixed up in one expression, it may be fairly difficult to change one parameter without involuntarily effecting other parameters. Also, the meaning of some parameters may not be obvious. For example take the "1000" in the sin() expression which is the frequency (I'm sure you guessed it correctly).

Therefore, I suggest using two sources in series connection (for voltage sources) or parallel connection (for current sources). Thus it is easier to model the noiseless signal and the noise separately.

figure 5.png

Figure 5 Splitted voltage sources

Figure 5 shows two voltage sources:
  • V3 modeling a sinusoidal voltage source with a DC offset of 1 V, an amplitude of 1 V and a frequency of 1 kHz
  • B1 modeling the noise source with 1µV peak noise voltage on top of V3
The signal source and the noise source can now be handled independently, which is in my view a great advantage over the complex technique of figure 3.6-1.
The random(x) function generates a random number between 0...1 depending on the parameter "x". In order to use this function in a meaningful way for a random source, two things have to be considered:
  1. scale the random value to the required amplitude of the noise signal
  2. use simulation time as the parameter "x" for the random function. Since "x" has to be an integer number, simulation time needs to be scaled accordingly. Depending on the timescale you are using, it may be necessary to scale simulation time by a factor of e.g. 1e6 which would give a new random value every µs.
The random(x) function generates a pseudo-random signal with an assumed (by me) uniform distribution in the interval 0...1. If a different distribution of the noise is required, additional mathematical operations may be necessary. For examples see the Marsaglia polar method or Box-Muller method for generating random values with a normal distribution (

If the noise source is required to have special characteristics, not easily obtainable with standard SPICE tools, an alternative is to generate externally the source data as data file for a PWL source. This is described in the reference below.


SPICE help topics to look at: random, arbitrary source, B., PWL

Harald Kapp, 2014-05-13
Harald Kapp
First release
Last update
0.00 star(s) 0 ratings

More resources from Harald Kapp