Class MetricsExtractor
Computes amplitude/error metrics 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:
{
"MyMetrics": {
"Type": "MetricExtractor",
"Inputs": [ "SlidingWindow1" ],
"Params": [ "RMS" ],
"DesiredRate": 100
}
}
Params:
| Index | Description |
|---|---|
| 0 |
Metric type (string). One of: RMS, MAV, IEMG, SSI,
VAR, STD, LOG, PEAK, P2P, MEAN, ZSCORE.
Case-insensitive. Defaults to RMS if omitted.
|
How Type, Inputs and Params work · Block catalogue and parameter reference
Implements
Inherited Members
Namespace: MOSAIC.Models.Analytics
Assembly: MOSAIC.dll
Syntax
public class MetricsExtractor : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks
Input: A MathNet.Numerics.LinearAlgebra.Matrix<T> of double where rows represent samples and columns represent channels (typically produced by an upstream SlidingWindow block).
Output: A MathNet.Numerics.LinearAlgebra.Vector<T> of double containing one metric value per channel, published to all downstream subscribers.
The metric to compute is selected via the Metric property and defaults to RMS. Supported metrics include RMS, MAV, IEMG, SSI, VAR, STD, LOG, PEAK, P2P, MEAN, and ZSCORE.
Window size and overlap are controlled entirely by the upstream SlidingWindow block, keeping this block focused on the metric computation itself.
Constructors
MetricsExtractor(string, MetricType, double)
Initializes a new MetricsExtractor with the specified name, metric type, and optional desired rate.
Declaration
public MetricsExtractor(string name, MetricType metric = MetricType.RMS, double desiredRate = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | |
| MetricType | metric | |
| double | desiredRate |
Fields
_metric
Gets or sets the metric type to compute.
Declaration
[ObservableProperty]
private MetricType _metric
Field Value
| Type | Description |
|---|---|
| MetricType |
_outputChannels
Gets the number of output channels, determined from the column count of the first input matrix received.
Declaration
[ObservableProperty]
private int _outputChannels
Field Value
| Type | Description |
|---|---|
| int |
_windowSize
Gets the window size (row count) from the most recent input matrix.
Declaration
[ObservableProperty]
private int _windowSize
Field Value
| Type | Description |
|---|---|
| int |
Properties
JsonTypeName
Block type identifier for JSON serialization. Override for a custom name.
Declaration
protected override string JsonTypeName { get; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
Metric
Gets or sets the metric type to compute.
Declaration
[ExcludeFromCodeCoverage]
public MetricType Metric { get; set; }
Property Value
| Type | Description |
|---|---|
| MetricType |
OutputChannels
Gets the number of output channels, determined from the column count of the first input matrix received.
Declaration
[ExcludeFromCodeCoverage]
public int OutputChannels { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
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
Scope for visualizing the output signal in the UI.
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
ComputeIEMG(Matrix<double>, int, int)
Computes Integrated EMG (sum of absolute values): Σ|x|.
Declaration
private static double ComputeIEMG(Matrix<double> window, int col, int rows)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | window | |
| int | col | |
| int | rows |
Returns
| Type | Description |
|---|---|
| double |
ComputeLOG(Matrix<double>, int, int)
Computes Log Detector: e^(Σlog|x|/N).
Declaration
private static double ComputeLOG(Matrix<double> window, int col, int rows)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | window | |
| int | col | |
| int | rows |
Returns
| Type | Description |
|---|---|
| double |
ComputeMAV(Matrix<double>, int, int)
Computes Mean Absolute Value: Σ|x|/N.
Declaration
private static double ComputeMAV(Matrix<double> window, int col, int rows)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | window | |
| int | col | |
| int | rows |
Returns
| Type | Description |
|---|---|
| double |
ComputeMEAN(Matrix<double>, int, int)
Computes arithmetic Mean: Σx/N.
Declaration
private static double ComputeMEAN(Matrix<double> window, int col, int rows)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | window | |
| int | col | |
| int | rows |
Returns
| Type | Description |
|---|---|
| double |
ComputeMetric(Matrix<double>, int, int)
Dispatches metric computation for all channels based on the current Metric setting.
Declaration
private Vector<double> ComputeMetric(Matrix<double> window, int rows, int cols)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | window | |
| int | rows | |
| int | cols |
Returns
| Type | Description |
|---|---|
| Vector<double> |
ComputeP2P(Matrix<double>, int, int)
Computes Peak-to-Peak: max(x) − min(x).
Declaration
private static double ComputeP2P(Matrix<double> window, int col, int rows)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | window | |
| int | col | |
| int | rows |
Returns
| Type | Description |
|---|---|
| double |
ComputePEAK(Matrix<double>, int, int)
Computes Peak (maximum absolute value): max(|x|).
Declaration
private static double ComputePEAK(Matrix<double> window, int col, int rows)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | window | |
| int | col | |
| int | rows |
Returns
| Type | Description |
|---|---|
| double |
ComputeRMS(Matrix<double>, int, int)
Computes Root Mean Square: √(Σx²/N).
Declaration
private static double ComputeRMS(Matrix<double> window, int col, int rows)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | window | |
| int | col | |
| int | rows |
Returns
| Type | Description |
|---|---|
| double |
ComputeSSI(Matrix<double>, int, int)
Computes Simple Square Integral: Σx².
Declaration
private static double ComputeSSI(Matrix<double> window, int col, int rows)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | window | |
| int | col | |
| int | rows |
Returns
| Type | Description |
|---|---|
| double |
ComputeSTD(Matrix<double>, int, int)
Computes Standard Deviation: √(Σ(x−μ)²/N) (population standard deviation).
Declaration
private static double ComputeSTD(Matrix<double> window, int col, int rows)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | window | |
| int | col | |
| int | rows |
Returns
| Type | Description |
|---|---|
| double |
ComputeVAR(Matrix<double>, int, int)
Computes Variance: Σ(x−μ)²/N (population variance).
Declaration
private static double ComputeVAR(Matrix<double> window, int col, int rows)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | window | |
| int | col | |
| int | rows |
Returns
| Type | Description |
|---|---|
| double |
ComputeZSCORE(Matrix<double>, int, int)
Computes Z-Score of the last sample relative to the window:
(x[N-1] − μ) / σ where μ and σ are computed over the full window.
Declaration
private static double ComputeZSCORE(Matrix<double> window, int col, int rows)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | window | |
| int | col | |
| int | rows |
Returns
| Type | Description |
|---|---|
| double |
Remarks
Returns 0 if the standard deviation is effectively zero (constant signal).
ConfigureInput(IServiceProvider, JsonModel)
Creates and configures a MetricsExtractor from a JSON model definition.
Declaration
public static MetricsExtractor ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceProvider | sp | |
| JsonModel | m |
Returns
| Type | Description |
|---|---|
| MetricsExtractor |
Dispose()
Releases resources used by this block, including the visualization scope.
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
OnMetricChanged(MetricType)
Executes the logic for when Metric just changed.
Declaration
private void OnMetricChanged(MetricType value)
Parameters
| Type | Name | Description |
|---|---|---|
| MetricType | value | The new property value that was set. |
Remarks
This method is invoked right after the value of Metric is changed.
OnMetricChanged(MetricType, MetricType)
Executes the logic for when Metric just changed.
Declaration
private void OnMetricChanged(MetricType oldValue, MetricType newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| MetricType | oldValue | The previous property value that was replaced. |
| MetricType | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of Metric is changed.
OnMetricChanging(MetricType)
Executes the logic for when Metric is changing.
Declaration
private void OnMetricChanging(MetricType value)
Parameters
| Type | Name | Description |
|---|---|---|
| MetricType | value | The new property value being set. |
Remarks
This method is invoked right before the value of Metric is changed.
OnMetricChanging(MetricType, MetricType)
Executes the logic for when Metric is changing.
Declaration
private void OnMetricChanging(MetricType oldValue, MetricType newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| MetricType | oldValue | The previous property value that is being replaced. |
| MetricType | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of Metric is changed.
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 metric vector.
Declaration
protected override void OnReceive(object sender, object? value)
Parameters
| Type | Name | Description |
|---|---|---|
| object | sender | |
| object | value |
Overrides
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.