Class Resampler

Sample-time resampler with zero-order hold and stable output snapshots.

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:

{
  "Downsample": {
    "Type": "Resampler",
    "Inputs": [ "EMG" ],
    "Params": [ "100" ]
  }
}

How Type, Inputs and Params work · Block catalogue and parameter reference

Inheritance
Resampler
Namespace: MOSAIC.Models.SignalProcessing
Assembly: MOSAIC.dll
Syntax
public sealed class Resampler : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks

Overview: Converts the input sample spacing to TargetRate using zero-order hold. Output values are stable snapshots. Sample time is inferred from upstream metadata (vector publication rate or matrix row rate), with the constructor input rate as a fallback. Without input metadata, the target rate is assumed. Output arrives on input callbacks, so use a separate clocked sink if wall-clock delivery must be paced. Apply an appropriate low-pass filter before downsampling when aliasing matters.

Input types:

  • MathNet.Numerics.LinearAlgebra.Vector<T> — single sample, one value per channel.
  • MathNet.Numerics.LinearAlgebra.Matrix<T> [timesteps × channels] — each row is processed as a new sample through the same timing logic. Outputs between input instants hold the preceding value and are emitted when the next input arrives.
  • ValueTuple<string, object> — legacy tagged format; inner object is unwrapped and handled as above.

Rate propagation: The block sets DesiredRate to TargetRate, ensuring all downstream blocks inherit the resampled rate.

Constructors

Resampler()

Declaration
public Resampler()

Resampler(string, double)

Declaration
public Resampler(string name, double desiredRate)
Parameters
Type Name Description
string name
double desiredRate

Resampler(string, double, double)

Declaration
public Resampler(string name, double desiredRate, double targetRate)
Parameters
Type Name Description
string name
double desiredRate
double targetRate

Fields

_channelCount

Number of channels being resampled.

Declaration
[ObservableProperty]
private int _channelCount
Field Value
Type Description
int

_configuredInputRate

Declaration
private readonly double _configuredInputRate
Field Value
Type Description
double

_gate

Declaration
private readonly object _gate
Field Value
Type Description
object

_inputRate

Input sample rate in Hz, resolved from source metadata or the configured fallback.

Declaration
[ObservableProperty]
[NotifyPropertyChangedFor("ResampleRatio")]
[NotifyPropertyChangedFor("ConfigSummary")]
private double _inputRate
Field Value
Type Description
double

_nextInputTime

Declaration
private double _nextInputTime
Field Value
Type Description
double

_nextOutputTime

Declaration
private double _nextOutputTime
Field Value
Type Description
double

_previous

Declaration
private Vector<double>? _previous
Field Value
Type Description
Vector<double>

_samplesPublished

Total samples published downstream.

Declaration
[ObservableProperty]
private long _samplesPublished
Field Value
Type Description
long

_samplesReceived

Total samples received from upstream.

Declaration
[ObservableProperty]
private long _samplesReceived
Field Value
Type Description
long

_targetRate

Target output rate in Hz. Also updates DesiredRate.

Declaration
[ObservableProperty]
[NotifyPropertyChangedFor("ResampleRatio")]
[NotifyPropertyChangedFor("ConfigSummary")]
private double _targetRate
Field Value
Type Description
double

Properties

ChannelCount

Number of channels being resampled.

Declaration
[ExcludeFromCodeCoverage]
public int ChannelCount { get; set; }
Property Value
Type Description
int

ConfigSummary

Human-readable summary of the resampling configuration.

Declaration
public string ConfigSummary { get; }
Property Value
Type Description
string

DumpFilePrefix

Recordings from this block are named <block>_resampled.csv.

Declaration
protected override string DumpFilePrefix { get; }
Property Value
Type Description
string
Overrides
BaseBlock.DumpFilePrefix

InputRate

Input sample rate in Hz, resolved from source metadata or the configured fallback.

