Skip to main content

Digital Signal processing

ewma

Exponentially weighted moving average is a simple PIR filter with a gain parameter. The closer gain to 1 and the more closely the EWMA tracks the original time series.

import { Temperature } from "@devicescript/core"
import { ewma } from "@devicescript/observables"

const thermometer = new Temperature()

thermometer.reading
.pipe(ewma(0.5))
.subscribe(t => console.log(t))

rollingAverage

A windowed rolling average filter.

import { Temperature } from "@devicescript/core"
import { rollingAverage } from "@devicescript/observables"

const thermometer = new Temperature()

thermometer.reading
.pipe(rollingAverage(10))
.subscribe(t => console.log(t))

fir

A general purpose Finite Response Filter filter. Coefficients are typically computed in a seperate process.

import { Temperature } from "@devicescript/core"
import { fir } from "@devicescript/observables"

const thermometer = new Temperature()

thermometer.reading
.pipe(fir([0.1, 0.2, 1]))
.subscribe(t => console.log(t))

levelDetector

Measures and thresholds data into low/mid/high levels.

import { Temperature } from "@devicescript/core"
import { levelDetector } from "@devicescript/observables"

const thermometer = new Temperature()

thermometer.reading
.pipe(levelDetector(20 /* low threshold */, 30 /*high threshold */))
.subscribe(level =>
console.log(level < 0 ? "cold" : level > 0 ? "hot" : "mild")
)