06_passive_ac: freqency domain simulation: ac

Scope

In this simulation we are going to look at how a multi-stage RC filter behaves when stimulated with sine waves of various frequencies.

The schematics

The single-sheet schematic contains the filter, the voltage source and the spice command symbol.


Click the image to get the sch-rnd sheet

SPICE: what an ac simulation is

In the ac analysis simulation a DC solution is calculated first and then a small signal sinusoidal stimulus is applied over a range of frequencies. The result is typically a graph with frequency on the X axis and gain or phase on the Y axis. The AC analysis is often used to get a transfer function.

Preparing for simulation

V1

In our example, V1 specifies a 1V AC signal with a DC component of 0V on the in network. The syntax for this is (see in V1's spice/params):

dc 0 ac 1

The frequency of the ac component is not specified because that will be varied over a range by the analysis command.

Raw spice commands

It contains the following script:

ac dec 10 1 100k

settype decibel out
plot vdb(out) xlimit 1 100k ylabel 'small signal gain'

settype phase out
plot cph(out) xlimit 1 100k ylabel 'phase (in rad)'

let outd = 180/PI*cph(out)
settype phase outd
plot outd xlimit 1 100k ylabel 'phase (in deg)'

The first line instructs spice to do the "ac analysis" in decade variation mode (dec 10), to get a decade logarithmic output with 10 points in each decade. It then specifies the range of interest for the frequencies: anything between 1 Hz and 100 kHz.

Then come three plots. The first is the output voltage in decibels, on a logarithmic Y scale, then the phase shift of the circuit, both in radians and in degrees.

Export and run ngspice

Because of the plot commands the output is a set of drawings (if ngspice is run on X): three graphs with one curve each.

Using other implementations

gnucap

Gnucap uses a different command syntax. Modify the spice command symbol's spice/command attribute to:

print ac vdb(out) zp(out)
op
ac dec 10 1 1000k > plot.txt

After the export, write the single word spice in the first line of the file (e.g. using a text editor), otherwise gnucap won't know the file is in spice syntax. Then run gnucap 06_passive_ac.cir and it will dump a text table to plot.txt that can be plotted using a suitable utility, e.g. gnuplot.

The gnucap-modified schematic is also available.

xyce

TODO