Integrator
Circuit description
An integrator in measurement and control applications is an element whose output signal is the time integral of its input signal. It accumulates the input quantity over a defined time to produce a representative output.
Goals
- Calculate integrator response
- Calculate integrator response for
R1=R2=R3=R
Modeling the circuit
First we include Symbolics.jl
and CircuitS
.
using Symbolics
include("../CircuitS.jl")
The we create the circuit and add all of the elements as shown in the picture above:
circuit = create_circuit()
add_element([Resistor, "R1", 1, 3], circuit)
add_element([Resistor, "R2", 4, 5], circuit)
add_element([Resistor, "R3", 5, 2], circuit)
add_element([Capacitor, "C", 3, 4, "U0"], circuit)
add_element([Voltage, "Ug", 1, 0], circuit)
add_element([OpAmp, "OpAmp1", [3, 0], 2], circuit)
add_element([OpAmp, "OpAmp2", [0, 5], 4], circuit)
Simulation
After we've built everything, we initialise and simulate the circuit:
init_circuit(circuit)
result = simulate(circuit)
println(result)
Dict{Any, Any} with 8 entries:
"V5" => 0
"V3" => 0
"V2" => (R3*Ug + C*R1*R3*U0) / (C*R1*R2*s)
"I_OpAmp2" => (-Ug - C*R1*U0 - C*R2*Ug*s) / (-C*R1*R2*s)
"V4" => (-Ug - C*R1*U0) / (C*R1*s)
"I_Ug" => Ug / (-R1)
"I_OpAmp1" => (-Ug - C*R1*U0) / (C*R1*R2*s)
"V1" => Ug
Integrator response is the voltage of node 2:
println(result["V2"])
(R3*Ug + C*R1*R3*U0) / (C*R1*R2*s)
We can replace replace R1=R2=R3=R
the classic way, before the simulation:
@variables R1 R2 R3 R
init_circuit(circuit, Dict([R1=>R, R2=>R, R3=>R]))
result = simulate(circuit)
println(result["V2"])
(Ug + C*R*U0) / (C*R*s)
Or we can do it post simulation with JuliaSymbolics substitute function:
init_circuit(circuit)
result = simulate(circuit)
@variables R1 R2 R3 R
V2 = result["V2"]
V2 = SymbolicUtils.substitute(V2~0,Dict([R1=>R, R2=>R, R3=>R]))
V2 = simplify(V2, expand=true)
println(V2)
We recommend applying the replacements before the simulation as it makes the MNA equations less complex and it decreases the chances of JuliaSymbolics simplify failure.