Open
Description
The following construct is equivalent to delaying a signal by 2 samples. but the result is that the output is constantly zero. The expected output is a step from 0 to 1 at t=4.
delay(k) ~ input(k - 1)
Hold(delay(k-1))
using ModelingToolkit: t_nounits as t, D_nounits as D
k = ShiftIndex(Clock(t, 1))
@mtkmodel DelayModel begin
@variables begin
input(t) = 0
delay(t) = 0
x(t) = 0
end
@equations begin
input ~ (t >= 2)
delay(k) ~ input(k - 1)
D(x) ~ (-x + Hold(delay(k-1))) / 1e-3
end
end
@mtkbuild m = DelayModel()
prob = ODEProblem(
m, [m.delay(k - 3) => 0, m.delay(k - 2) => 0, m.delay(k - 1) => 0], (0.0, 10.0))
sol = solve(prob, Tsit5(), kwargshandle = KeywordArgSilent, dtmax = 0.5)
plot(sol, idxs=m.x)