Skip to content

FirstOrder(lowpass=false): documented transfer function differs from implementation for k != 1Β #515

Description

@EthanJamesLew

Describe the bug 🐞

The documented transfer function for FirstOrder(lowpass=false) differs from the implementation when k β‰ 
1.

The docstring gives (sT + 1 - k)/(sT + 1), but the component equations imply k*sT/(sT + 1).

These agree at the default k=1. For k=2, their DC gains are βˆ’1 and 0, respectively.

Expected behavior

The documentation and implementation should describe the same transfer function. I’m unsure which
behavior is intended.

Minimal Reproducible Example πŸ‘‡

using ModelingToolkit, Symbolics
  using ModelingToolkit: t_nounits as t, D_nounits as D
  using ModelingToolkitStandardLibrary.Blocks: FirstOrder, Constant

  @named input = Constant()
  @named filter = FirstOrder(lowpass=false)
  @named model = System(
      [connect(input.output, filter.input)], t;
      systems=[input, filter],
  )

  eqs = equations(expand_connections(model))
  rate = only(eq.rhs for eq in eqs if isequal(eq.lhs, D(filter.x)))
  output = only(
      eq.rhs for eq in eqs
      if isequal(eq.lhs, filter.y) &&
         any(v -> isequal(v, filter.x), Symbolics.get_variables(eq.rhs))
  )

  values = Dict(filter.u => 1, filter.x => 2, filter.k => 2, filter.T => 1)
  evaluate(expr) = Symbolics.unwrap_const(Symbolics.unwrap(
      Symbolics.simplify(Symbolics.substitute(expr, values))
  ))

  @show evaluate(rate)    # 0: the state is stationary
  @show evaluate(output)  # 0: actual output
  @show (1 - 2) * 1       # -1: documented DC gain times input

Error & Stacktrace ⚠️

No exception occurs. The discrepancy is in the output:

evaluate(rate) = 0
evaluate(output) = 0
(1 - 2) * 1 = -1

Environment (please complete the following information):

Julia 1.11.9. Relevant entries from using Pkg; Pkg.status():

βŒƒ [961ee093] ModelingToolkit v11.20.0
βŒ… [16a59e39] ModelingToolkitStandardLibrary v2.29.4
βŒƒ [0c5d862f] Symbolics v7.18.1

Additional context

Found using our formal property prover system.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions