Maker Pro
What if?

What if?

Scenario Analysis:
Parametric values are a great way to simulate "what if" scenarios in SPICE. Using the ".STEP" directive parametric values can be stepped through different values. For each value a simulation is performed and the results can be displayed in the waveform display. This allows direct comparison of the circuit for different values of its components.

figure 1.png

Figure 1 Stepping the value of a resistor

In the above circuit, the directive ".STEP param Rfilter LIST 1k 10k 100k" steps resistor R1 through 1kOhm, 10kOhm and 100kOhm (the values given as a list). For each value of R1 an AC analysis (transfer function) is performed. Displaying the "waveform" of the voltage across C1 results in three curves for the amplitude and three curves for the phase of the voltage with respect to frequency (AC analysis from 100Hz to 100kHz).

Note: To step more than one parameter, you need one ".STEP" directive per parameter, e.g.

.STEP param Rfilter LIST 1k 10k 100k
.STEP param Cfilter LIST 1n 10n 100n​

Beware: This will not result in 3 simulation runs, as one might naively think. Rather, each parameter from the list for Rfilter is simulated with each of the three parameters for Cfilter, resulting in 3*3 simulations and a rapidly increasing simulation time:

  • 1k + 1n
  • 1k + 10n
  • 1k + 100n
  • 10k + 1n
  • 10k + 10n
  • 10k + 100n
  • 100k + 1n
  • 100k + 10n
  • 100k + 100n
A maximum of three ".STEP" directives is allowed (the help for LTSPICE says "Step sweeps may be nested up to three levels deep."). Other parameters can be stepped, too. See the SPICE help for details.

SPICE help topics to look at: .STEP, .PARAM, .AC

Monte Carlo analysis:
This is not about gambling, although the name is derived from the administrative area of the Principality of Monaco (http://en.wikipedia.org/wiki/Principality_of_Monaco) bordering the Mediterranean sea and known for its casinos.

A standard simulation gives results based on exact component values. A bit of variability can be introduced using „What if“ analysis. Monte Carlo simulation (footnote) is a kind of "what if" analysis where the relevant parameters are chosen randomly (as in throwing dice, therefore the reference to Monte Carlo) from a range of allowed values. This range of values is typically centered around the nominal value +- the allowed tolerance. For example: R=10 kOhm +-5%.

Since in practice the true value can be any value within this range, it is impossible to simulate all values. It is even more impossible (allow me to say so) to simulate all combinations of different component values in a complex circuit.

Monte Carlo (short: MC) simulation offers a way out of this dilemma by using probabilities and statistical analysis.
  1. The probability part of MC simulation is achieved by randomly selecting for each component a value within the possible range. Taking the above example, R=10.026 kOhm could be a choice. This is done for every relevant component (to minimize simulation time, do not vary components where the tolerance is not significant for your simulation).
  2. The statistical part of MC simulation is achieved by running many simulations where parameters or values are changed between each simulation as described in step 1. Depending on the complexity of the circuit and the variability of the parameters, a few simulation runs may suffice or a few thousand runs may be required.
  3. For each simulation the results are stored. After completing the last simulation, all simulation results are superimposed. Thus a band of results will be displayed (instead of a single line for a single simulation) showing the range of possible circuit responses.
You will find a sample under LTSPICE_home\examples\Educational\MonteCarlo.asc
where LTSPICE_home is the root directory of your LTSPICE installation (e.g. C:\program files\LTC\LTspiceIV, depending on your setup).

figure 2.png

Figure 2: Monte Carlo simulation example

The things to do to start a MC simulation are:
  1. For each component replace the fixed value with a random value from within the allowed range. This is done using {mc(value, tolerance)}. For example L2 = {mc(10u,tol)} in conjunction with ".PARAM tol=0.05" makes L2=10µH+-5%.
  2. Force LTSPICE to do a set of simulations instead of just a single run. This is achieved by the LTSPCIE directive ".STEP param X 0 20 1". "X" is a dummy parameter that is not used anywhere. It is stepped, however from 0 to 20 in steps of 1, giving 21 simulation runs, with different parameters for each run due to the {mc()} parameters from the previous step.

Some tips:
  • Minimize the number of variable parameters. A large number of variables will require many simulations for satisfactory results.
  • Start with a small number of simulations. Increase the number of simulations only if the results are not satisfactory. Use good engineering judgment.
SPICE help topics to look at: .STEP, .PARAM, .AC

More information on Monte Carlo simulation:
http://en.wikipedia.org/wiki/Monte_Carlo_method

Harald Kapp, 2014-05-13
  • Like
Reactions: Arouse1973
Author
Harald Kapp
Views
69
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from Harald Kapp

Top