Class FirFilter

FIR (Finite Impulse Response) filter that processes samples one at a time using a circular delay line.

Inheritance
FirFilter
Implements
Namespace: MOSAIC.Components.SignalProcessing
Assembly: MOSAIC.dll
Syntax
public class FirFilter : IOnlineFilter
Remarks

The filter computes the output as the discrete convolution of the input with the coefficient array: y[n] = Σ b[k] · x[n−k], where b are the coefficients and x is the input history.

A circular buffer (_delayLine) is used to avoid shifting the entire history on each sample, giving O(N) per sample where N is the number of taps.

Coefficients are typically produced by FilterDesign factory methods.

Thread-safety: This type is not thread-safe. If concurrent access is required, the caller must synchronize externally.

Constructors

FirFilter(double[])

Initializes a new FirFilter with the specified coefficients.

Declaration
public FirFilter(double[] coefficients)
Parameters
Type Name Description
double[] coefficients

The filter tap weights. The array is stored by reference (not copied). Must contain at least one element.

Exceptions
Type Condition
ArgumentNullException

Thrown if coefficients is null.

Fields

_coefficients

Filter coefficients (taps) applied during convolution.

Declaration
private readonly double[] _coefficients
Field Value
Type Description
double[]

_delayIndex

Current write position in the circular delay line.

Declaration
private int _delayIndex
Field Value
Type Description
int

_delayLine

Circular buffer holding the most recent input samples.

Declaration
private readonly double[] _delayLine
Field Value
Type Description
double[]

Properties

Order

Gets the filter order (number of coefficients / taps).

Declaration
public int Order { get; }
Property Value
Type Description
int

Methods

ProcessSample(double)

Processes a single input sample through the filter and returns the filtered output.

Declaration
public double ProcessSample(double sample)
Parameters
Type Name Description
double sample

The input sample value.

Returns
Type Description
double

The filtered output sample computed via convolution with the coefficient array.

ProcessSamples(double[])

Processes an array of input samples sequentially through the filter.

Declaration
public double[] ProcessSamples(double[] samples)
Parameters
Type Name Description
double[] samples

The input sample array.

Returns
Type Description
double[]

A new array of the same length containing the filtered output samples.

Reset()

Resets the filter state by clearing the delay line, as if no samples had been processed.

Declaration
public void Reset()

Implements

IOnlineFilter

Search documentation

Start typing to search the documentation.