Skip to content
DerivativeIntegratorTerminatorTest.md

DerivativeIntegratorTerminatorTest

Test component that demonstrates the chained behavior of differentiation and integration of a sine signal.

This component connects a sine source through a derivative block to an integrator and finally to a terminator, demonstrating that differentiating and then integrating a signal approximately recovers the original signal. The derivative block approximates the mathematical operation d/dt, while the integrator performs the operation ∫dt. When applied in sequence to a sine wave, the output should theoretically match the input with some phase shift.

Usage

BlockComponents.DerivativeIntegratorTerminatorTest()

Behavior

[connect(source+y(t),derivative+u(t))connect(derivative+y(t),integrator+u(t))connect(integrator+y(t),terminator+u(t))dderivative.x(t)dt=derivative.u(t)derivative.x(t)derivative.Tderivative.y(t)=derivative.k(derivative.u(t)derivative.x(t))derivative.Tdintegrator.x(t)dt=integrator.kintegrator.u(t)integrator.y(t)=integrator.x(t)source.y(t)=ifelse(source.start_time<t,source.offset+source.amplitudesin(source.phase+6.2832source.frequency(source.start_time+t)),source.offset)]

Source

dyad
# Test component that demonstrates the chained behavior of differentiation and integration of a sine signal.
#
# This component connects a sine source through a derivative block to an integrator and finally to a terminator,
# demonstrating that differentiating and then integrating a signal approximately recovers the original signal.
# The derivative block approximates the mathematical operation d/dt, while the integrator performs the operation ∫dt.
# When applied in sequence to a sine wave, the output should theoretically match the input with some phase shift.
test component DerivativeIntegratorTerminatorTest
  # Approximates the derivative of the input signal with configured gain and time constant
  derivative = Derivative(k = 1, T = 0.001) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 150, "y1": 20, "x2": 250, "y2": 120, "rot": 0}
      }
    }
  }
  # Integrates the input signal with specified gain
  integrator = Integrator(k = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 280, "y1": 20, "x2": 380, "y2": 120, "rot": 0}
      }
    }
  }
  # Terminates the signal path, consuming the input without producing an output
  terminator = Terminator() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 410, "y1": 20, "x2": 510, "y2": 120, "rot": 0}
      }
    }
  }
  # Generates a sinusoidal signal with 1 Hz frequency and unit amplitude
  source = Sine(amplitude = 1, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      }
    }
  }
relations
  # Connects the sine wave output to the derivative block input
  connect(source.y, derivative.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  # Connects the derivative output to the integrator input
  connect(derivative.y, integrator.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  # Connects the integrator output to the terminator input
  connect(integrator.y, terminator.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "experiments": {},
    "tests": {
      "case1": {
        "stop": 10,
        "atol": {"integrator.y": 0.01, "terminator.u": 0.01},
        "expect": {
          "final": {"integrator.y": 0, "terminator.u": 0},
          "signals": ["integrator.y", "terminator.u"]
        }
      }
    }
  }
}
end
Flattened Source
dyad
# Test component that demonstrates the chained behavior of differentiation and integration of a sine signal.
#
# This component connects a sine source through a derivative block to an integrator and finally to a terminator,
# demonstrating that differentiating and then integrating a signal approximately recovers the original signal.
# The derivative block approximates the mathematical operation d/dt, while the integrator performs the operation ∫dt.
# When applied in sequence to a sine wave, the output should theoretically match the input with some phase shift.
test component DerivativeIntegratorTerminatorTest
  # Approximates the derivative of the input signal with configured gain and time constant
  derivative = Derivative(k = 1, T = 0.001) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 150, "y1": 20, "x2": 250, "y2": 120, "rot": 0}
      }
    }
  }
  # Integrates the input signal with specified gain
  integrator = Integrator(k = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 280, "y1": 20, "x2": 380, "y2": 120, "rot": 0}
      }
    }
  }
  # Terminates the signal path, consuming the input without producing an output
  terminator = Terminator() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 410, "y1": 20, "x2": 510, "y2": 120, "rot": 0}
      }
    }
  }
  # Generates a sinusoidal signal with 1 Hz frequency and unit amplitude
  source = Sine(amplitude = 1, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      }
    }
  }
relations
  # Connects the sine wave output to the derivative block input
  connect(source.y, derivative.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  # Connects the derivative output to the integrator input
  connect(derivative.y, integrator.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  # Connects the integrator output to the terminator input
  connect(integrator.y, terminator.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "experiments": {},
    "tests": {
      "case1": {
        "stop": 10,
        "atol": {"integrator.y": 0.01, "terminator.u": 0.01},
        "expect": {
          "final": {"integrator.y": 0, "terminator.u": 0},
          "signals": ["integrator.y", "terminator.u"]
        }
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt