Before doing analog filter design with DSP, beware of analogfilter design seems to be broken · Issue #341 · JuliaDSP/DSP.jl · GitHub
TLDR; analog filter design is quite broken in DSP but the problem can be worked around.
Having said that, here’s how you can convert a filter to an MTK system with the PR #843
using DSP, ControlSystemsBase
# Digital filter
fs = 100
df = digitalfilter(Bandpass(5, 10; fs), Butterworth(2))
G = tf(df, 1/fs)
bodeplot(G, xscale=:identity, yscale=:identity, hz=true)
# Analog filter
af = analogfilter(Bandpass(0.05, 0.30), Butterworth(2))
G = tf(af)
bodeplot(G, xscale=:identity, yscale=:identity, hz=true)
# Convert to statespace for simulation with MTK
sys = ss(G) # This performs numerical scaling automatically
using ControlSystemsMTK
odesys = ODESystem(sys; name=:filter)
The resulting odesys
will have connectors input::RealInput
and output::RealOutput
from ModelingToolkitStandardLibrary.