SciML / SciML/ModelingToolkitStandardLibrary.jl
`DampedSinVoltage` output oscillates before `starttime`, `offset` doesn't work with negative `starttime`
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 171
- Forks
- 49
- Avg merge
- 15h 50m
- Merged PRs (30d)
- 10
Description
_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)

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:

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:

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the DampedSinVoltage definition and inspect its use of _step and _damped_sin_wave. Update the starttime handling so the output is zero before starttime and the offset applies from starttime, then add or run regression checks covering positive and negative starttime cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100