BlockWerk Documentation
📊

Signal Generator

Sources

The SignalGenerator block is a versatile signal source that generates various types of time-varying signals for simulation and testing purposes. It can produce sinusoidal waves, cosine waves, square waves, sawtooth waves, and triangular waves. This block is essential for creating test signals, reference inputs, and periodic disturbances in control systems and signal processing applications.

The SignalGenerator operates as a time-based function generator, producing output signals based on the current simulation time and the configured parameters. It has no input ports and continuously outputs the generated signal to its single output port.

Simulate in BlockWerk

Interactive sandbox directly in your browser — zero installation, WASM-powered.

Simulate in BlockWerk →

Mathematical Model

The signal generator supports multiple waveform types, all sharing a common base angle θ\theta and normalized position nn:

θ(t)=2πft+ϕn(t)=(θ(t)2π) mod 1(normalized cycle position, 0≤n<1)\begin{aligned} \theta(t) &= 2\pi f t + \phi \\ n(t) &= \left( \frac{\theta(t)}{2\pi} \right) \bmod 1 \quad \text{(normalized cycle position, } 0 \le n < 1 \text{)} \end{aligned}

The output y(t)y(t) depends on the selected signalType:

y(t)=offset+{Asin⁡(θ(t)),SineAcos⁡(θ(t)),CosineA⋅sgn(dutyCycle−n(t)),SquareA(2n(t)−1),SawtoothA(1−4∣n(t)−0.5∣),Triangley(t) = \text{offset} + \begin{cases} A \sin(\theta(t)), & \text{Sine} \\ A \cos(\theta(t)), & \text{Cosine} \\ A \cdot \text{sgn}(\text{dutyCycle} - n(t)), & \text{Square} \\ A (2n(t) - 1), & \text{Sawtooth} \\ A (1 - 4|n(t) - 0.5|), & \text{Triangle} \end{cases}

Where:

  • y(t)y(t) is the output signal at time tt
  • AA is the amplitude parameter
  • ff is the frequency parameter (Hz)
  • ϕ\phi is the phase parameter (converted to radians internally)
  • offset\text{offset} is the DC offset parameter

Inputs & Outputs

Direction ID Label Type Status
→ In trigger Trigger number Optional
← Out out Signal number Output

Parameters

Parameters Label Type Default Description
signalType Signal Type select sine Type of periodic signal to generate
amplitude Amplitude number 1 Peak amplitude of the signal
frequency Frequency number 1 Signal frequency in Hertz
offset Offset number 0 DC offset added to the signal
phase Phase number 0 Initial phase offset in degrees
dutyCycle Duty Cycle number 0.5 Duty cycle for square wave (0-1)

Usage Examples

1Hz Sine Wave

Generate a basic unit-amplitude sine wave:

SignalGenerator (signalType: "sine", frequency: 1) → NumericDisplay

PWM Signal

Generate a 10Hz PWM signal with 30% duty cycle:

SignalGenerator (signalType: "square", frequency: 10, dutyCycle: 0.3) → Controller

Phase-Shifted Cosine

Two equivalent ways to generate a cosine:

SignalGenerator (signalType: "cosine", frequency: 1) → Scope
SignalGenerator (signalType: "sine", frequency: 1, phase: 90) → Scope

Remarks & Best Practices

  • Phase Convention: Phase is specified in degrees (0-360) and shifts the signal forward in time. A positive phase advances the waveform.
  • Time-Based: Signals are calculated from the current simulation time. The block is stateless — output depends only on time and parameters.
  • WASM Optimized: Implemented in Rust for high-frequency signal generation without performance lag.
  • Negative Time Handling: The normalized position uses double-modulo ((x % 1 + 1) % 1) to handle negative argument values correctly.
  • Duty Cycle Clamping: The duty cycle value is clamped to [0, 1] regardless of the input value.

Related Components