Class SinGenerator
Synthetic signal source that generates d sinusoidal components with configurable
amplitude, frequency, and per-channel phase offsets.
JSON configuration
Use these block entries inside a pipeline configuration. Input names must match other blocks in that pipeline; device addresses and file paths must match your setup.
JSON configuration:
{
"SinWave": {
"Type": "SinGenerator",
"Inputs": [ "Clock" ],
"DesiredRate": 200,
"Params": [ 8, 1.0, 0.2, 0.0, 10.0 ],
"Path": "C:/Data/session1"
}
}
Params:
| Index | Description |
|---|---|
| 0 | ComponentCount (int, default 1) — number of sine channels. |
| 1 | Amplitude (double, default 1.0). |
| 2 | Frequency (double, default 0.2) — Hz. |
| 3 | Phase (double, default 0.0) — base phase offset in radians. |
| 4 | PhaseStep (double, default 10.0) — inter-channel phase step in radians. |
How Type, Inputs and Params work · Block catalogue and parameter reference
Implements
Inherited Members
Namespace: MOSAIC.Models.Streaming
Assembly: MOSAIC.dll
Syntax
public class SinGenerator : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks
Overview: On each tick from an upstream ClockBlock,
the generator evaluates A × sin(2π·f·t + φ₀ + i·Δφ) for each component i,
where t is derived from a jitter-free sample counter, A = Amplitude,
f = Frequency, φ₀ = Phase,
and Δφ = PhaseStep.
Time base: Rather than relying on wall-clock timestamps (which suffer from jitter
and can alias high-frequency signals), time is computed as sampleIndex / sampleRate
using DesiredRate (falls back to 1000 Hz if unset).
Source block: This block is driven by a clock tick (double timestamp) on OnReceive(object, object), not by upstream data.
CSV logging: When a Path is specified, Dumper
automatically logs the generated signal vector via Publish(object).
Constructors
SinGenerator(string, double, int, double, double, double, double, int)
Initializes a new SinGenerator block.
Declaration
public SinGenerator(string name = "Sin", double desiredRate = 0, int componentCount = 1, double amplitude = 1, double frequency = 0.2, double phase = 0, double phaseStep = 10, int scansPerPacket = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Display name. |
| double | desiredRate | Tick rate in Hz (typically inherited from a clock). |
| int | componentCount | Number of sine channels. Must be ≥ 1. |
| double | amplitude | Signal amplitude. |
| double | frequency | Signal frequency in Hz. |
| double | phase | Base phase offset in radians. |
| double | phaseStep | Inter-channel phase step in radians. |
| int | scansPerPacket |
Fields
_amplitude
Amplitude of the sine waves.
Declaration
private double _amplitude
Field Value
| Type | Description |
|---|---|
| double |
_componentCount
Number of sine components (channels).
Declaration
private int _componentCount
Field Value
| Type | Description |
|---|---|
| int |
_dt
Declaration
private double _dt
Field Value
| Type | Description |
|---|---|
| double |
_frequency
Frequency in Hz.
Declaration
private double _frequency
Field Value
| Type | Description |
|---|---|
| double |
_omega
Precomputed angular frequency (2π·f).
Declaration
private double _omega
Field Value
| Type | Description |
|---|---|
| double |
_phase
Base phase offset in radians (applied to the first component).
Declaration
private double _phase
Field Value
| Type | Description |
|---|---|
| double |
_phaseStep
Phase step between consecutive components in radians.
Declaration
private double _phaseStep
Field Value
| Type | Description |
|---|---|
| double |
_sampleIndex
Sample counter for jitter-free phase accumulation.
Declaration
private long _sampleIndex
Field Value
| Type | Description |
|---|---|
| long |
_scansPerPacket
Samples generated per tick. One (the default) publishes a MathNet.Numerics.LinearAlgebra.Vector<T> as before; more publishes a MathNet.Numerics.LinearAlgebra.Matrix<T> of rows = samples, columns = components.
Declaration
private int _scansPerPacket
Field Value
| Type | Description |
|---|---|
| int |
Remarks
Above one this block emits the same shape a packetised device does — for example
MccDaq with its ScansPerPacket — at a true sample rate of
tickRate × ScansPerPacket while still publishing once per tick. That path needed a rig
to exercise before, so it could not be checked on a desk.
The phase runs continuously across packet boundaries, so a dropped, duplicated or reordered packet appears as a kink in an otherwise clean sine. Set Frequency to a whole number of hertz and count cycles against the scope's time axis: ten seconds of a 1 Hz sine is ten cycles, and any other count means the axis is wrong by exactly that ratio.
_settingsLock
Declaration
private readonly object _settingsLock
Field Value
| Type | Description |
|---|---|
| object |
_signal
Reusable buffer for the most recently generated signal.
Declaration
private Vector<double> _signal
Field Value
| Type | Description |
|---|---|
| Vector<double> |
Properties
AllowableBlocks
Type names this block accepts as inputs, or an empty array when it accepts any.
Declaration
public override string[] AllowableBlocks { get; }
Property Value
| Type | Description |
|---|---|
| string[] | Upstream runtime class names, as checked by BlockConstraints. Empty means unrestricted. |
Overrides
Remarks
Advisory metadata for the pipeline builder, which uses it to grey out incompatible sources while a connection is being dragged. Not enforced at run time — a config that wires an unlisted block in still builds.
Amplitude
Declaration
public double Amplitude { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
ComponentCount
Declaration
public int ComponentCount { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
DumpFilePrefix
Recordings from this block are named <block>_sin.csv.
Declaration
protected override string DumpFilePrefix { get; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
Frequency
Declaration
public double Frequency { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
JsonTypeName
Block type identifier for JSON serialization. Override for a custom name.
Declaration
protected override string JsonTypeName { get; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
Phase
Declaration
public double Phase { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
PhaseStep
Declaration
public double PhaseStep { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
SampleRate
True sample rate of the generated signal: one tick yields ScansPerPacket samples.
Declaration
public double SampleRate { get; }
Property Value
| Type | Description |
|---|---|
| double |
Remarks
Distinct from the tick rate whenever a packet carries more than one sample, and it is this rate — not the tick rate — that the time base and the scope both need.
ScansPerPacket
Declaration
public int ScansPerPacket { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
TransformsSignalRate
True when this block produces a new sample spacing (for example resampling).
Declaration
protected override bool TransformsSignalRate { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Overrides
Visualization
This block's visualization, or null when it has none.
Declaration
protected override BlockVisualization? Visualization { get; }
Property Value
| Type | Description |
|---|---|
| BlockVisualization |
Overrides
Remarks
Blocks own their scope as a public Viz property rather than inheriting one, so the
base class has no way to reach it. Overriding this is what lets the rate below be wired up
automatically. With correct publication metadata, the bundle derives the time axis for
one vector per publication or fixed-size contiguous sample packets from the feed shape.
When a plot needs a rate that publication frequency and feed shape cannot express (for
example, variable-sized packets or overlapping windows), declare it with
Viz.UpdateSignalRate. An explicit declaration wins over the derived rate. A block
with several bundles must configure each one; this hook exposes only one bundle.
Viz
Visualization scope for the generated signal.
Declaration
public BlockVisualization Viz { get; set; }
Property Value
| Type | Description |
|---|---|
| BlockVisualization |
Methods
ConfigureInput(IServiceProvider, JsonModel)
Creates a SinGenerator from a JSON pipeline definition.
Declaration
public static SinGenerator ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceProvider | sp | Service provider for dependency injection. |
| JsonModel | m | JSON model. See the class-level example for |
Returns
| Type | Description |
|---|---|
| SinGenerator | A configured SinGenerator instance. |
Dispose()
Releases visualization and base class resources (including CSV dumper if configured).
Declaration
public override void Dispose()
Overrides
GetJsonParams()
Block-specific parameters for JSON. Override to provide custom parameters.
Declaration
protected override IReadOnlyList<object>? GetJsonParams()
Returns
| Type | Description |
|---|---|
| IReadOnlyList<object> | The values for Params, in the order this block's |
Overrides
OnComponentCountChanged(int)
Resizes the signal buffer when component count changes.
Declaration
private void OnComponentCountChanged(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value |
OnDesiredRateChanged(double, double)
Called when DesiredRate changes. Override to react (e.g. rebuild filters).
Declaration
protected override void OnDesiredRateChanged(double oldRate, double newRate)
Parameters
| Type | Name | Description |
|---|---|---|
| double | oldRate | The previous rate in Hz; |
| double | newRate | The new rate in Hz. Always greater than |
Overrides
OnFrequencyChanged(double)
Recomputes angular frequency when frequency changes.
Declaration
private void OnFrequencyChanged(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value |
OnInputRateChanged(double)
Called when InputRate changes. Override to recalculate output rate.
Declaration
protected override void OnInputRateChanged(double newInputRate)
Parameters
| Type | Name | Description |
|---|---|---|
| double | newInputRate | The rate in Hz at which the upstream block now publishes. |
Overrides
OnReceive(object, object)
Evaluates all sine components at the current sample index and publishes the result.
Declaration
protected override void OnReceive(object sender, object tNow)
Parameters
| Type | Name | Description |
|---|---|---|
| object | sender | The upstream clock block. |
| object | tNow | Current time in seconds (double) — unused, sample counter provides the time base. |
Overrides
Remarks
Time is computed as sampleIndex / sampleRate rather than from the upstream
timestamp to eliminate wall-clock jitter that would alias high-frequency signals.
OnScansPerPacketChanged(int)
Re-derives the time base when the packet size changes at runtime.
Declaration
private void OnScansPerPacketChanged(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value |
RefreshTimeBase()
Republishes the sample rate to the sample spacing, the block graph and the local scope.
Declaration
private void RefreshTimeBase()
Remarks
The scope has to be told separately: SignalRate travels along the block graph for downstream DSP, but nothing carries it into the local visualization. And it must be given the sample rate rather than the tick rate, because the scope advances its x-axis once per row written and OnReceive(object, object) writes every row of the packet.