Modelling a variable (i.e. nonlinear) capacitor in Simulink: how to make it stable?
Show older comments
I am modelling a variable capacitor, which is described by the following nonlinear equation:
. To implement this, I have been taking the standard approach of measuring the current i through the variable capacitor, integrating it to get the charge Q, and then dividing it by the capacitance
at that time instant (necessary, since the capacitance varies) to get the voltage V across the capacitor, and then finally feeding that into a Controlled Voltage Source to generate that instantaneous voltage. See the image below for what this looks like in Simulink, and a well-done similar implementation on the FileExchange.
While this approach is relatively straightforward and simple, it is extremely sensitive and will produce voltages that approach infinity at the beginning of simulations. Even if I try saturating the output voltage (or alternatively, saturating the integrator), I still get unrealistic results. The only thing that makes it run "correctly" is making the sample time
incredibly small, on the order of
, which of course makes the simulation very slow and generates many data points (sometimes causing Simulink to crash). I should note that even at these small sample times, the voltage across the variable capacitor is unrealistically noisy. I have tried a number of other tricks but to no avail:
incredibly small, on the order of - Initializing the integrator and the voltage source (and other elements in the larger circuit that this variable capacitor is a part of)
- Trying a continuous vs. discrete integrator
- Using a unit delay (or transfer function as advised by Guy on Simulink in this post)
- Using ode15s or other nonlinear solvers
- Making the capacitance
a static value for several seconds to let the circuit settle into a steady-state before varying it
Note that
is generated by a Sine Wave block and is never equal to zero.
I am guessing this is a broader issue pertinent to other applications, since I am feeding a measured quantity directly into an integrator, and the Current Measurement block has no reference for currents prior to simulation beginning (like the "chicken vs. egg").
Does anyone have any tips on how to either model variable capacitors or more generally, make integrators less sensitive? Thank you!

7 Comments
Sam Chak
on 19 Jul 2022
David Skrovanek
on 19 Jul 2022
Edited: David Skrovanek
on 19 Jul 2022
Jon
on 19 Jul 2022
How do you compute C(t)? If it is given by an equation please provide the equation, if it is from a data file please attach a listing of the C vs t values you are feeding into your simulation
David Skrovanek
on 19 Jul 2022
Jon
on 19 Jul 2022
What is the load across the capacitor (a simple resistor, some more complicated circuit)?
David Skrovanek
on 19 Jul 2022
Sam Chak
on 20 Jul 2022
If your capacitance
is varying with time, then you can include it in the dynamical RC circuit model as an exogenous variable.
Accepted Answer
More Answers (0)
Categories
Find more on Electrical Sensors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


