Class AdaptiveFilterBlock
Adaptive first-order IIR low-pass filter for heteroscedastic signals where noise grows with signal magnitude.
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:
{
"AdaptiveLP": {
"Type": "AdaptiveFilter",
"Inputs": [ "EMG" ],
"DesiredRate": 200,
"Params": [ 5.0, 0.0, -20.0, 10.0 ],
"Path": "C:/Data/session1"
}
}
Params:
| Index | Description |
|---|---|
| 0 | Alpha (double, 0–10, default 5.0) — derivative pre-filter smoothing (UI scale). |
| 1 | Offset (double, −5 to 5, default 0.0) — base exponent offset. |
| 2 | Magnitude (double, −40 to 0, default −20.0) — signal-magnitude contribution. |
| 3 | Deriviate (double, 0 to 40, default 10.0) — derivative contribution. |
How Type, Inputs and Params work · Block catalogue and parameter reference
Implements
Inherited Members
Namespace: MOSAIC.Models
Assembly: MOSAIC.dll
Syntax
public class AdaptiveFilterBlock : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks
Algorithm (per sample, per channel):
- Finite-difference derivative: dx = (x[k] − x[k−1]) × fₛ
- Filtered derivative: dx_filt[k] = αd × dx + (1 − αd) × dx_filt[k−1], where αd = (2π·α / fₛ) / (1 + 2π·α / fₛ) and α = Alpha / 10 ∈ [0, 1].
- Adaptive cutoff: fc = exp(Offset + Deriviate × |dx_filt[k]| + Magnitude × |x[k]|).
- Output: a = (2π·fc / fₛ) / (1 + 2π·fc / fₛ), y[k] = a × x[k] + (1 − a) × y[k−1].
Inputs: Accepts both MathNet.Numerics.LinearAlgebra.Vector<T> (single sample) and MathNet.Numerics.LinearAlgebra.Matrix<T> (rows = time steps, columns = channels). State is maintained across calls so each column is filtered as a continuous channel over time.
Parameters (UI-bindable): Alpha (0–10), Offset (−5 to 5), Magnitude (−40 to 0), Deriviate (0 to 40). CutoffFrequency exposes the adaptive fc of the first channel for UI readout.
CSV logging: When a Path is specified, Dumper
automatically logs every published value via Publish(object).
Constructors
AdaptiveFilterBlock(string, double, double, double, double, double)
Initializes a new AdaptiveFilterBlock.
Declaration
public AdaptiveFilterBlock(string name = "AdaptiveFilter", double desiredRate = 0, double alphaUi = 5, double offset = 0, double magnitude = -10, double deriviate = 10)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Display name of the block. |
| double | desiredRate | Sampling/processing rate in Hz. |
| double | alphaUi | Derivative pre-filter smoothing (UI scale 0–10, default 5.0). |
| double | offset | Base exponent offset (default 0.0). |
| double | magnitude | Signal-magnitude exponent contribution (default −10.0). |
| double | deriviate | Derivative exponent contribution (default 10.0). |
Fields
_alpha
Derivative pre-filter smoothing (UI scale 0–10; internal 0–1).
Declaration
[ObservableProperty]
private double _alpha
Field Value
| Type | Description |
|---|---|
| double |
_cutoffFrequency
Adaptive cutoff frequency of the first channel (Hz), updated each tick for UI readout.
Declaration
[ObservableProperty]
private double _cutoffFrequency
Field Value
| Type | Description |
|---|---|
| double |
_deriviate
Derivative contribution to the adaptive cutoff exponent (0 to 40). Spelling preserved for XAML binding compatibility.
Declaration
[ObservableProperty]
private double _deriviate
Field Value
| Type | Description |
|---|---|
| double |
_isExpanded
Whether the filter settings panel is expanded in the UI.
Declaration
[ObservableProperty]
private bool _isExpanded
Field Value
| Type | Description |
|---|---|
| bool |
_magnitude
Signal-magnitude contribution to the adaptive cutoff exponent (−40 to 0).
Declaration
[ObservableProperty]
private double _magnitude
Field Value
| Type | Description |
|---|---|
| double |
_offset
Base exponent offset for the adaptive cutoff (−5 to 5).
Declaration
[ObservableProperty]
private double _offset
Field Value
| Type | Description |
|---|---|
| double |
_prevDerivative
Per-channel state: previous filtered derivative.
Declaration
private Vector<double>? _prevDerivative
Field Value
| Type | Description |
|---|---|
| Vector<double> |
_prevInput
Per-channel state: previous input sample.
Declaration
private Vector<double>? _prevInput
Field Value
| Type | Description |
|---|---|
| Vector<double> |
_prevOutput
Per-channel state: previous output sample.
Declaration
private Vector<double>? _prevOutput
Field Value
| Type | Description |
|---|---|
| Vector<double> |
_samplingFrequency
Sampling frequency in Hz (set from DesiredRate).
Declaration
private double _samplingFrequency
Field Value
| Type | Description |
|---|---|
| double |
Properties
Alpha
Derivative pre-filter smoothing (UI scale 0–10; internal 0–1).
Declaration
[ExcludeFromCodeCoverage]
public double Alpha { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
CutoffFrequency
Adaptive cutoff frequency of the first channel (Hz), updated each tick for UI readout.
Declaration
[ExcludeFromCodeCoverage]
public double CutoffFrequency { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Deriviate
Derivative contribution to the adaptive cutoff exponent (0 to 40). Spelling preserved for XAML binding compatibility.
Declaration
[ExcludeFromCodeCoverage]
public double Deriviate { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
DumpFilePrefix
Recordings from this block are named <block>_adaptive.csv.
Declaration
protected override string DumpFilePrefix { get; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
IsExpanded
Whether the filter settings panel is expanded in the UI.
Declaration
[ExcludeFromCodeCoverage]
public bool IsExpanded { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
JsonTypeName
Block type identifier for JSON serialization. Override for a custom name.
Declaration
protected override string JsonTypeName { get; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
Magnitude
Signal-magnitude contribution to the adaptive cutoff exponent (−40 to 0).
Declaration
[ExcludeFromCodeCoverage]
public double Magnitude { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Offset
Base exponent offset for the adaptive cutoff (−5 to 5).
Declaration
[ExcludeFromCodeCoverage]
public double Offset { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Methods
ConfigureInput(IServiceProvider, JsonModel)
Creates an AdaptiveFilterBlock from a JSON pipeline definition.
Declaration
public static AdaptiveFilterBlock ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceProvider | sp | Service provider for dependency injection. |
| JsonModel | m | JSON model. |
Returns
| Type | Description |
|---|---|
| AdaptiveFilterBlock | A configured AdaptiveFilterBlock instance. |
Dispose()
Releases 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
OnAlphaChanged(double)
Executes the logic for when Alpha just changed.
Declaration
private void OnAlphaChanged(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 Alpha is changed.
OnAlphaChanged(double, double)
Executes the logic for when Alpha just changed.
Declaration
private void OnAlphaChanged(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 Alpha is changed.
OnAlphaChanging(double)
Executes the logic for when Alpha is changing.
Declaration
private void OnAlphaChanging(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The new property value being set. |
Remarks
This method is invoked right before the value of Alpha is changed.
OnAlphaChanging(double, double)
Executes the logic for when Alpha is changing.
Declaration
private void OnAlphaChanging(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 Alpha is changed.
OnCutoffFrequencyChanged(double)
Executes the logic for when CutoffFrequency just changed.
Declaration
private void OnCutoffFrequencyChanged(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 CutoffFrequency is changed.
OnCutoffFrequencyChanged(double, double)
Executes the logic for when CutoffFrequency just changed.
Declaration
private void OnCutoffFrequencyChanged(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 CutoffFrequency is changed.
OnCutoffFrequencyChanging(double)
Executes the logic for when CutoffFrequency is changing.
Declaration
private void OnCutoffFrequencyChanging(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The new property value being set. |
Remarks
This method is invoked right before the value of CutoffFrequency is changed.
OnCutoffFrequencyChanging(double, double)
Executes the logic for when CutoffFrequency is changing.
Declaration
private void OnCutoffFrequencyChanging(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 CutoffFrequency is changed.
OnDeriviateChanged(double)
Executes the logic for when Deriviate just changed.
Declaration
private void OnDeriviateChanged(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 Deriviate is changed.
OnDeriviateChanged(double, double)
Executes the logic for when Deriviate just changed.
Declaration
private void OnDeriviateChanged(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 Deriviate is changed.
OnDeriviateChanging(double)
Executes the logic for when Deriviate is changing.
Declaration
private void OnDeriviateChanging(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The new property value being set. |
Remarks
This method is invoked right before the value of Deriviate is changed.
OnDeriviateChanging(double, double)
Executes the logic for when Deriviate is changing.
Declaration
private void OnDeriviateChanging(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 Deriviate is changed.
OnIsExpandedChanged(bool)
Executes the logic for when IsExpanded just changed.
Declaration
private void OnIsExpandedChanged(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | The new property value that was set. |
Remarks
This method is invoked right after the value of IsExpanded is changed.
OnIsExpandedChanged(bool, bool)
Executes the logic for when IsExpanded just changed.
Declaration
private void OnIsExpandedChanged(bool oldValue, bool newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | oldValue | The previous property value that was replaced. |
| bool | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of IsExpanded is changed.
OnIsExpandedChanging(bool)
Executes the logic for when IsExpanded is changing.
Declaration
private void OnIsExpandedChanging(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | The new property value being set. |
Remarks
This method is invoked right before the value of IsExpanded is changed.
OnIsExpandedChanging(bool, bool)
Executes the logic for when IsExpanded is changing.
Declaration
private void OnIsExpandedChanging(bool oldValue, bool newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | oldValue | The previous property value that is being replaced. |
| bool | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of IsExpanded is changed.
OnMagnitudeChanged(double)
Executes the logic for when Magnitude just changed.
Declaration
private void OnMagnitudeChanged(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 Magnitude is changed.
OnMagnitudeChanged(double, double)
Executes the logic for when Magnitude just changed.
Declaration
private void OnMagnitudeChanged(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 Magnitude is changed.
OnMagnitudeChanging(double)
Executes the logic for when Magnitude is changing.
Declaration
private void OnMagnitudeChanging(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The new property value being set. |
Remarks
This method is invoked right before the value of Magnitude is changed.
OnMagnitudeChanging(double, double)
Executes the logic for when Magnitude is changing.
Declaration
private void OnMagnitudeChanging(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 Magnitude is changed.
OnOffsetChanged(double)
Executes the logic for when Offset just changed.
Declaration
private void OnOffsetChanged(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 Offset is changed.
OnOffsetChanged(double, double)
Executes the logic for when Offset just changed.
Declaration
private void OnOffsetChanged(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 Offset is changed.
OnOffsetChanging(double)
Executes the logic for when Offset is changing.
Declaration
private void OnOffsetChanging(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The new property value being set. |
Remarks
This method is invoked right before the value of Offset is changed.
OnOffsetChanging(double, double)
Executes the logic for when Offset is changing.
Declaration
private void OnOffsetChanging(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 Offset is changed.
OnReceive(object, object)
Processes incoming data: applies the adaptive filter to vectors or matrices.
Declaration
protected override void OnReceive(object sender, object value)
Parameters
| Type | Name | Description |
|---|---|---|
| object | sender | The upstream block. |
| object | value | A MathNet.Numerics.LinearAlgebra.Vector<T> (single sample) or MathNet.Numerics.LinearAlgebra.Matrix<T> (rows = time, columns = channels). |
Overrides
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown for unsupported input types. |
Process(Matrix<double>)
Processes a matrix of samples (rows = time steps, columns = channels). State is shared across rows so each column is filtered as a continuous channel.
Declaration
public Matrix<double> Process(Matrix<double> X)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | X | Input matrix. |
Returns
| Type | Description |
|---|---|
| Matrix<double> | Filtered output matrix of the same dimensions. |
Process(Vector<double>)
Processes a single sample vector through the adaptive filter. Updates internal state and CutoffFrequency.
Declaration
public Vector<double> Process(Vector<double> x)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector<double> | x | Input sample vector (one value per channel). |
Returns
| Type | Description |
|---|---|
| Vector<double> | Filtered output vector of the same dimension. |