All Projects → jonnieZG → Ewma

jonnieZG / Ewma

Licence: mit
Exponentially Weighted Moving Average Filter

Projects that are alternatives of or similar to Ewma

Arduinojson
📟 JSON library for Arduino and embedded C++. Simple and efficient.
Stars: ✭ 5,456 (+25880.95%)
Mutual labels:  arduino, arduino-library, esp8266
Easybutton
Arduino library for debouncing momentary contact switches, detect press, release, long press and sequences with event definitions and callbacks.
Stars: ✭ 187 (+790.48%)
Mutual labels:  arduino, arduino-library, esp8266
Espmqttclient
Wifi and MQTT handling for ESP8266 and ESP32
Stars: ✭ 169 (+704.76%)
Mutual labels:  arduino, arduino-library, esp8266
Irremoteesp8266
Infrared remote library for ESP8266/ESP32: send and receive infrared signals with multiple protocols. Based on: https://github.com/shirriff/Arduino-IRremote/
Stars: ✭ 1,964 (+9252.38%)
Mutual labels:  arduino, arduino-library, esp8266
Ssd1306
Driver for SSD1306, SSD1331, SSD1351, IL9163, ILI9341, ST7735, PCD8544, Nokia 5110 displays running on Arduino/ESP32/Linux (Rasperry) platforms
Stars: ✭ 303 (+1342.86%)
Mutual labels:  arduino, arduino-library, esp8266
Pzem004t
Arduino communication library for Peacefair PZEM-004T Energy monitor
Stars: ✭ 165 (+685.71%)
Mutual labels:  arduino, arduino-library, esp8266
Arduino Applemidi Library
Send and receive MIDI messages over Ethernet (rtpMIDI or AppleMIDI)
Stars: ✭ 177 (+742.86%)
Mutual labels:  arduino, arduino-library, esp8266
Ws2812fx
WS2812 FX Library for Arduino and ESP8266
Stars: ✭ 1,113 (+5200%)
Mutual labels:  arduino, arduino-library, esp8266
Esp8266 Weather Station
ESP8266 Weather Station library supporting OpenWeatherMap, Aeris and other sources
Stars: ✭ 822 (+3814.29%)
Mutual labels:  arduino, arduino-library, esp8266
Arduinowebsockets
A library for writing modern websockets applications with Arduino (ESP8266 and ESP32)
Stars: ✭ 213 (+914.29%)
Mutual labels:  arduino, arduino-library, esp8266
Button2
Arduino Library to simplify working with buttons. It allows you to use callback functions to track single, double, triple and long clicks. It also takes care of debouncing.
Stars: ✭ 109 (+419.05%)
Mutual labels:  arduino, arduino-library, esp8266
Espui
A simple web user interface library for ESP32 and ESP8266
Stars: ✭ 330 (+1471.43%)
Mutual labels:  arduino, arduino-library, esp8266
Tft espi
Arduino and PlatformIO IDE compatible TFT library optimised for the STM32, ESP8266 and ESP32 that supports different driver chips
Stars: ✭ 1,215 (+5685.71%)
Mutual labels:  arduino, arduino-library, esp8266
Arduino Homekit Esp8266
Native Apple HomeKit accessory implementation for the ESP8266 Arduino core.
Stars: ✭ 545 (+2495.24%)
Mutual labels:  arduino, arduino-library, esp8266
Aunit
Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test. Used with AUniter or EpoxyDuino for continuous builds.
Stars: ✭ 73 (+247.62%)
Mutual labels:  arduino, arduino-library, esp8266
Socket.io Client
A socket.io-client implementation for ESP8266 and Arduino
Stars: ✭ 170 (+709.52%)
Mutual labels:  arduino, arduino-library, esp8266
Easyntpclient
Library to read time from Network Time Protocol (NTP) servers.
Stars: ✭ 20 (-4.76%)
Mutual labels:  arduino, arduino-library, esp8266
Dsckeybusinterface
An Arduino/esp8266/esp32 library to directly interface with DSC security systems.
Stars: ✭ 202 (+861.9%)
Mutual labels:  arduino, arduino-library, esp8266
Heatpump
Arduino library to control Mitsubishi Heat Pumps via connector cn105
Stars: ✭ 327 (+1457.14%)
Mutual labels:  arduino, arduino-library, esp8266
Guislice
GUIslice drag & drop embedded GUI in C for touchscreen TFT on Arduino, Raspberry Pi, ARM, ESP8266 / ESP32 / M5stack using Adafruit-GFX / TFT_eSPI / UTFT / SDL
Stars: ✭ 534 (+2442.86%)
Mutual labels:  arduino, arduino-library, esp8266

