Signal Generator
SourcesThe SignalGenerator block produces standard time-varying periodic waveforms for simulation excitation, dynamic frequency-response characterization, and hardware-in-the-loop (HIL) testing. It can generate sinusoidal, cosine, bipolar square, linear sawtooth, and symmetric triangular waveforms. The block features intuitive engineering parameterization—peak amplitude, frequency in Hertz, DC offset, initial phase in degrees, and square-wave duty cycle—along with an optional external reset trigger port.
Mathematical Model
Let be the frequency in Hertz, the initial phase angle in radians, and the current continuous simulation time. The total phase angle is defined as:
The normalized cycle position is evaluated via modulo arithmetic:
The output signal is evaluated based on the selected signalType, scaled by peak amplitude and shifted by DC offset :
where is the configured dutyCycle (), and evaluates to for and for .
When an external rising edge is detected on the optional trigger port (), the internal time counter resets to .
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
Example 1: Sinusoidal Excitation for Bode Frequency Response Identification
Subjecting a mechanical flexible arm to swept sinusoidal excitation to identify resonance frequencies. Configuring signalType = "sine", frequency = 25.0 Hz, amplitude = 2.0 N, and offset = 0.0. Feeding the output into an actuator model and measuring output acceleration across frequency steps enables empirical Bode magnitude and phase reconstruction.
Example 2: Bipolar Square Wave PWM Chopper with Phase Lead
Generating a bipolar reference command for an electrical drive test with signalType = "square", frequency = 50.0 Hz (), amplitude = 12.0 V, dutyCycle = 0.75 (high for , low for ), and phase = 45.0 degrees. This produces a calibrated periodic switching waveform for inductive coil current analysis.
Remarks & Best Practices
- Nyquist-Shannon Sampling Requirement: To ensure numerical accuracy and avoid aliasing distortion, the simulation time step must satisfy . In practice, use at least 20 to 50 solver steps per waveform cycle ().
- Stateless Continuous Time Evaluation: Implemented in Rust/WASM as a stateless time-dependent algebraic generator, preventing drift across long multi-hour simulation runs.
- Bipolar vs. Unipolar Output: Unlike the unipolar
PulseGenerator(which alternates between and ),SignalGeneratorin square mode produces a bipolar waveform oscillating between and around the DC offset. - Negative Time Resilience: Uses double-modulo normalization internally to maintain continuous waveform integrity even if time reference reverses during solver backtracking.
Related Components
- PulseGenerator: Unipolar pulse train generator with pulse-count limit and duty cycle in percent.
- Step: Generates a single Heaviside step transition.
- Ramp: Unbounded linearly increasing time ramp.
- Clock: Monotonically increasing continuous simulation time source.