Class: Toybox::Math::FirFilter

Inherits:
Filter show all

Overview

Finite Impulse Response (FIR) filter implementation.

Examples:

Shows the constructor and implementation for filter use with accelerometer data. Borrowed from the PitchCounter sample included in the SDK.

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

// Constructor
function initialize() {
// initialize FIR filter
var options = {:coefficients => [ -0.0278f, 0.9444f, -0.0278f ], :gain => 0.001f};
try {
    mFilter = new Math.FirFilter(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) ⇒ FirFilter

Initialize the FIR filter.

Parameters:

Options Hash (dictionary):

  • :coefficients (Toybox::Lang::Symbol)

    An Array of Float values that specify the 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


7970
7971
# File 'Monkeybrains.rb', line 7970

def initialize(dictionary)
end

Instance Method Details

apply(data) ⇒ Object

Since:

  • 2.3.0


7972
7973
# File 'Monkeybrains.rb', line 7972

def apply(data)
end