Signal Generator
SourcesThe 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.
Mathematical Model
The signal generator supports multiple waveform types, all sharing a common base angle and normalized position :
The output depends on the selected signalType:
Where:
- is the output signal at time
- is the amplitude parameter
- is the frequency parameter (Hz)
- is the phase parameter (converted to radians internally)
- 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) → ScopeRemarks & 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
timeand 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
- PulseGenerator: For unipolar pulses
- Constant: For steady DC signals
- Step: For a single transition event