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 single-sheet schematic contains the filter, the voltage source and the spice command symbol.
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.
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.
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.
Because of the plot commands the output is a set of drawings (if ngspice is run on X): three graphs with one curve each.
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.
TODO