Transient analysis
A transient analysis will attempt to include as many effects possible. The unfortunate consequence is that this type of simulation is also by far the slowest. Luckily, it is relatively straightforward to use.
Let's use our low-pass RC filter from before and apply a pulsed voltage source.
// Build the circuit
var ckt = new Circuit(
new VoltageSource("V1", "in", "0", new Pulse(0.0, 5.0, 0.01, 1e-3, 1e-3, 0.02, 0.04)),
new Resistor("R1", "in", "out", 10.0e3),
new Capacitor("C1", "out", "0", 1e-6)
);
// Create the simulation
var tran = new Transient("Tran 1", 1e-3, 0.1);
// Make the exports
var inputExport = new RealVoltageExport(tran, "in");
var outputExport = new RealVoltageExport(tran, "out");
// Simulate
foreach (int _ in tran.Run(ckt, Transient.ExportTransient))
{
double input = inputExport.Value;
double output = outputExport.Value;
}
The voltage source now is passed a Pulse object that will calculate the voltage in time for us.
The Transient simulation expects a timestep that will be used to calculate the initial timestep for the simulation, and a final time that tells the analysis the last time point to simulate.
The resulting waveforms look as follows:
Note that Spice 3f5 will simulate the same thing if you feed it the following netlist.
Transient example
V1 in 0 PULSE(0 5 10m 1m 1m 20m 40m)
R1 in out 10k
C1 out 0 1u
.TRAN 1m 0.1
* Export voltages/currents/etc.
.END