I was running some SPICE simulations recently and needed to add Gaussian white noise to specific nodes in my circuit in order to measure noise tolerance. Between the two simulators I run, OrCAD’s PSPICE and Cadence, I hoped that there would be an easy way to do this – perhaps a noise-generating source of some kind or a rand function that would return random values according to a specified distribution. Unfortunately, this is not the case – a sad fact that has caused others working with SPICE to lament:
Unfortunately there is no easy way [in SPICE] to randomly tolerance devices such that they are not a perfect match, or to add a ‘noise’ voltage to insure the circuit will start. (Wish list: add a rnd(n) function to B2SPICE to enable random part values to be specified, or a small noise generator to be created. The proposed function would return a pseudo-random number between zero and unity, where ‘n’ could represent a uniform distribution for the value ‘0′, a Gaussian distribution for a ‘1′ argument, and so on.) [http://www.beigebag.com/case_convergence.htm]
After relentlessly pursuing the matter, however, I have found that there is in fact a way around this apparent limitation in SPICE. The solution involves the use of a piecewise linear source, a common SPICE component which outputs voltage or current according to tuples of the form (time,voltage/current) which are supplied by the simulation programmer. These tuples control the source by indicating the voltage or current signal that it should be supplying at any given point in time. A programmer can supply a seemingly infinite number of these tuples in order to control the output of the source over a certain time period.
An effectively random source can be created by generating voltage or current values according to a desired distribution and using these values in the tuples of a piecewise linear source. In my case, I used a short Matlab program to generate values that were normally distributed with a mean and variance of my choosing and then used these values as data points for a piecewise linear voltage source.
Here’s an example of how the whole process might work:
Let’s say, for instance, that in order to test the noise tolerance of a circuit, you need input voltages that behave like Gaussian white noise with a specific mean and variance.
- Search your SPICE component library for a piecewise linear voltage source. In both Cadence and PSPICE there a is piecewise linear voltage source that takes its data points from a file (this component is “pwlf” in Cadence and “vpwl_file” in PSPICE).
- Use this voltage source component for your input signals.
- Configure each component to pull data from a file – in this case we’ll call the file ‘pwlFile.in’.
- Use this Matlab program to generate the pwlFile.in file and place it in your SPICE simulation directory. Note that the program provided generates voltage values the are normally distributed according to a user-specified mean and variance.