Circuit with Passive Elements, Small Signal AC
Now we want to see what the small signal behavior of this rc ladder network might be. Small signal means that we set a dc operating point to our circuit. Then we add a small ac signal to the input and simulate what the output ac voltage might be versus frequency. So we have to vary the frequency of this small input signal. And we are not interested in the absolute output voltage value, but its relation to the input (gain) and its phase shift in relation to the input (phase). Fortunately there is the ac
command in ngspice that makes life easy. Firstly, we have to tell ngspice where to input their small signal ac voltage. We choose node in, that is our voltage source V1. V1 now becomes
V1 in 0 dc 0 ac 1 PULSE (0 5 1u 1u 1u 1 1)
We simply added ac 1
. The dc 0
sets the operating point (which does not matter in such a simple circuit), PULSE
does matter only during transient simulation, so we keep it for simplicity. The 1 in ac 1
just helps with getting the ratio out/in, by dividing the output by 1, or just take it as is. The simulation command is
ac dec 10 1 100k
We want to do an ac
simulation. We vary the frequency as if plotted logarithmically, with 10 points per decade. The starting frequency is 1 Hz, the stopping frequency is 100 kHz. So we will get 51 data points. If now plotted with the command plot out
, the graph looks ugly (output below 0?). Well, we are dealing with AC signals.
These are complex numbers, consisting of a real part and an imaginary part (or equivalently consist of magnitude and phase). Typically plot out
only delivers the real part of the signal. But we want to see magnitude (or gain) and phase, like in a Bode plot. So one should use plot vdb(out)
for the gain in dB and plot ph(out)
for the phase. Now the graphs are o.k., but titles and labels are not yet satisfactory. ngspice plotting procedures here need some manual tweaking.
Before we move on, we have to streamline our approach. Typing everything to the console seems too laborious. ngspice has a feature to assemble all interactive commands (the ones we have typed) into a .control
... .endc
section. This .control
section can be added to the netlist, which now looks like
.title dual rc ladder * file name rcrcac.cir R1 int in 10k V1 in 0 dc 0 ac 1 PULSE (0 5 1u 1u 1u 1 1) R2 out int 1k C1 int 0 1u C2 out 0 100n .control ac dec 10 1 100k plot vdb(out) plot ph(out) .endc .end
We save our netlist in file rcrcac.cir and start ngspice. The netlist is read, the commands in the .control
section (ac simulation and plotting) are executed automatically. Still we would like to improve the graphics plot. We do this by using several extra commands, that we add to the .control
section. All of them are described in the ngspice manual, chapter. 17.5. The complete input file now reads:
.title dual rc ladder * file name rcrcac.cir R1 int in 10k V1 in 0 dc 0 ac 1 PULSE (0 5 1u 1u 1u 1 1) R2 out int 1k C1 int 0 1u C2 out 0 100n .control 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' .endc .end