Skip to content
Square.md

Square ​

Square wave generator that alternates between positive and negative values.

Generates a square wave signal that oscillates between offset+amplitude and offset-amplitude at the specified frequency. The square wave is generated using floor functions to create the periodic pattern. The output is held at the offset value until the start time is reached, after which the oscillation begins. The signal transitions instantaneously between high and low states.

This component extends from Signal

Usage ​

BlockComponents.Square(start_time=0.0, offset=0.0, amplitude, frequency)

Parameters: ​

NameDescriptionUnitsDefault value
start_timeTime at which the signal starts changing from its offset values0
offsetConstant value added to the signal output–0
amplitudeMaximum height of the square wave from zero (or from offset if specified)–
frequencyFrequency of the square wave oscillationHz

Connectors ​

  • y - This connector represents a real signal as an output from a component (RealOutput)

Behavior ​

y(t)=ifelse(start_time<t,offset+amplitude(1−2⌊2frequency(−start_time+t)⌋+4⌊frequency(−start_time+t)⌋),offset)

Source ​

dyad
"""
Square wave generator that alternates between positive and negative values.

Generates a square wave signal that oscillates between `offset+amplitude` and `offset-amplitude`
at the specified frequency. The square wave is generated using floor functions to create the
periodic pattern. The output is held at the offset value until the start time is reached, after
which the oscillation begins. The signal transitions instantaneously between high and low states.
"""
component Square
  extends Signal
  "Maximum height of the square wave from zero (or from offset if specified)"
  parameter amplitude::Real
  "Frequency of the square wave oscillation"
  parameter frequency::Frequency
relations
  y = ifelse(start_time < time, offset + (amplitude * (4 * floor(frequency * (time - start_time)) - 2 * floor(2 * (time - start_time) * frequency) + 1)), offset)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/Square.svg"}
  }
}
end
Flattened Source
dyad
"""
Square wave generator that alternates between positive and negative values.

Generates a square wave signal that oscillates between `offset+amplitude` and `offset-amplitude`
at the specified frequency. The square wave is generated using floor functions to create the
periodic pattern. The output is held at the offset value until the start time is reached, after
which the oscillation begins. The signal transitions instantaneously between high and low states.
"""
component Square
  "Real-valued output connector for the component"
  y = RealOutput() {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0},
        "diagram": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
      }
    }
  }
  "Time at which the signal starts changing from its offset value"
  parameter start_time::Time = 0.0
  "Constant value added to the signal output"
  parameter offset::Real = 0.0
  "Maximum height of the square wave from zero (or from offset if specified)"
  parameter amplitude::Real
  "Frequency of the square wave oscillation"
  parameter frequency::Frequency
relations
  y = ifelse(start_time < time, offset + (amplitude * (4 * floor(frequency * (time - start_time)) - 2 * floor(2 * (time - start_time) * frequency) + 1)), offset)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/Square.svg"}
  }
}
end


Test Cases ​

No test cases defined.