Skip to content
SineVariableFrequencyAndAmplitude.md

SineVariableFrequencyAndAmplitude

Sine voltage source with adjustable frequency and amplitude through external signals.

Generates a sine wave whose amplitude and frequency can be controlled dynamically through input connections. The component integrates the input frequency to compute the phase angle, then uses this phase to produce a sine wave output signal. The output formula is:

y=offset+amplitudesin(phi)

where phi evolves according to der(phi) = 2*π*frequency. This allows for creating time-varying oscillating signals with controllable parameters.

|                amplitude
|                    ↓
|                 +-----+
|   frequency --→ |     | --→ y
|                 +-----+

Usage

SineVariableFrequencyAndAmplitude(phi0=0, offset=0)

Parameters:

NameDescriptionUnitsDefault value
phi0Initial phase of the sine wave0
offsetOffset of the sine 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 sine waverad

Behavior

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

Source

dyad
# Sine voltage source with adjustable frequency and amplitude through external signals.
#
# Generates a sine wave whose amplitude and frequency can be controlled dynamically through
# input connections. The component integrates the input frequency to compute the phase angle,
# then uses this phase to produce a sine wave output signal. The output formula is:
#
# ```math
# y = offset + amplitude*sin(phi)
# ```
# where phi evolves according to `der(phi) = 2*π*frequency`. This allows for creating time-varying
# oscillating signals with controllable parameters.
#
# ```
# |                amplitude
# |                    ↓
# |                 +-----+
# |   frequency --→ |     | --→ y
# |                 +-----+
# ```
component SineVariableFrequencyAndAmplitude
  # Input for controlling the amplitude of the sine wave
  amplitude = RealInput() [{"Dyad": {"placement": {"icon": {"x1": -50, "y1": 250, "x2": 50, "y2": 350}}}}]
  # Input for controlling the frequency of the sine wave
  frequency = RealInput() [{"Dyad": {"placement": {"icon": {"x1": -50, "y1": 650, "x2": 50, "y2": 750}}}}]
  # Output representing the resulting sine wave signal
  y = RealOutput() [{"Dyad": {"placement": {"icon": {"x1": 950, "y1": 450, "x2": 750, "y2": 550}}}}]
  # Initial phase of the sine wave
  parameter phi0::Real = 0
  # Offset of the sine wave
  parameter offset::Real = 0
  # Phase of the sine wave
  variable phi::Angle
relations
  initial phi = phi0
  der(phi) = 2*π*frequency
  y = offset+amplitude*sin(phi)
end
Flattened Source
dyad
# Sine voltage source with adjustable frequency and amplitude through external signals.
#
# Generates a sine wave whose amplitude and frequency can be controlled dynamically through
# input connections. The component integrates the input frequency to compute the phase angle,
# then uses this phase to produce a sine wave output signal. The output formula is:
#
# ```math
# y = offset + amplitude*sin(phi)
# ```
# where phi evolves according to `der(phi) = 2*π*frequency`. This allows for creating time-varying
# oscillating signals with controllable parameters.
#
# ```
# |                amplitude
# |                    ↓
# |                 +-----+
# |   frequency --→ |     | --→ y
# |                 +-----+
# ```
component SineVariableFrequencyAndAmplitude
  # Input for controlling the amplitude of the sine wave
  amplitude = RealInput() [{"Dyad": {"placement": {"icon": {"x1": -50, "y1": 250, "x2": 50, "y2": 350}}}}]
  # Input for controlling the frequency of the sine wave
  frequency = RealInput() [{"Dyad": {"placement": {"icon": {"x1": -50, "y1": 650, "x2": 50, "y2": 750}}}}]
  # Output representing the resulting sine wave signal
  y = RealOutput() [{"Dyad": {"placement": {"icon": {"x1": 950, "y1": 450, "x2": 750, "y2": 550}}}}]
  # Initial phase of the sine wave
  parameter phi0::Real = 0
  # Offset of the sine wave
  parameter offset::Real = 0
  # Phase of the sine wave
  variable phi::Angle
relations
  initial phi = phi0
  der(phi) = 2*π*frequency
  y = offset+amplitude*sin(phi)
metadata {}
end


Test Cases

This is setup code, that must be run before each test case.

julia
using BlockComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames

snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")
"/home/actions-runner-10/.julia/packages/BlockComponents/77kIK/test/snapshots"