Skip to content
SquareTest.md

SquareTest

Connects a square wave generator to an integrator to test integration of a periodic signal.

This component demonstrates the integration of a square wave over time. It connects a Square signal generator (with amplitude 1, frequency 2 Hz, start time 0.5 seconds, and offset 0.7) to an Integrator block. The square wave alternates between values of 0.7 and 1.7, and when integrated, should reach approximately 3.537 at t=5 seconds.

Usage

SquareTest()

Behavior

signal.y(t)=integrator.u(t)dintegrator.x(t)dt=integrator.kintegrator.u(t)integrator.y(t)=integrator.x(t)signal.y(t)=ifelse(signal.start_time<t,signal.offset+signal.amplitude(1+4signal.frequency(signal.start_time+t)22signal.frequency(signal.start_time+t)),signal.offset)

Source

dyad
# Connects a square wave generator to an integrator to test integration of a periodic signal.
#
# This component demonstrates the integration of a square wave over time. It connects a Square
# signal generator (with amplitude 1, frequency 2 Hz, start time 0.5 seconds, and offset 0.7)
# to an Integrator block. The square wave alternates between values of 0.7 and 1.7, and when
# integrated, should reach approximately 3.537 at t=5 seconds.
test component SquareTest
  # Integrator block that accumulates the square wave input
  integrator = Integrator()
  # Square wave generator with specified amplitude, frequency, start time and offset
  signal = Square(amplitude=1, frequency=2, start_time=0.5, offset=0.7)
relations
  connect(signal.y, integrator.u)
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 5,
        "atol": {"integrator.x": 0.001},
        "expect": {
          "initial": {"signal.y": 0.7},
          "signals": ["signal.y", "integrator.x"],
          "final": {"signal.y": 1.7, "integrator.x": 3.53706}
        }
      }
    }
  }
}
end
Flattened Source
dyad
# Connects a square wave generator to an integrator to test integration of a periodic signal.
#
# This component demonstrates the integration of a square wave over time. It connects a Square
# signal generator (with amplitude 1, frequency 2 Hz, start time 0.5 seconds, and offset 0.7)
# to an Integrator block. The square wave alternates between values of 0.7 and 1.7, and when
# integrated, should reach approximately 3.537 at t=5 seconds.
test component SquareTest
  # Integrator block that accumulates the square wave input
  integrator = Integrator()
  # Square wave generator with specified amplitude, frequency, start time and offset
  signal = Square(amplitude=1, frequency=2, start_time=0.5, offset=0.7)
relations
  connect(signal.y, integrator.u)
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 5,
        "atol": {"integrator.x": 0.001},
        "expect": {
          "initial": {"signal.y": 0.7},
          "signals": ["signal.y", "integrator.x"],
          "final": {"signal.y": 1.7, "integrator.x": 3.53706}
        }
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt