Transfer functions

May 06, 2026 Last reply: 1 month ago 32 Replies

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.

formatting link
also used the information in the LM3900 application note (Fig 40) which was pointed out by piglet. This also calls it a Bi-quad filter.
formatting link
my own tests I used page 59 (pdf page 61) of this article:
formatting link
that I added resistor R7 to provide positive feedback between vout and the inverting input of the first op amp. This resistor was given a value of 100Meg so initially it may as well not be there.



After some online research I came across this

formatting link
I downloaded version 4 beta. The installation and activation process is annoying, but it's free and seems to work and I have no wish to complain about the authors concentrating on its function rather than its presentation or software stability. Always right click and run it as administrator from C:\SapWin4 and open your saved sch file from the File menu. Otherwise use New Circuit. My saved sch file is included below. I also included component values which are not strictly needed here if all you want is the transfer function.



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

formatting link
That led to the following python program which contains commented num and dem lines from the m file. If you look at the example transfer function you can easily see how to construct the sys line below for any transfer function produced by SapWin.



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.


<painful simulation exercise>

PSIM used to have a (limited) demo available. Google/wayback may be able to find it?

<snip>

There is a tool for doing this called Spice, which has been around for some fifty years. There's a free, and popular version of this - LTSpice

- which was first released in 1999 - which Edward Rawde has been using for years.

The "transfer function" tells you happens at an output when a stimulus is applied to an input.

Circuit simulation generalises this a bit. Spice records the state of every node in the circuit simulated for the whole length of the simulation (unless you tell it not to).

My post wasn't directed ay you Bill. It's only for people who know how to use a computer.

<snip usual misunderstandings and inability to use Google>

But it does obtain the transfer function from the schematic, which is what I wanted. And gets much faster when you've been throug it once.

This?

formatting link
'll have a look.

Can you tell me how to do something like this in LTSpice please Bill?

import sympy as sp

# Define symbolic variables s, t = sp.symbols('s t')

# Define your transfer function G(s) # Example: G(s) = 1 / (s^2 + 3s + 2)

G = 1 / (s**2 + 3*s + 2)

# Compute the inverse Laplace transform

g_t = sp.inverse_laplace_transform(G, s, t)

print(f"Time-domain function g(t): {g_t}")

Roberts has been publishing about SPICE for over 30 years. This latest text,which is free, is centered on LTSPICE. You are interested in Chapters 9 and 10.

formatting link

Anything more complicated is probably not needed. You can always use Mason's Rule(s) to consolidate multi-multi- multi- signal flow graphs, but most of that doesn't even apply to practical circuits.

formatting link

<snip>

Entertaining qualification. What did you think you had to say to them?

Edward assesses his own skills correctly.

What might you mean by "sympy?

LTSpice has its own list of symbolic variables. You don't get to define time for yourself - you have to use their built-in variable.

The does look like a Laplace transform. You can pull them out of Williams and Taylor's "Electronic Filter Design Handbook" not to mention any number of more obscure textbooks.

That's what Williams and Taylor exists to let you find.

Getting trained in the relevant math is another option. Expecting a computer to do it for you is a trifle unrealistic.

Only those who have attended Hogwarts School of Witchcraft and Wizardry would know that.

Sympy is an adjective that means "associated with symps."

John Larkin Highland Tech Glen Canyon Design Center Lunatic Fringe Electronics

Transfer functions are kind of old-fashioned. They are an invitation to do a lot of ugly algebra. And anything interesting is nonlinear.

John Larkin Highland Tech Glen Canyon Design Center Lunatic Fringe Electronics

Yes that's true, but when you do want to play with transfer functions and when they get more complex than anything you might find in a textbook, a computer algebra package makes it easy to do that which would otherwise be very error prone ugly algebra and take a long time.

So your choices would be to leave the algebra to Bill (since he has already memorised his Laplace transform table) or get a computer to do it. I know which I'd choose.

Lots of the perfectly linear stuff can be quite interesting, if unrealistic.

Far from memorising the Laplace transform tables, I took the advice of another engineer, who told me to buy a copy of Williams and Taylor who present a bunch of interesting Laplace transforms and document the consequences.

If you want frequency selective filters, that's a good place to get them.

None of the computer programs I've run into have been all that helpful. The mathematicians who put them together don't seem to know enough about circuit design to ask the users the right questions.

That's probably because you know nothing about python.

If you want software to do any kind of actual circuit design for you then good luck with that.

[Sorry, spent the day doing evaluations/assessments... I hate having to be on "normal people time"! :<]

Here's the canonical reference:

formatting link
But, it appears that their demos are now "registered" instead of just "feature limited". OTOH, their "student" licenses (free w/ registration) cover most of the products and capabilities of the "paid" licenses.

Note that it will build the phase/magnitude plot by iterating through the simulation so it can take some time (depending on how finely you want the iteration to explore the frequency domain).

MatLAB is probably the go-to tool for this sort of thing. Octave being a FOSS competitor. But, the schematic requirement may complicate that.

Your SapWin tool may, in the long run, be the better approach. Maybe take on a more active "contributor" role to help them along?

There are a bunch of electronic-design AI startups here. We get their pitches at maker-space meetups; I expect more tonight.

I haven't been impressed so far. At least the beer and pizza are free.

Allspice Ai doesn't design boards; it just reviews them. That might be useful.

John Larkin Highland Tech Glen Canyon Design Center Lunatic Fringe Electronics

I've used it before, but not do do anything python can't do now.

Also Mathcad, which still seems to still exist if you have $800/year to spare.

I don't know the extent to which python can do what Matlab can do but it must be starting to take some work away from Matlab.

In theory, any turing complete language can do anything that any other can. It's just a matter of style (and support, etc.) You'd have to look at the support libraries/frameworks available in each camp to decide where you have the best "starting point".

I am lucky (?) in that I made most of my software acquisitions under the "old" licensing style. Admittedly, older versions (how many truly significant features am I missing out on?) but I don't have to "rent" anything -- which would be REALLY annoying if I just needed to use something for a few weeks, or poke around with it periodically.

The issue I have with all FOSS "products" is that they are more "projects" than "products". No one takes ownership in the same way that a commercial vendor is required to. (PostgreSQL is a notable exception -- but, really for their Enterprise offering and for obvious reasons!)

With more than 30 years in the FOSS world (since ~1992), I've enough first-hand experience to know that "enough eyes" looking at a product does NOT ensure it is more robust or reliable than a closed product would be. Witness the number of bugs that have hidden in plain sight for years: "We also used KLEE as a bug finding tool, applying it to 452 applications (over 430K total lines of code), where it found 56 serious bugs, including three in COREUTILS that had been missed for over 15 years. Finally, we used KLEE to crosscheck purportedly identical BUSYBOX and COREUTILS utilities, finding functional correctness errors and a myriad of inconsistencies." A commercial product risks losing business if it fails to support their product(s) adequately.

If I opt to use a FOSS tool, then I make a commitment to supporting it, myself -- at least to the extent to which

*my* needs require. In this way, I can be sure the problems that *I* want fixed are "top priority" -- above and beyond the feeping creaturism that plagues much of the FOSS community.

I just had a look. The state-variable information from page 121 is interesting but it doesn't include some of the components in the circuit I posted. Probably because it would then start to get hard to fit the transfer function across one page.

It doesn't seem to include state-variable but this page is useful for fiter design

formatting link

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required