Skip to content
LIBRARY
Sources.Cosine.md

Sources.Cosine

Generates a cosine wave with configurable parameters.

The component produces a cosine output according to:

When time < start_time, the output depends on the continuous parameter:

  • continuous = true (default): output equals offset + amplitude * cos(2π * frequency * (start_time - shift_time) + phase), ensuring value continuity at start_time (backwards compatible)

  • continuous = false: output equals offset

By default shift_time = start_time (backwards compatible). Set shift_time = 0 for absolute time reference where phase has its exact physical meaning.

Note: when shift_time = start_time, the start_time parameter introduces a hidden phase shift of 2π * frequency * start_time. Use shift_time = 0 to avoid this.

This component extends from BlockComponents.Interfaces.Signal

Usage

BlockComponents.Sources.Cosine(start_time=0.0, offset=0.0, amplitude, frequency, phase=0.0, shift_time=start_time, continuous=true)

Parameters:

NameDescriptionUnitsDefault value
start_timeTime at which the signal starts changing from its offset values0.0
offsetConstant value added to the signal output0.0
amplitudeThe peak value of the cosine wave
frequencyThe number of cycles per secondHz
phaseThe phase shift of the cosine wave in radiansrad0.0
shift_timeTime origin for the waveform (default: start_time for backwards compatibility; set to 0 for absolute time reference)sstart_time
continuousIf true, output is continuous at start_time by holding at the start value; if false, output is offset before start_timetrue

Connectors

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

Behavior

Source

dyad
"""
Generates a cosine wave with configurable parameters.

The component produces a cosine output according to:

```math
y = \text{offset} + \text{amplitude} \cdot \cos(2\pi \cdot \text{frequency} \cdot (\text{time} - \text{shift\_time}) + \text{phase})
```

When `time < start_time`, the output depends on the `continuous` parameter:
- `continuous = true` (default): output equals `offset + amplitude * cos(2π * frequency * (start_time - shift_time) + phase)`, ensuring value continuity at `start_time` (backwards compatible)
- `continuous = false`: output equals `offset`

By default `shift_time = start_time` (backwards compatible). Set `shift_time = 0` for
absolute time reference where `phase` has its exact physical meaning.

Note: when `shift_time = start_time`, the `start_time` parameter introduces a hidden
phase shift of `2π * frequency * start_time`. Use `shift_time = 0` to avoid this.
"""
component Cosine
  extends BlockComponents.Interfaces.Signal
  "The peak value of the cosine wave"
  parameter amplitude::Real
  "The number of cycles per second"
  parameter frequency::Frequency
  "The phase shift of the cosine wave in radians"
  parameter phase::Angle = 0.0
  "Time origin for the waveform (default: start_time for backwards compatibility; set to 0 for absolute time reference)"
  parameter shift_time::Time = start_time
  "If true, output is continuous at start_time by holding at the start value; if false, output is offset before start_time"
  parameter continuous::Boolean = true
relations
  y = offset + ifelse(continuous, amplitude * ifelse(time >= start_time, cos(2 * π * frequency * (time - shift_time) + phase), cos(2 * π * frequency * (start_time - shift_time) + phase)), ifelse(time >= start_time, amplitude * cos(2 * π * frequency * (time - shift_time) + phase), 0.0))
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/Cosine.svg"}
  }
}
end
Flattened Source
dyad
"""
Generates a cosine wave with configurable parameters.

The component produces a cosine output according to:

```math
y = \text{offset} + \text{amplitude} \cdot \cos(2\pi \cdot \text{frequency} \cdot (\text{time} - \text{shift\_time}) + \text{phase})
```

When `time < start_time`, the output depends on the `continuous` parameter:
- `continuous = true` (default): output equals `offset + amplitude * cos(2π * frequency * (start_time - shift_time) + phase)`, ensuring value continuity at `start_time` (backwards compatible)
- `continuous = false`: output equals `offset`

By default `shift_time = start_time` (backwards compatible). Set `shift_time = 0` for
absolute time reference where `phase` has its exact physical meaning.

Note: when `shift_time = start_time`, the `start_time` parameter introduces a hidden
phase shift of `2π * frequency * start_time`. Use `shift_time = 0` to avoid this.
"""
component Cosine
  "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
  "The peak value of the cosine wave"
  parameter amplitude::Real
  "The number of cycles per second"
  parameter frequency::Frequency
  "The phase shift of the cosine wave in radians"
  parameter phase::Angle = 0.0
  "Time origin for the waveform (default: start_time for backwards compatibility; set to 0 for absolute time reference)"
  parameter shift_time::Time = start_time
  "If true, output is continuous at start_time by holding at the start value; if false, output is offset before start_time"
  parameter continuous::Boolean = true
relations
  y = offset + ifelse(continuous, amplitude * ifelse(time >= start_time, cos(2 * π * frequency * (time - shift_time) + phase), cos(2 * π * frequency * (start_time - shift_time) + phase)), ifelse(time >= start_time, amplitude * cos(2 * π * frequency * (time - shift_time) + phase), 0.0))
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/Cosine.svg"}
  }
}
end


Test Cases

No test cases defined.