ModelingToolkitStandardLibrary.jl icon indicating copy to clipboard operation
ModelingToolkitStandardLibrary.jl copied to clipboard

`DampedSinVoltage` output oscillates before `starttime`, `offset` doesn't work with negative `starttime`

Open AayushSabharwal opened this issue 3 years ago • 1 comments

_step(t, δ, 1.0, st) doesn't actually become 0 before st, and instead asymptotically converges there. This works fine for stepping functions such as _cos_wave, but _damped_sin_wave oscillations grow too fast (exponentially in the reverse direction). Hence, the actual output turns into something like this (plots from Desmos)

image

starttime is set to be 10 here, so it is expected the output would be constantly 0 before then but it isn't.


Additionally, the offset applied to the voltage of DampedSinVoltage doesn't respect starttime. The offset is only applied at t>=0, and hence if starttime is negative with a non-zero offset it leads to the following:

image

This is with offset=3.3 and starttime=-2.8

This is fixable by changing: v ~ _step(t, δ, o, 0.0) + _damped_sine_wave(t, f, A, st, ϕ, d) * _step(t, δ, 1.0, st) to: v ~ _step(t, δ, o, st) + _damped_sine_wave(t, f, A, st, ϕ, d) * _step(t, δ, 1.0, st)

Resulting in the following: image

AayushSabharwal avatar Dec 09 '21 07:12 AayushSabharwal

Yeah, this is an oversight. _step should've had st. I'll fix this

ven-k avatar Dec 23 '21 07:12 ven-k