EWMA

Exponentially Weighted Moving Average filter is used for smoothing data series readings. Unlike the method with a history buffer that calculates an average of the last N readings, this method consumes significantly less memory and works faster.

For example, if you have a wonky ADC, like the one in ESP8266, with a lot of noise, you will need a filter to smooth out the readings. Basically, EWMA filter allows you to specify the weight of the last reading versus the previous filtered value, by setting the alpha parameter. Roughly said, if you set alpha to, let's say, 0.1 it means that the result will be approximately the average of the last 10 readings.

output = alpha * reading + (1 - alpha) * lastOutput

  • alpha = Smoothing factor, in range [0,1]. Higher the value - less smoothing (higher the latest reading impact)
  • reading = current input value
  • lastOutput = last filter output value
  • output = filter output value after the last reading

EWMAT - Template for no-float filter

Exponentially Weighted Moving Average filter template that allows restriction to a specific data type (generally a non-floating-point data type), such as uint32_t. Avoiding floating point arithmetics can significantly decrease code footprint, especially in embeded devices, such as Arduino or STM32.

Note that the integer data type has to be as big as possible (32 bits at least, signed or unsinged), in order to allow internal calculations to be correctly performed, since the result will overflow in case when a too small data type is chosen.

The filtered value in this class is calculated as:

output = (alpha * reading + (alphaScale - alpha) * lastOutput) / alphaScale

If you want to create a filter for integers, with an alpha value of 0.03, you will just do the following:

EwmaT <int> filter(3, 100)

  • alpha = Smoothing factor in range [0,alphaScale]. Higher the value - less smoothing (higher the latest reading impact)
  • alphaScale = Number that will divide the alpha value, in order to get the actual alpha parameter of the filter (usually 10, 100, 1000 etc.)
  • lastOutput = last filter output value
  • output = filter output value after the last reading

Applications

Some sensors, like accelerometers or fast photoresistors that move a lot, give you quite noisy readings, meaning that two consecutive readings usually can differ up to 10%. These spikes make detection of movements (or whatever correlated events) impossible, so in order to smooth them out, you need to use a filter like this one.

Instantiate a filter, find an alpha value that meets the best your sampling frequency and noise level (the actual value is something you have to find out by trial and error) and feed it with readings from the sensor. Instead of using these readings directly in your further applications (calulations or whatever), read the .output value from the filter - and that's all.

Example

This example reads ADC input and filters it with two separate EWMA filters, each one with a different smoothing factor. You can observe how the first one is faster to detect changes, but more prone to noise, while the last one is less prone to noise, but slower to detect changes. The selection of the best alpha value depends on your actual application, the amount of noise and sampling frequency.

#include <Arduino.h>
#include <Ewma.h>

Ewma adcFilter1(0.1);   // Less smoothing - faster to detect changes, but more prone to noise
Ewma adcFilter2(0.01);  // More smoothing - less prone to noise, but slower to detect changes

void setup()
{
    Serial.begin(115200);
    pinMode(A0, INPUT);
}

void loop()
{
    int raw = analogRead(A0);
    float filtered1 = adcFilter1.filter(raw);
    float filtered2 = adcFilter2.filter(raw);
    Serial.printf("Raw=%d, Filter1=%.3f, Filter2=%.3f", raw, filtered1, filtered2);
    
    delay(100);
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].