Message Boards Message Boards

Deriving transfer equations of active filters with Wolfram Language


Today I had the opportunity to revisit an old topic for my Bachelor's degree (Op Amps) and felt the urge to see just how much can Mathematica help in the classroom for deriving equations for an application of op amps known as active filters.

For those who do not know what active filters are, as their name suggest, a filter that permits the separation of useful frequencies in a signal to pass through a system from one stage to another. They are classified according to the type of filtering that they execute: Low Pass, High Pass, Band Pass, and Band Rejection. There is an extensive amount of literature that can greatly expand on my explanations such as Electronic Devices by Floyd.

Getting started

To start off, I chose to derive the transfer equation for a second order low pass active filter. The circuit diagram is shown below. Second Order Low Pass Filter

From the field of Electronics and Electrical engineering there are great tools available to analyze the system without much difficulty. The concepts which are used are Nodal Voltage Analysis of circuits, Laplace transformation to convert from the time domain to the frequency domain and a bit of Control Theory to study the system after obtaining the equation.

Deriving the equations

For the case of op amps and active filters a couple of assumptions must be made for the analysis.

  • Input Impedance is close to infinity
  • Output Impedance is close to zero
  • The voltage difference between input terminals (V+ and V-) is zero

We start by converting the capacitors to impedances (Z) in the frequency domain.

Z1= 1 / (s c1);
Z2 = 1/ (s c2);

Establish the equations for each node (V1, V2, V3)

eq01 = (v1 - vin)/R1 + (v1 - v2)/R2 + (v1 - vout)/Z2 == 0;
eq02 = (v2 - v1)/R2 + v2/Z1 == 0;
eq03 = (v3 - vout)/R3 + v3/R4 == 0;

As mentioned earlier, the input voltage difference accross voltage terminals is zero. Thus

v2 = v3;

We now solve the system of equations

{solutionLP} = Solve[{eq01, eq02, eq03}, {v1, v2, vout}]

enter image description here

We obtain the transfer function for the system which describes the relation between output and input

H(s) = Voutput / Vinput (* Transfer function equation in control theory*)
LP = vout/vin /. {solutionLP} (* Transfer function for the Low Pass Filter *)

Let us now give values to the capacitors and resistors to simulate its behavior

parameters = {R1 -> 1000, R2 -> 1000, R3 -> 100, R4 -> 100, c1 -> 0.000001, c2 -> 0.000001}

Use the appropriate functions in Mathematica to get a transfer function model

tfLP = TransferFunctionModel[vout/vin /. {solutionLP}, s] /. parameters

enter image description here

Let us now see how the system responds to different input signals and frequencies

out01 = OutputResponse[tfLP, Sin[5000 t], t];
Plot[out01, {t, 0, 1/100}]

Output Response for Sin[5000 t]

out02 = OutputResponse[tfLP, UnitStep[t], t]
Plot[out02, {t, 0, 0.02}, PlotRange -> All]

Output Response for UnitStep[t]

We can get a more useful visualization by plotting the dB gain of the output depending on the frequency

LogLinearPlot[20 Log[Abs[tfLP[I frequency]]], {frequency, 0, 10000}]

Bode Plot

A smarter way to do the same is with a built-in function


Bode Plot 2


Overall, Mathematica proves that what could have taken me about three hours of work by hand can be done in less than ten minutes. This speeds up dramatically the process of learning about a new topic in Electronics and implementing a design for a specific problem. One can easily make several iterations of the system, coupled with other equations to obtain proper values for the passive components of the filters and simulate its response in mere seconds.

To Do

I'd love to expand a bit more on this topic, adding the equations for the others filtered mentioned. Of course more useful examples would be provided from my own notes and real world comparisons. The example shown above was created just for this demonstration and can obviously be improved as well.

5 Replies

Issac have you seen these built-in filters: Linear and Nonlinear Filters and specifically LowpassFilter ? I still think you work has educational value as you derive things from scratch. Perhaps it would also be interesting to compare your filters to built-in ones.

POSTED BY: Sam Carrettie

Hi Sam, I did not know about the existence of those functions. I'll play around with them later.

I still think you work has educational value as you derive things from scratch

I'm glad the point got accross, I made the post with the intention of showing how Mathematica can be integrated at an introductory level for Electronics. And sure, the automated functions are always faster to implement in code; my focus was to test development from the physical implementation perspective with limited values available for components (standard capacitor and resistor values).

The next step with the code is to set a Manipulate[] function which could solve the system of equations for the missing quantities and compare that to the standard equations used in Electronics to define resistor and capacitor values.

enter image description here - Congratulations! This post is now a Staff Pick as distinguished on your profile! Thank you, keep it coming! In future it is a good idea to add some meaningful outputs (as we did for formulas in your post) and possibly attach the notebook. We could not understand if meant this as a valid Wolfram Language syntax:

H(s) = Voutput / Vinput (* Transfer function equation in control theory*)
LP = vout/vin /. {solutionLP} (* Transfer function for the Low Pass Filter *)
POSTED BY: Moderation Team


Nice presentation.

You may also be interested in Wolfram SystemModeler. It will derive the equations from the circuit diagram. For more complicated circuits it is a big time saver. Also, it is well integrated with Mathematica so you can do Mathematica analysis on the equations, optimize parameters, etc. Some things are easier in Mathematica and some things are easier in SystemModeler so it is good that they are well integrated.


POSTED BY: Neil Singer

Hi Neil,

I do agree with the simplicity that SystemModeler offers, and have enjoyed using it since June. I may make a comparison for higher order filters as a followup post just to show the benefits of the object representation.

I made the example with Mathematica because it's readily available at my university (Site license) and I am preparing a proper presentation to distribute to engineering students later in the year to aid their courses which will include both products. Hope to share it with all of you soon!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract