Search code examples
matlab

Representing Electric circuits in Matlab


How can you represent electric circuits like the one I have linked in Matlab? If the nodes were connected by transfer functions instead of capacitors, inductors and resistors this could be done by a matrix. Is there some similar method to represent electric circuits to find the relationships between the currents and voltages?

Circuit diagram:

Circuit diagram


Solution

  • Sure, I do this sort of thing all the time. There's no way getting around the fact that you'll have to do some math, though.

    Use tf() to define your complex impedances (ie. 1/sC, sL, and R). Maybe write some short functions:

    • circuit_series(Z1,Z2) = Z1+Z2
    • circuit_parallel(Z1,Z2) = Z1*Z2/(Z1+Z2)
    • voltage_divider(Z1,Z2) = Z2/(Z1+Z2).

    Use MATLAB to sum up the total complex impedance seen by vi. You'll have to solve for the voltages at the intermediate nodes with the voltage divider equation before you can get to vo. Once you have the transfer function vo/vi, you can do fun things such as given an arbitrary vi waveform over time, compute the resulting vo waveform (assuming some initial conditions!).