Sometimes it's useful to obtain the transfer function for a circuit or network. For simple circuits this can be done manually but for anything complex a manual approach is error prone. Once you have the transfer function you will want to do plots which these days aren't likely to be wanted on paper, even if they can be done on paper. There have also been questions in this group about how transfer functions relate to analog computer circuits so I wanted to see if I could find a means to obtain the transfer function for any circuit consisting of ideal op amps and other passive components.
To do that I started with what became known as the state-variable filter. This was used in recently posted sinewave oscillator circuits. Exactly why it's called a state-variable filter seems to be lost to history but there's a clue in the following document on page 9.
After some online research I came across this
O#160#180#0#O3#1#0 W#140#180#140#180# W#250#130#250#200# W#250#200#240#200# W#650#200#640#200# W#650#200#650#130# W#340#220#350#220# W#430#260#430#200# W#430#260#230#260# W#430#130#430#200# W#170#260#130#260# W#650#130#620#130# W#650#130#650#120# W#650#120#650#80# W#650#80#220#80# W#450#130#420#130# W#360#130#320#130# W#260#130#220#130# C#620#130#1#C2#1E-8#0 C#420#130#1#C1#1E-8#0 R#510#130#1#R6#16000#0 R#320#130#1#R5#16000#0 W#120#130#160#130# W#160#80#120#80# R#230#260#1#R2#10000#0 R#130#260#1#R1#10000#0 R#220#80#1#R4#10000#0 R#220#130#1#R3#10000#0 W#150#220#160#220# W#150#260#150#220# O#350#180#0#O2#1#0 g#330#230#0#g1#1#0 W#330#220#330#230# W#330#220#340#220# W#120#180#160#180# W#120#80#120#180# O#560#180#0#O3#1#0 W#540#220#550#220# W#540#220#540#230# g#540#230#0#g2#1#0 W#550#220#560#220# W#340#180#350#180# W#340#130#340#180# W#540#180#560#180# W#560#130#510#130# W#540#130#540#180# v#430#260#0#vout#1#0 V#60#270#0#Vin#1#1 g#60#340#0#g3#1#0 W#60#330#60#340# W#60#260#60#270# W#60#260#70#260# R#220#30#1#R7#100000000#0 W#120#30#160#30# W#120#80#120#30# W#440#30#220#30# w#440#50#1#1#0#1 W#440#30#440#50# W#440#130#440#110#
Drawing a schematic can be a little frustrating for an LTSpice user and you'll need that universal Windows get out of anything key at the top left of your keyboard (Esc). I set Zoom to 2.
When the schematic is drawn and saved as an sch file (or use the file above, 59 lines) you can go to Analysis, Check Nodes. This will either show you that your nodes are ok or generate an access violation. Op amps don't have designators so I refer to them as U1, U2, U3 from left to right.
Now go to Analysis and Complete Analysis. As if by magic, a transfer function should appear. Now go to Output Export Matlab (.m) Laplace Domain and save the m file. Don't worry, I don't have Matlab either, you won't need it. Close SapWin.
Open the m file (Notepad++ if you don't already have an editor). All you need from here is the num and the dem.
At this point I decided to consult the oracle again like this
import control as ct import matplotlib.pyplot as plt
# Define a transfer function: H(s) = (s + 2) / (s^2 + 2s + 3) #sys = ct.tf([1, 2], [1, 2, 3])
#num = + ( -C2*R2*R4*R6*R7 -C2*R2*R3*R6*R7 -C2*R2*R3*R4*R6 )*s; #den = + ( R2*R3*R7 +R1*R3*R7 )+ ( -C2*R2*R3*R4*R6 +C2*R1*R4*R6*R7 +C2*R1*R3*R6*R7 )*s+ ( C2*C1*R2*R4*R5*R6*R7
+C2*C1*R1*R4*R5*R6*R7 )*s^2;
R1=10000 R2=10000 R3=10000 R4=10000 R5=16000 R6=16000 R7=1e8 C1=1e-8 C2=1e-8
sys = ct.tf([-C2*R2*R4*R6*R7 -C2*R2*R3*R6*R7 -C2*R2*R3*R4*R6, 0], [C2*C1*R2*R4*R5*R6*R7 +C2*C1*R1*R4*R5*R6*R7,-C2*R2*R3*R4*R6
+C2*R1*R4*R6*R7 +C2*R1*R3*R6*R7 ,R2*R3*R7 +R1*R3*R7 ])
ct.bode_plot(sys, Hz=True, dB=True, deg=True ) plt.grid(True) plt.show()
ct.pole_zero_plot(sys) plt.grid(True) plt.show()
ct.nyquist_plot(sys) plt.grid(True) plt.show()
When you run this, assuming line wraps have been sorted out, the first thing which is likely to happen is that you will need to do pip install control And maybe also update pip while you're at it. Now run again and if all is well then after a short delay, as if by magic, a bode plot will appear.
So far this isn't any more than LTSpice can do with a frequency sweep but now close the bode plot window. A pole zero plot should appear. Close that and a Nyquist plot should appear. Close that and the program should exit.
Note that for the component values given in the python program the poles are well inside the left half plane so this is a stable filter circuit. R7 is not required for a filter.
Now change R1 to 470 and R7 to 82000 in the python program. The poles are now just inside the right half plane so this is an oscillator.
If anyone knows any simpler ways to do similar manipulations without expensive commercial software please let me know. It would be nice to be able to go directly from an LTSpice schematic or net list to a SapWin4 schematic.