Cosine
Generates a cosine wave with configurable parameters.
A signal generator that produces a cosine wave with the equation
when time exceeds start_time, otherwise outputs the offset value. The component allows setting the wave's amplitude, frequency, phase shift and vertical offset.
This component extends from Signal
Usage
Cosine(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 | The peak value of the cosine wave | – | |
frequency | The number of cycles per second | Hz | |
phase | The phase shift of the cosine wave in radians | rad | 0 |
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.
#
# A signal generator that produces a cosine wave with the equation
#
# ```math
# y(t) = offset + amplitude \cdot \cos(2\pi \cdot frequency \cdot (t-start\_time) + phase)
# ```
#
# when time exceeds start_time, otherwise outputs the offset value. The component allows setting
# the wave's amplitude, frequency, phase shift and vertical offset.
component Cosine
extends 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
relations
y = if start_time<time then offset+amplitude*cos(2*π*frequency*(time-start_time)+phase) else offset
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/Cosine.svg"}}}
end
Flattened Source
dyad
# Generates a cosine wave with configurable parameters.
#
# A signal generator that produces a cosine wave with the equation
#
# ```math
# y(t) = offset + amplitude \cdot \cos(2\pi \cdot frequency \cdot (t-start\_time) + phase)
# ```
#
# when time exceeds start_time, otherwise outputs the offset value. The component allows setting
# the wave's amplitude, frequency, phase shift and vertical offset.
component Cosine
# 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
# 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
relations
y = if start_time<time then offset+amplitude*cos(2*π*frequency*(time-start_time)+phase) else offset
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/Cosine.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