restart;Filters:=module() option package;
(* Package to model simple RC,CR and LRC circuits.
Usage:
The models are differential equations and should be run through dsolve.
Vin is the input voltage and can be constant (for a step response)
or a function of t (e.g. step with finite slope).
Vin needs to be integrable or the solution has to be done numerically.
*)
export RC,CR,LRC,RLCpar;
# RC is R followed by C; output is Vc (lowpass)
RC:=(Vin,R,C,t) -> Vc(t)=Vin-R*C*diff(Vc(t),t);
# CR is C followed by R, output is Vr (highpass)
CR:=(Vin,R,C,t) -> Vr(t)= R*C*(diff(Vin, t)-(diff(Vr(t), t)));
# LRC is L followed by R followed by C, output is Vc (2nd-order lowpass)
LRC:=(Vin,L,R,C,t) -> Vc(t)=Vin-L*C*diff(Vc(t),t$2)-R*C*diff(Vc(t),t);
# RLCpar is R followed by a parallel LC resonator
RLCpar:=(Vin,L,R,C,t) -> Vo(t)=L/R*(diff(Vin,t)-diff(Vo(t),t))-L*C*diff(Vo(t),t$2);
end module;
libname;LibraryTools:-Save(Filters,cat(libname[1],"/Filters.mla"));