I am running an AC analysis of a two-stage amplifi...
# xschem
r
I am running an AC analysis of a two-stage amplifier in unity gain feedback. The input has 0.9V DC and 1mV AC. I am trying to plot the voltages and the gain in dB with db() function. But it seems that the db() function always give positive value... As shown on the plot above. The output voltage vo (6.05e-05) is below vi (0.001), but the gain, which is db(v(vo)/v(vi)) is +24.37dB. Am I missing something really simple?
s
@Richie Fan in AC plots xschem plots all variables as complex numbers with magnitude (
gain
) and phase (
ph(gain)
)(in degrees). If you plot
ph(gain)
you will see it has a phase of 180deg, so
gain
it is actually a negative real number. To see the correct gain just plot this:
"vout vin / db20()"
(including quotes) You can display also an alias name for the wave:
"gain; vout vin / db20()"
this expression means: create a new "gain" wave, by taking vout and vin, dividing the first by the second and applying 20*log10() (db20()).
@Richie Fan see below example of a gain variable saved as
let gain=db(v(diffout)/v(minus))
and magnitude and phase plotted in xschem, vs the xschem-calculated gain.
m
In the ac example in xschem demos, the phase is plotted with ph(out), is that an xschem or ngspice expression?
if it's xschem, why is not "out ph()" like the gain "out db20()" ?
and how does xschem know to use the ac analysis in the plhase and gain plots (I'm looking a the ac example in the xschem demos)
s
@Matt Venn frequency plots are saved by ngspice in the raw file as complex data with real and imaginary part. So node
out
in a ngspice generated AC raw file is a complex number:
out = re + i * im
. Since we are mostly interested in magnitude and phase rather than real and imaginary parts (unless when doing nyquist plots) xschem transforms data
out=re + i * im
into magnitude:
out = √(re² + im²)
and phase:
ph(out) = atan2(im, re)*180 / π
. So, yes
ph(out)
is xschem specific, it is the phase of
out
measured in degrees. > if it's xschem, why is not "out ph()" like the gain "out db20()" ? Because as said above in xschem
out
is the magnitude of ngspice saved node
out
. You can't get a phase out of a magnitude. Xschem already has transformed the complex ngspice-saved number
out
into magnitude (
out
) and phase in degrees (
ph(out)
). The db20() function just does
20*log10(out)
to transform magnitude
out
into a value in
dB
> and how does xschem know to use the ac analysis in the plhase and gain plots (I'm looking a the ac example in the xschem demos) If there is only one simulation (only one AC sim for example) xschem will load this one and figure out it's an AC plot. If there are multiple simulations (op, dc, tran, ac) the graph can specify which simulation to load. See the Raw file and Sim type text boxes.
m
thank you very much Stefan!
so is ph(out) a variable name then?
s
@Matt Venn
so is ph(out) a variable name then?
Yes, from every complex variable
xxx
(two real numbers, one representing the real part, the other the imaginary component) saved by ngspice in ac raw files xschem creates
xxx
(the magnitude) and
ph(xxx)
(the phase in degrees)
@Matt Venn xschem creates magnitude and phase out of AC complex data, since in bode plots very likely you will plot magnitude (perhaps transformed to dB , db20() function) and phase. You can always get back the real and imaginary components though. Image below shows a nyquist plot for a 2 stage differential amplifier, you see the uncompensated diffamp encircling the -1,0 point in the complex plane, another way to say it is unstable and will oscillate.
m
Thanks!
s
Interesting way to visualise the nyquist plot @Stefan Schippers. Thanks for including this feature in xschem. Could I ask if the schematic of the
test_nyquist.sch
could be shared or where are the ac examples in the xschem repo ? I tried the ngspice expression for the imaginary part as
imag(vout_vector)
but it doesn't generate a nyquist plot.
s
the test_nyquist has been added to the xschem distribution. This example uses generic MOS models, not sky130 specific devices, so you can test it without an installed pdk. https://github.com/StefanSchippers/xschem/blob/master/xschem_library/examples/test_nyquist.sch
👍 1