I am modeling a capacitor which has its capacitance varying according to the DC Bias. The DC Bias is computed by taking the mean of the voltage across the capacitance.
class CAP: """ Represents the Capacitor. """ def __init__(self, nominal_capacitance): # Theoretical capacitance without DC Bias (i.e. voltage mean at 0) self.nominal_capacitance = nominal_capacitance # uF # Actual capacitance, initialized at the nominal value self.capacitance = nominal_capacitance # uF # Voltage control loop settings self.set_voltage_value = None # Value set in mV self.set_lower_voltage_window_bound = None # Window upper bound in mV self.set_upper_voltage_window_bound = None # Window lower bound in mV self.voltage = 0 # Voltage across the capacitor self.being_charge = False # Is it being charged/discharged by the control loop? # Measurements self.charge_counter = 0 self.discharge_counter = 0 self.voltage_charged = 0 self.voltage_discharged = 0 # List of the voltage across the capacitance self.timeline =  # mV def update_capacitance(self): """ Value according to the DC Bias characterstic approximation. """ global timelines_resolution # time step between 2 voltages measurements in the list self.timeline DC_bias = np.mean(self.timeline) / 1000 change_perc = (-0.0008*(DC_bias**4)+0.0474*(DC_bias**3)-0.7953*(DC_bias**2)-0.5447*DC_bias-0.4847)/100 self.capacitance = self.nominal_capacitance * (1+change_perc)
The voltage across the capacitance is controlled via a control loop which will recharge or discharge the capacitor. The goal is to keep its voltage within boundaries (window).
self.timeline will have one measure point (voltage) added every
timelines_resolution. I can get between 200 000 points to a few millions.
The conversion to a numpy array and the mean computation become quite long. On the otherhand, it is handy to work with a list and its
append method since I do not know beforehand the number of point that will be measured.
Do you see any other way to compute this DC Bias or to make this faster?
At the moment, I call the function
update_capacitance every 25000 points. I would like to increase this resolution.