Triangular
Triangular waveform generator with configurable amplitude and frequency.
Produces a continuous triangular wave signal that oscillates between -amplitude and +amplitude values. The triangular wave is generated using modulo arithmetic on the time variable, creating a periodic signal with the specified frequency. The component begins generating the waveform only after the start_time is reached; before that point, it outputs the offset value. The period of the wave is automatically calculated as the inverse of the frequency.
This component extends from Signal
Usage
Triangular(start_time=0.0, offset=0.0, amplitude, frequency, period=1/frequency)
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 | Maximum amplitude of the triangular wave | – | |
frequency | Frequency of the triangular wave | Hz |
Connectors
y
- This connector represents a real signal as an output from a component (RealOutput
)
Behavior
Source
dyad
# Triangular waveform generator with configurable amplitude and frequency.
#
# Produces a continuous triangular wave signal that oscillates between -amplitude and
# +amplitude values. The triangular wave is generated using modulo arithmetic on the
# time variable, creating a periodic signal with the specified frequency. The component
# begins generating the waveform only after the start_time is reached; before that point,
# it outputs the offset value. The period of the wave is automatically calculated as the
# inverse of the frequency.
component Triangular
extends Signal
# Maximum amplitude of the triangular wave
parameter amplitude::Real
# Frequency of the triangular wave
parameter frequency::Frequency
# Period of the triangular wave, calculated as inverse of frequency
final parameter period::Period = 1/frequency
relations
y = if start_time<time then 4*amplitude*frequency*abs(abs(mod(time-period/4-start_time, period))-period/2)-amplitude else offset
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/Triangular.svg"}}}
end
Flattened Source
dyad
# Triangular waveform generator with configurable amplitude and frequency.
#
# Produces a continuous triangular wave signal that oscillates between -amplitude and
# +amplitude values. The triangular wave is generated using modulo arithmetic on the
# time variable, creating a periodic signal with the specified frequency. The component
# begins generating the waveform only after the start_time is reached; before that point,
# it outputs the offset value. The period of the wave is automatically calculated as the
# inverse of the frequency.
component Triangular
# 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 triangular wave
parameter amplitude::Real
# Frequency of the triangular wave
parameter frequency::Frequency
# Period of the triangular wave, calculated as inverse of frequency
final parameter period::Period = 1/frequency
relations
y = if start_time<time then 4*amplitude*frequency*abs(abs(mod(time-period/4-start_time, period))-period/2)-amplitude else offset
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/Triangular.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