Class ZeroCrossings
Computes the Zero Crossings (ZC) feature for each channel in a windowed input signal.
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:
{
"ZC": {
"Type": "ZeroCrossings",
"Inputs": [ "SlidingWindow1" ],
"Params": [ 0.01 ],
"DesiredRate": 100,
"Path": "C:/Data/session1"
}
}
Params:
| Index | Description |
|---|---|
| 0 |
Threshold (double, optional). Minimum absolute difference between consecutive
samples to count a zero crossing. Defaults to 0.0.
|
How Type, Inputs and Params work · Block catalogue and parameter reference
Implements
Inherited Members
Namespace: MOSAIC.Models.FlowControl
Assembly: MOSAIC.dll
Syntax
public class ZeroCrossings : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks
Formula: ZC = Σ sgn(−x[n] × x[n+1]) where |x[n] − x[n+1]| ≥ threshold.
Input: A MathNet.Numerics.LinearAlgebra.Matrix<T> of double where rows represent samples and columns represent channels (typically from an upstream SlidingWindow block).
Output: A MathNet.Numerics.LinearAlgebra.Vector<T> of double containing one ZC count per channel, published to all downstream subscribers.
Threshold: The configurable Threshold parameter suppresses noise by requiring the absolute difference between consecutive samples to exceed a minimum magnitude before counting a zero crossing. A threshold of 0 counts all sign changes through zero.
Zero Crossings is a simple frequency-domain proxy — higher ZC counts indicate higher dominant frequency content in the signal.
CSV logging: When a Path is specified, Dumper
automatically logs the output vector via Publish(object).
Constructors
ZeroCrossings(string, double, double)
Initializes a new ZeroCrossings block.
Declaration
public ZeroCrossings(string name, double threshold = 0, double desiredRate = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Display name of the block. |
| double | threshold | Minimum difference threshold for noise suppression. |
| double | desiredRate | Desired processing rate in Hz (typically inherited). |
Fields
_outputChannels
Gets the number of output channels, determined from the column count of the input matrix.
Declaration
[ObservableProperty]
private int _outputChannels
Field Value
| Type | Description |
|---|---|
| int |
_threshold
Gets or sets the minimum amplitude difference threshold for noise suppression. Consecutive samples must differ by at least this amount to count as a zero crossing.
Declaration
[ObservableProperty]
private double _threshold
Field Value
| Type | Description |
|---|---|
| double |
_windowSize
Gets the window size (row count) from the most recent input matrix.
Declaration
[ObservableProperty]
private int _windowSize
Field Value
| Type | Description |
|---|---|
| int |
Properties
DumpFilePrefix
Recordings from this block are named <block>_zc.csv.
Declaration
protected override string DumpFilePrefix { get; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
JsonTypeName
Block type identifier for JSON serialization. Override for a custom name.
Declaration
protected override string JsonTypeName { get; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
OutputChannels
Gets the number of output channels, determined from the column count of the input matrix.
Declaration
[ExcludeFromCodeCoverage]
public int OutputChannels { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Threshold
Gets or sets the minimum amplitude difference threshold for noise suppression. Consecutive samples must differ by at least this amount to count as a zero crossing.
Declaration
[ExcludeFromCodeCoverage]
public double Threshold { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
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 helper for binding the ZC output to the UI scope.
Declaration
public BlockVisualization? Viz { get; }
Property Value
| Type | Description |
|---|---|
| BlockVisualization |
WindowSize
Gets the window size (row count) from the most recent input matrix.
Declaration
[ExcludeFromCodeCoverage]
public int WindowSize { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
ConfigureInput(IServiceProvider, JsonModel)
Creates a ZeroCrossings from a JSON pipeline definition.
Declaration
public static ZeroCrossings ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceProvider | sp | Service provider for dependency injection. |
| JsonModel | m | JSON model. |
Returns
| Type | Description |
|---|---|
| ZeroCrossings | A configured ZeroCrossings 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
OnOutputChannelsChanged(int)
Executes the logic for when OutputChannels just changed.
Declaration
private void OnOutputChannelsChanged(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The new property value that was set. |
Remarks
This method is invoked right after the value of OutputChannels is changed.
OnOutputChannelsChanged(int, int)
Executes the logic for when OutputChannels just changed.
Declaration
private void OnOutputChannelsChanged(int oldValue, int newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| int | oldValue | The previous property value that was replaced. |
| int | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of OutputChannels is changed.
OnOutputChannelsChanging(int)
Executes the logic for when OutputChannels is changing.
Declaration
private void OnOutputChannelsChanging(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The new property value being set. |
Remarks
This method is invoked right before the value of OutputChannels is changed.
OnOutputChannelsChanging(int, int)
Executes the logic for when OutputChannels is changing.
Declaration
private void OnOutputChannelsChanging(int oldValue, int newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| int | oldValue | The previous property value that is being replaced. |
| int | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of OutputChannels is changed.
OnReceive(object, object?)
Processes an incoming windowed matrix and publishes the computed ZC vector.
Declaration
protected override void OnReceive(object sender, object? value)
Parameters
| Type | Name | Description |
|---|---|---|
| object | sender | The upstream block. |
| object | value | Expected to be a MathNet.Numerics.LinearAlgebra.Matrix<T> of double (rows = samples, columns = channels). Non-matrix inputs are rejected and reported through ReportError(string, Exception?); activity status remains automatic. |
Overrides
Remarks
For each channel, the algorithm iterates consecutive sample pairs and counts positions where the sign changes (one positive, one negative), provided the absolute difference exceeds Threshold.
OnThresholdChanged(double)
Executes the logic for when Threshold just changed.
Declaration
private void OnThresholdChanged(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The new property value that was set. |
Remarks
This method is invoked right after the value of Threshold is changed.
OnThresholdChanged(double, double)
Executes the logic for when Threshold just changed.
Declaration
private void OnThresholdChanged(double oldValue, double newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| double | oldValue | The previous property value that was replaced. |
| double | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of Threshold is changed.
OnThresholdChanging(double)
Executes the logic for when Threshold is changing.
Declaration
private void OnThresholdChanging(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The new property value being set. |
Remarks
This method is invoked right before the value of Threshold is changed.
OnThresholdChanging(double, double)
Executes the logic for when Threshold is changing.
Declaration
private void OnThresholdChanging(double oldValue, double newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| double | oldValue | The previous property value that is being replaced. |
| double | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of Threshold is changed.
OnWindowSizeChanged(int)
Executes the logic for when WindowSize just changed.
Declaration
private void OnWindowSizeChanged(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The new property value that was set. |
Remarks
This method is invoked right after the value of WindowSize is changed.
OnWindowSizeChanged(int, int)
Executes the logic for when WindowSize just changed.
Declaration
private void OnWindowSizeChanged(int oldValue, int newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| int | oldValue | The previous property value that was replaced. |
| int | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of WindowSize is changed.
OnWindowSizeChanging(int)
Executes the logic for when WindowSize is changing.
Declaration
private void OnWindowSizeChanging(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The new property value being set. |
Remarks
This method is invoked right before the value of WindowSize is changed.
OnWindowSizeChanging(int, int)
Executes the logic for when WindowSize is changing.
Declaration
private void OnWindowSizeChanging(int oldValue, int newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| int | oldValue | The previous property value that is being replaced. |
| int | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of WindowSize is changed.