Skip to content
Triangular.md

Triangular

Triangular waveform generator with configurable amplitude and frequency.

Produces a continuous triangular wave signal that oscillates between -amplitude and +amplitude values. The triangular wave is generated using modulo arithmetic on the time variable, creating a periodic signal with the specified frequency. The component begins generating the waveform only after the start_time is reached; before that point, it outputs the offset value. The period of the wave is automatically calculated as the inverse of the frequency.

This component extends from Signal

Usage

BlockComponents.Triangular(start_time=0.0, offset=0.0, amplitude, frequency, period=1 / frequency)

Parameters:

NameDescriptionUnitsDefault value
start_timeTime at which the signal starts changing from its offset values0
offsetConstant value added to the signal output0
amplitudeMaximum amplitude of the triangular wave
frequencyFrequency of the triangular waveHz

Connectors

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

Behavior

y(t)=ifelse(start_time<t,amplitude+4amplitudefrequency|12period+|mod(14periodstart_time+t,period)||,offset)

Source

dyad
# Triangular waveform generator with configurable amplitude and frequency.
#
# Produces a continuous triangular wave signal that oscillates between -amplitude and
# +amplitude values. The triangular wave is generated using modulo arithmetic on the
# time variable, creating a periodic signal with the specified frequency. The component
# begins generating the waveform only after the start_time is reached; before that point,
# it outputs the offset value. The period of the wave is automatically calculated as the
# inverse of the frequency.
component Triangular
  extends Signal
  # Maximum amplitude of the triangular wave
  parameter amplitude::Real
  # Frequency of the triangular wave
  parameter frequency::Frequency
  # Period of the triangular wave, calculated as inverse of frequency
  final parameter period::Period = 1 / frequency
relations
  y = ifelse(start_time < time, 4 * amplitude * frequency * abs(abs(mod(time - period / 4 - start_time, period)) - period / 2) - amplitude, offset)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/Triangular.svg"}
  }
}
end
Flattened Source
dyad
# Triangular waveform generator with configurable amplitude and frequency.
#
# Produces a continuous triangular wave signal that oscillates between -amplitude and
# +amplitude values. The triangular wave is generated using modulo arithmetic on the
# time variable, creating a periodic signal with the specified frequency. The component
# begins generating the waveform only after the start_time is reached; before that point,
# it outputs the offset value. The period of the wave is automatically calculated as the
# inverse of the frequency.
component Triangular
  # 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 amplitude of the triangular wave
  parameter amplitude::Real
  # Frequency of the triangular wave
  parameter frequency::Frequency
  # Period of the triangular wave, calculated as inverse of frequency
  final parameter period::Period = 1 / frequency
relations
  y = ifelse(start_time < time, 4 * amplitude * frequency * abs(abs(mod(time - period / 4 - start_time, period)) - period / 2) - amplitude, offset)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/Triangular.svg"}
  }
}
end


Test Cases

No test cases defined.