Signal Generator
Shippingsignal_generatorPeriodic waveform source: sine, square, triangle, sawtooth, pulse, DC
Signature
Outputs
signalSignal
Parameters
| Key | Type | Default | Notes |
|---|---|---|---|
waveform | enum | sine | one of: sine, square, triangle, sawtooth, pulse, dc |
frequency | float | 1.0Hz | |
amplitude | float | 1.0 | |
offset | float | 0.0 | |
phase | float | 0.0° | |
duty_cycle | float | 50% | |
symmetry | float | 50% | |
sample_rate | float | 1000.0Hz | |
duration | float | 1.0s |
Description
Signal Generator is a source node that synthesizes a periodic waveform sampled uniformly in time. It produces one output signal on port signal with no inputs. Six shapes are available via the waveform parameter: sine, square, triangle, sawtooth, pulse, and dc. The generated waveform is , where is amplitude, is offset, and is the selected shape evaluated at the running phase with frequency , sample rate , and initial phase .
The time grid is fully specified by sample_rate and duration: the output holds samples at spacing . phase is entered in degrees and converted to radians internally; duty_cycle and symmetry are entered as percentages (0-100) and converted to 0-1 fractions internally. duty_cycle sets the high fraction of a period for square/pulse; symmetry sets the rising-edge fraction for triangle. For dc, frequency and phase are ignored and the output is the constant (plus where applicable).
The node is stateless: it holds no accumulator or persistent phase between runs, so each evaluation reproduces the same buffer for identical parameters. The output carries no measurement uncertainty (the waveform is a deterministic mathematical construct, ); amplitude and offset are dimensionless magnitudes, while frequency, sample_rate (Hz) and duration (s) define the physical time axis. To inject stochastic error, sum this signal with noise_generator.
Mathematics
Examples
A 1 kHz sine sampled at audio rate
Set waveform = sine, frequency = 1000, amplitude = 1.0, sample_rate = 48000, duration = 0.5. This yields samples of , i.e. a clean tone with 48 samples per cycle. Feed signal directly into fft to recover a single spectral line at 1 kHz, or into audio_output to hear it.
Asymmetric pulse train for a PWM stimulus
For a 25%-duty control pulse: waveform = pulse, frequency = 50, duty_cycle = 25, amplitude = 1.0, offset = 0. Each 20 ms period is high for the first 5 ms and low for the remaining 15 ms.
period = 1 / 50 Hz = 20 ms
high = 0.25 * 20 ms = 5 ms
low = 15 msApplications
- Generating reference tones and sweeps to characterize filters, amplifiers, and audio chains (drive an `iir_filter` or `fft` and measure the response).
- Producing deterministic test stimuli (square, pulse, sawtooth) for control-loop, PWM, and digital-logic simulation via `schmitt_trigger` or `comparator`.
- Building synthetic ground-truth signals for validating detection and analysis algorithms such as `peak_detection`, `envelope`, or `derivative`.
- Teaching and demonstrating sampling, aliasing, and Fourier concepts by pairing controlled `frequency`/`sample_rate` ratios with spectral nodes.
Neat
Choosing `frequency` close to or above `sample_rate / 2` deliberately produces aliasing, making the node a compact demonstrator of the Nyquist limit: a 900 Hz sine at $f_s = 1000$ Hz folds back to an apparent 100 Hz tone.
`triangle` and `sawtooth` are the same family: a triangle with `symmetry = 100` (all rising edge) is a rising ramp, and `symmetry = 0` is a falling ramp, so the sawtooth is the degenerate limit of the symmetry control.
Known issues
The sample count is $N = \lfloor f_s \cdot \text{duration}\rfloor$; when $f_s \cdot T$ is non-integer the final fractional sample is truncated, so the emitted duration can be slightly shorter than requested.
Non-band-limited shapes (`square`, `sawtooth`, `pulse`, sharp `triangle`) contain harmonics extending past Nyquist; at modest `sample_rate` these fold back as aliasing artifacts on the ideal edges.