Skip to content
ExpSine.md

ExpSine

Exponentially damped sine wave with configurable amplitude, frequency, and damping.

Generates a sinusoidal signal that exponentially decays over time based on the damping coefficient. The signal remains at the offset value until the start time is reached, after which it follows the equation:

y(t)=offset+amplitudeedamping(ttstart)sin(2πfrequency(ttstart)+phase)

This component extends from Signal

Usage

ExpSine(start_time=0.0, offset=0.0, amplitude, damping, frequency, phase)

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 sine wave
dampingCoefficient controlling how quickly the sine wave decayss-1
frequencyFrequency of the sine wave oscillationHz
phasePhase angle offset of the sine wave in radiansrad

Connectors

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

Behavior

y(t)=ifelse(start_time<t,offset+amplitudeedamping(start_time+t)sin(phase+6.2832frequency(start_time+t)),offset)

Source

dyad
# Exponentially damped sine wave with configurable amplitude, frequency, and damping.
#
# Generates a sinusoidal signal that exponentially decays over time based on the damping coefficient.
# The signal remains at the offset value until the start time is reached, after which it follows the
# equation:
#
# ```math
# y(t) = \text{offset} + \text{amplitude} \cdot e^{-\text{damping}\cdot(t-t_{\text{start}})} \cdot \sin(2\pi \cdot \text{frequency} \cdot (t-t_{\text{start}}) + \text{phase})
# ```
component ExpSine
  extends Signal
  # Maximum amplitude of the sine wave
  parameter amplitude::Real
  # Coefficient controlling how quickly the sine wave decays
  parameter damping::DampingCoefficient
  # Frequency of the sine wave oscillation
  parameter frequency::Frequency
  # Phase angle offset of the sine wave in radians
  parameter phase::Angle
relations
  y = if start_time<time then offset+amplitude*exp(-damping*(time-start_time))*sin(2*π*frequency*(time-start_time)+phase) else offset
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/ExpSine.svg"}}}
end
Flattened Source
dyad
# Exponentially damped sine wave with configurable amplitude, frequency, and damping.
#
# Generates a sinusoidal signal that exponentially decays over time based on the damping coefficient.
# The signal remains at the offset value until the start time is reached, after which it follows the
# equation:
#
# ```math
# y(t) = \text{offset} + \text{amplitude} \cdot e^{-\text{damping}\cdot(t-t_{\text{start}})} \cdot \sin(2\pi \cdot \text{frequency} \cdot (t-t_{\text{start}}) + \text{phase})
# ```
component ExpSine
  # Real-valued output connector for the component
  y = RealOutput() [{"Dyad": {"placement": {"icon": {"x1": 950, "y1": 450, "x2": 1050, "y2": 550}}}}]
  # 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 sine wave
  parameter amplitude::Real
  # Coefficient controlling how quickly the sine wave decays
  parameter damping::DampingCoefficient
  # Frequency of the sine wave oscillation
  parameter frequency::Frequency
  # Phase angle offset of the sine wave in radians
  parameter phase::Angle
relations
  y = if start_time<time then offset+amplitude*exp(-damping*(time-start_time))*sin(2*π*frequency*(time-start_time)+phase) else offset
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/ExpSine.svg"}}}
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"