Class: Toybox::Math::IirFilter

Inherits:
Filter show all

Overview

Infinite Impulse Response (IIR) filter implementation.

Examples:

Shows the constructor and implementation for filter use with accelerometer data.

using Toybox.Math;
var mX = [0];
var mY = [0];
var mZ = [0];
var mFilter;

// Constructor
function initialize() {
// initialize IIR filter. Coefficients are for demonstration purposes only.
var options = {:coefficients_a => [ -0.0278f, 0.9444f, -0.0278f ],
               :coefficients_b => [ 0.0278f, -0.9444f, 0.0278],
               :gain => 0.001f};
try {
    mFilter = new Math.IirFilter(options);
    }
catch(e) {
    System.println(e.getErrorMessage());
    }
}

// Callback to receive accelerometer data
function accel_callback(sensorData) {
    mX = mFilter.apply(sensorData.accelerometerData.x);
    mY = sensorData.accelerometerData.y;
    mZ = sensorData.accelerometerData.z;
    onAccelData();
}

See Also:

Since:

  • 2.3.0

Instance Method Summary collapse

Methods inherited from Lang::Object

equals, hashCode, method, toString, weak

Constructor Details

initialize(dictionary) ⇒ IirFilter

Initialize the IIR filter.

Parameters:

Options Hash (dictionary):

  • :coefficients_a (Toybox::Lang::Symbol)

    An Array of Float values that specify the feedback filter coefficients. A resource ID referencing a JSON Array resource can also be used here.

  • :coefficients_b (Toybox::Lang::Symbol)

    An Array of Float values that specify the feed forward filter coefficients. A resource ID referencing a JSON Array resource can also be used here.

  • :gain (Toybox::Lang::Symbol)

    A Float value that specifies a multiplier to be applied to the coefficients.

Raises:

Since:

  • 2.3.0


8025
8026
# File 'Monkeybrains.rb', line 8025

def initialize(dictionary)
end

Instance Method Details

apply(data) ⇒ Object

Since:

  • 2.3.0


8027
8028
# File 'Monkeybrains.rb', line 8027

def apply(data)
end