Pulse
Periodic pulse generator with configurable amplitude, period, and duty cycle.
Generates a square wave that alternates between amplitude and offset values. The signal stays at amplitude value for duty_cycle × period duration and at offset value for the remainder of each period. The period starts at start_time and repeats indefinitely.
This component extends from Signal
Usage
Pulse(start_time=0.0, offset=0.0, amplitude, duty_cycle, period)
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 value of the pulse signal | – | |
duty_cycle | Fraction of the period during which output equals amplitude (between 0 and 1) | – | |
period | Time between consecutive pulses | s |
Connectors
y
- This connector represents a real signal as an output from a component (RealOutput
)
Behavior
Source
dyad
# Periodic pulse generator with configurable amplitude, period, and duty cycle.
#
# Generates a square wave that alternates between amplitude and offset values. The signal stays
# at amplitude value for duty_cycle × period duration and at offset value for the remainder of
# each period. The period starts at start_time and repeats indefinitely.
#
# ```math
# y(t) = \begin{cases}
# \text{amplitude}, & \text{if } t > \text{start\_time} \text{ and } t \leq \text{start\_time} + \text{duty\_cycle} \times \text{period} \pmod{\text{period}} \\
# \text{offset}, & \text{otherwise}
# \end{cases}
# ```
component Pulse
extends Signal
# Maximum value of the pulse signal
parameter amplitude::Real
# Fraction of the period during which output equals amplitude (between 0 and 1)
parameter duty_cycle::Real
# Time between consecutive pulses
parameter period::Time
relations
y = if time>start_time then if time<=start_time+duty_cycle*period then amplitude else offset else offset
end
Flattened Source
dyad
# Periodic pulse generator with configurable amplitude, period, and duty cycle.
#
# Generates a square wave that alternates between amplitude and offset values. The signal stays
# at amplitude value for duty_cycle × period duration and at offset value for the remainder of
# each period. The period starts at start_time and repeats indefinitely.
#
# ```math
# y(t) = \begin{cases}
# \text{amplitude}, & \text{if } t > \text{start\_time} \text{ and } t \leq \text{start\_time} + \text{duty\_cycle} \times \text{period} \pmod{\text{period}} \\
# \text{offset}, & \text{otherwise}
# \end{cases}
# ```
component Pulse
# 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 value of the pulse signal
parameter amplitude::Real
# Fraction of the period during which output equals amplitude (between 0 and 1)
parameter duty_cycle::Real
# Time between consecutive pulses
parameter period::Time
relations
y = if time>start_time then if time<=start_time+duty_cycle*period then amplitude else offset else offset
metadata {}
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