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 | | +––––––+
Usage
CosineVariableFrequencyAndAmplitude(phi0=0, offset=0)
Parameters:
Name | Description | Units | Default value |
---|---|---|---|
phi0 | Initial phase of the cosine wave | – | 0 |
offset | Offset of the cosine wave | – | 0 |
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
Name | Description | Units |
---|---|---|
phi | Phase of the cosine wave | rad |
Behavior
Source
# 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": {"x1": -50, "y1": 250, "x2": 50, "y2": 350}}}}]
# Input port for the frequency of the cosine wave in Hz
frequency = RealInput() [{"Dyad": {"placement": {"icon": {"x1": -50, "y1": 650, "x2": 50, "y2": 750}}}}]
# Output port for the resulting cosine waveform
y = RealOutput() [{"Dyad": {"placement": {"icon": {"x1": 950, "y1": 450, "x2": 750, "y2": 550}}}}]
# 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)
end
Flattened Source
# 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": {"x1": -50, "y1": 250, "x2": 50, "y2": 350}}}}]
# Input port for the frequency of the cosine wave in Hz
frequency = RealInput() [{"Dyad": {"placement": {"icon": {"x1": -50, "y1": 650, "x2": 50, "y2": 750}}}}]
# Output port for the resulting cosine waveform
y = RealOutput() [{"Dyad": {"placement": {"icon": {"x1": 950, "y1": 450, "x2": 750, "y2": 550}}}}]
# 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 {}
end
Test Cases
This is setup code, that must be run before each test case.
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