Sine
Generates a sine wave signal with configurable parameters.
The component produces a sinusoidal output according to:
When time is less than start_time
, the output equals the offset
value.
This component extends from Signal
Usage
Sine(start_time=0.0, offset=0.0, amplitude, frequency, phase=0.0)
Parameters:
Name | Description | Units | Default value |
---|---|---|---|
start_time | Time at which the signal starts changing from its offset value | s | 0 |
offset | Constant value added to the signal output | – | 0 |
amplitude | Peak value of the sine wave | – | |
frequency | Number of cycles per time unit | Hz | |
phase | Angular displacement of the sine wave at start time | rad | 0 |
Connectors
y
- This connector represents a real signal as an output from a component (RealOutput
)
Behavior
Source
dyad
# Generates a sine wave signal with configurable parameters.
#
# The component produces a sinusoidal output according to:
#
# ```math
# y = \text{offset} + \text{amplitude} \cdot \sin(2\pi \cdot \text{frequency} \cdot (\text{time} - \text{start\_time}) + \text{phase})
# ```
#
# When time is less than `start_time`, the output equals the `offset` value.
component Sine
extends Signal
# Peak value of the sine wave
parameter amplitude::Real
# Number of cycles per time unit
parameter frequency::Frequency
# Angular displacement of the sine wave at start time
parameter phase::Angle = 0.0
relations
# Output equation that generates the sine wave when time exceeds start_time
y = if start_time<time then offset+amplitude*sin(2*π*frequency*(time-start_time)+phase) else offset
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/Sine.svg"}}}
end
Flattened Source
dyad
# Generates a sine wave signal with configurable parameters.
#
# The component produces a sinusoidal output according to:
#
# ```math
# y = \text{offset} + \text{amplitude} \cdot \sin(2\pi \cdot \text{frequency} \cdot (\text{time} - \text{start\_time}) + \text{phase})
# ```
#
# When time is less than `start_time`, the output equals the `offset` value.
component Sine
# 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
# Peak value of the sine wave
parameter amplitude::Real
# Number of cycles per time unit
parameter frequency::Frequency
# Angular displacement of the sine wave at start time
parameter phase::Angle = 0.0
relations
# Output equation that generates the sine wave when time exceeds start_time
y = if start_time<time then offset+amplitude*sin(2*π*frequency*(time-start_time)+phase) else offset
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/Sine.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"
Related
Examples
Experiments
Analyses
Tests