Skip to content
Pulse.md

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.

y(t)={amplitude,if t>start_time and tstart_time+duty_cycle×period(modperiod)offset,otherwise

This component extends from Signal

Usage

Pulse(start_time=0.0, offset=0.0, amplitude, duty_cycle, period)

Parameters:

NameDescriptionUnitsDefault value
start_timeTime at which the signal starts changing from its offset values0
offsetConstant value added to the signal output0
amplitudeMaximum value of the pulse signal
duty_cycleFraction of the period during which output equals amplitude (between 0 and 1)
periodTime between consecutive pulsess

Connectors

  • y - This connector represents a real signal as an output from a component (RealOutput)

Behavior

y(t)=ifelse(t>start_time,ifelse(tstart_time+duty_cycleperiod,amplitude,offset),offset)

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"