Declaration
[ExcludeFromCodeCoverage]
public double InputRate { 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
BaseBlock.JsonTypeName

ResampleRatio

Ratio of output rate to input rate.

Declaration
public double ResampleRatio { get; }
Property Value
Type Description
double

SamplesPublished

Total samples published downstream.

Declaration
[ExcludeFromCodeCoverage]
public long SamplesPublished { get; set; }
Property Value
Type Description
long

SamplesReceived

Total samples received from upstream.

Declaration
[ExcludeFromCodeCoverage]
public long SamplesReceived { get; set; }
Property Value
Type Description
long

TargetRate

Target output rate in Hz. Also updates DesiredRate.

Declaration
[ExcludeFromCodeCoverage]
public double TargetRate { get; set; }
Property Value
Type Description
double

TransformsPublicationRate

True when this block computes its own output cadence from its input.

Declaration
protected override bool TransformsPublicationRate { get; }
Property Value
Type Description
bool
Overrides
BaseBlock.TransformsPublicationRate

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
BaseBlock.TransformsSignalRate

Visualization

This block's visualization, or null when it has none.

Declaration
protected override BlockVisualization? Visualization { get; }
Property Value
Type Description
BlockVisualization
Overrides
BaseBlock.Visualization
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 resampled output to the UI scope.

Declaration
public BlockVisualization? Viz { get; }
Property Value
Type Description
BlockVisualization

Methods

ConfigureInput(IServiceProvider, JsonModel)

Declaration
public static Resampler ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
Type Name Description
IServiceProvider sp
JsonModel m
Returns
Type Description
Resampler

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public override void Dispose()
Overrides
BaseBlock.Dispose()

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 ConfigureInput reads them, or null when the block takes no parameters.

Overrides
BaseBlock.GetJsonParams()

OnChannelCountChanged(int)

Executes the logic for when ChannelCount just changed.

Declaration
private void OnChannelCountChanged(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 ChannelCount is changed.

OnChannelCountChanged(int, int)

Executes the logic for when ChannelCount just changed.

Declaration
private void OnChannelCountChanged(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 ChannelCount is changed.

OnChannelCountChanging(int)

Executes the logic for when ChannelCount is changing.

Declaration
private void OnChannelCountChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

This method is invoked right before the value of ChannelCount is changed.

OnChannelCountChanging(int, int)

Executes the logic for when ChannelCount is changing.

Declaration
private void OnChannelCountChanging(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 ChannelCount is changed.

OnInputRateChanged(double)

Executes the logic for when InputRate just changed.

Declaration
private void OnInputRateChanged(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 InputRate is changed.

OnInputRateChanged(double, double)

Executes the logic for when InputRate just changed.

Declaration
private void OnInputRateChanged(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 InputRate is changed.

OnInputRateChanging(double)

Executes the logic for when InputRate is changing.

Declaration
private void OnInputRateChanging(double value)
Parameters
Type Name Description
double value

The new property value being set.

Remarks

This method is invoked right before the value of InputRate is changed.

OnInputRateChanging(double, double)

Executes the logic for when InputRate is changing.

Declaration
private void OnInputRateChanging(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 InputRate is changed.

OnReceive(object, object)

Resamples in sample time using zero-order hold. Packet boundaries and CPU speed do not affect the result. Intermediate output times are delivered when the next input arrives; this block does not provide an independent real-time clock or an anti-aliasing filter.

Declaration
protected override void OnReceive(object sender, object data)
Parameters
Type Name Description
object sender
object data
Overrides
BaseBlock.OnReceive(object, object)

OnSamplesPublishedChanged(long)

Executes the logic for when SamplesPublished just changed.

Declaration
private void OnSamplesPublishedChanged(long value)
Parameters
Type Name Description
long value

The new property value that was set.

Remarks

This method is invoked right after the value of SamplesPublished is changed.

OnSamplesPublishedChanged(long, long)

Executes the logic for when SamplesPublished just changed.

Declaration
private void OnSamplesPublishedChanged(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that was replaced.

long newValue

The new property value that was set.

Remarks

This method is invoked right after the value of SamplesPublished is changed.

OnSamplesPublishedChanging(long)

Executes the logic for when SamplesPublished is changing.

Declaration
private void OnSamplesPublishedChanging(long value)
Parameters
Type Name Description
long value

The new property value being set.

Remarks

This method is invoked right before the value of SamplesPublished is changed.

OnSamplesPublishedChanging(long, long)

Executes the logic for when SamplesPublished is changing.

Declaration
private void OnSamplesPublishedChanging(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that is being replaced.

long newValue

The new property value being set.

Remarks

This method is invoked right before the value of SamplesPublished is changed.

OnSamplesReceivedChanged(long)

Executes the logic for when SamplesReceived just changed.

Declaration
private void OnSamplesReceivedChanged(long value)
Parameters
Type Name Description
long value

The new property value that was set.

Remarks

This method is invoked right after the value of SamplesReceived is changed.

OnSamplesReceivedChanged(long, long)

Executes the logic for when SamplesReceived just changed.

Declaration
private void OnSamplesReceivedChanged(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that was replaced.

long newValue

The new property value that was set.

Remarks

This method is invoked right after the value of SamplesReceived is changed.

OnSamplesReceivedChanging(long)

Executes the logic for when SamplesReceived is changing.

Declaration
private void OnSamplesReceivedChanging(long value)
Parameters
Type Name Description
long value

The new property value being set.

Remarks

This method is invoked right before the value of SamplesReceived is changed.

OnSamplesReceivedChanging(long, long)

Executes the logic for when SamplesReceived is changing.

Declaration
private void OnSamplesReceivedChanging(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that is being replaced.

long newValue

The new property value being set.

Remarks

This method is invoked right before the value of SamplesReceived is changed.

OnTargetRateChanged(double)

Executes the logic for when TargetRate just changed.

Declaration
private void OnTargetRateChanged(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 TargetRate is changed.

OnTargetRateChanged(double, double)

Executes the logic for when TargetRate just changed.

Declaration
private void OnTargetRateChanged(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 TargetRate is changed.

OnTargetRateChanging(double)

Executes the logic for when TargetRate is changing.

Declaration
private void OnTargetRateChanging(double value)
Parameters
Type Name Description
double value

The new property value being set.

Remarks

This method is invoked right before the value of TargetRate is changed.

OnTargetRateChanging(double, double)

Executes the logic for when TargetRate is changing.

Declaration
private void OnTargetRateChanging(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 TargetRate is changed.

ParseTargetRate(IReadOnlyList<object>?)

Declaration
private static double? ParseTargetRate(IReadOnlyList<object>? @params)
Parameters
Type Name Description
IReadOnlyList<object> params
Returns
Type Description
double?

ProcessSample(Vector<double>, double, double)

Declaration
private void ProcessSample(Vector<double> sample, double inputRate, double targetRate)
Parameters
Type Name Description
Vector<double> sample
double inputRate
double targetRate

ResetStatistics()

Declaration
public void ResetStatistics()

Implements

INotifyPropertyChanged
INotifyPropertyChanging
ISubscriber
IPublisher
IBaseBlockProps
IJsonExportable
IDisposable
IAsyncDisposable

Search documentation

Start typing to search the documentation.