Skip to content
CosineVariableFrequencyAndAmplitude.md

CosineVariableFrequencyAndAmplitude

Cosine voltage source with variable frequency and amplitude

Variable cosine generator with externally controlled amplitude and frequency inputs. The component generates a cosine waveform based on integration of the frequency input:

+––––––+ | amplitude | +––-+–––+ | v +––––––+ | | | Cosine +––> y | Generator | | | +––––––+ ^ | +––-+–––+ | frequency | +––––––+

dϕdt=2πfrequencyy=offset+amplitudecos(ϕ)

Usage

BlockComponents.CosineVariableFrequencyAndAmplitude(phi0=0, offset=0)

Parameters:

NameDescriptionUnitsDefault value
phi0Initial phase of the cosine wave0
offsetOffset of the cosine wave0

Connectors

  • amplitude - This connector represents a real signal as an input to a component (RealInput)

  • frequency - This connector represents a real signal as an input to a component (RealInput)

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

Variables

NameDescriptionUnits
phiPhase of the cosine waverad

Behavior

dphi(t)dt=6.2832frequency(t)y(t)=offset+cos(phi(t))amplitude(t)

Source

dyad
# Cosine voltage source with variable frequency and amplitude
#
# Variable cosine generator with externally controlled amplitude and frequency inputs.
# The component generates a cosine waveform based on integration of the frequency input:
#
# +------------+
# | amplitude  |
# +-----+------+
# |
# v
# +------------+
# |            |
# |  Cosine    +----> y
# | Generator  |
# |            |
# +------------+
# ^
# |
# +-----+------+
# | frequency  |
# +------------+
#
# ```math
# \frac{d\phi}{dt} = 2\pi \cdot frequency
# ```
#
# ```math
# y = offset + amplitude \cdot \cos(\phi)
# ```
component CosineVariableFrequencyAndAmplitude
  # Input port for the amplitude of the cosine wave
  amplitude = RealInput() {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": -100, "y1": 190, "x2": 0, "y2": 290, "rot": 0},
        "diagram": {"iconName": "default", "x1": -100, "y1": 190, "x2": 0, "y2": 290, "rot": 0}
      }
    }
  }
  # Input port for the frequency of the cosine wave in Hz
  frequency = RealInput() {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": -100, "y1": 680, "x2": 0, "y2": 780, "rot": 0},
        "diagram": {"iconName": "default", "x1": -100, "y1": 680, "x2": 0, "y2": 780, "rot": 0}
      }
    }
  }
  # Output port for the resulting cosine waveform
  y = RealOutput() {
    "Dyad": {
      "placement": {
        "icon": {
          "iconName": "default",
          "x1": 1100,
          "y1": 450,
          "x2": 1000,
          "y2": 550,
          "rot": 180
        },
        "diagram": {
          "iconName": "default",
          "x1": 1100,
          "y1": 450,
          "x2": 1000,
          "y2": 550,
          "rot": 180
        }
      }
    }
  }
  # Initial phase of the cosine wave
  parameter phi0::Real = 0
  # Offset of the cosine wave
  parameter offset::Real = 0
  # Phase of the cosine wave
  variable phi::Angle
relations
  initial phi = phi0
  der(phi) = 2 * π * frequency
  y = offset + amplitude * cos(phi)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/CosineVariableFrequencyAndAmplitude.svg"}
  }
}
end
Flattened Source
dyad
# Cosine voltage source with variable frequency and amplitude
#
# Variable cosine generator with externally controlled amplitude and frequency inputs.
# The component generates a cosine waveform based on integration of the frequency input:
#
# +------------+
# | amplitude  |
# +-----+------+
# |
# v
# +------------+
# |            |
# |  Cosine    +----> y
# | Generator  |
# |            |
# +------------+
# ^
# |
# +-----+------+
# | frequency  |
# +------------+
#
# ```math
# \frac{d\phi}{dt} = 2\pi \cdot frequency
# ```
#
# ```math
# y = offset + amplitude \cdot \cos(\phi)
# ```
component CosineVariableFrequencyAndAmplitude
  # Input port for the amplitude of the cosine wave
  amplitude = RealInput() {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": -100, "y1": 190, "x2": 0, "y2": 290, "rot": 0},
        "diagram": {"iconName": "default", "x1": -100, "y1": 190, "x2": 0, "y2": 290, "rot": 0}
      }
    }
  }
  # Input port for the frequency of the cosine wave in Hz
  frequency = RealInput() {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": -100, "y1": 680, "x2": 0, "y2": 780, "rot": 0},
        "diagram": {"iconName": "default", "x1": -100, "y1": 680, "x2": 0, "y2": 780, "rot": 0}
      }
    }
  }
  # Output port for the resulting cosine waveform
  y = RealOutput() {
    "Dyad": {
      "placement": {
        "icon": {
          "iconName": "default",
          "x1": 1100,
          "y1": 450,
          "x2": 1000,
          "y2": 550,
          "rot": 180
        },
        "diagram": {
          "iconName": "default",
          "x1": 1100,
          "y1": 450,
          "x2": 1000,
          "y2": 550,
          "rot": 180
        }
      }
    }
  }
  # Initial phase of the cosine wave
  parameter phi0::Real = 0
  # Offset of the cosine wave
  parameter offset::Real = 0
  # Phase of the cosine wave
  variable phi::Angle
relations
  initial phi = phi0
  der(phi) = 2 * π * frequency
  y = offset + amplitude * cos(phi)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/CosineVariableFrequencyAndAmplitude.svg"}
  }
}
end


Test Cases

No test cases defined.