Statistical is a lightweight library that brings together the basic and advanced statistical analysis functions needed when processing sensor data in Arduino and other embedded systems under one roof. It is optimized to reduce sensor noise, suppress sudden spikes, analyze distribution, and examine the trend of data over time.
Although initially developed for median/mode-based filtering, today it offers a comprehensive set of statistics that works on both fixed-size arrays and stream-based data.
The goal is to make raw data from the field more meaningful and controllable, thereby increasing accuracy and stability in sensor-based systems.
Array Statistics
On fixed-size float arrays:
- Average, Sum, Max, Min, Sq_Sum
- Arithmetic / Geometric / RMS / Extended RMS Average
- Sigma, Quartile, IQR
- Standard Deviation & Standard Deviation Error
- Variance
- Bubble Sort-based sorting
In this way, for example, from the last N measurements of a sensor:
- Noise-free median value
- Instantaneous min–max range
- Standard deviation and variance information
You can establish a structure that can be taken in one go.
Stream Statistics
When you need to track data stream-based instead of keeping it in arrays in long-running systems:
- Total number of data (count)
- Arithmetic mean of the stream
This method provides a great advantage in long-term measurements on microcontrollers where RAM is limited. When each new measurement arrives, metrics such as average, minimum, maximum are updated instantly and there is no need to keep all data in memory.
Linear Regression (Array & Stream)
For both fixed-size arrays and stream data:
- Slope
- Offset (intercept)
- R² (coefficient of determination)
by calculating, it allows you to track the trend of sensor data over time.
This analysis is of critical importance especially in the following situations:
- Sensor calibration and accuracy control
- Detection of drift over time
- Trend analyses of slowly changing processes
Slope-Based Anomaly Detection
In the library, by calculating the slope of the last n measurements:
- Rise / fall trend of sensor data
- A simple idea of whether sudden changes are normal or anomalies
There is also a slope-based structure.
This basic structure can be used to underlay higher-level anomaly detection and decision mechanisms.
When Should You Use It?
Statistical works exactly in these scenarios:
- If the sensor value you get from the ADC is noisy and occasionally throws absurd spikes
- If you want to track metrics such as average, min, max, standard deviation without filling memory in long-term measurements
- If you want to see the trend, slope, R² value of the raw sensor data you have
- If you want to extract simple features that you will use later on the ML/edge side on the microcontroller side
In short: In every project where you want to process and make meaningful raw data in the field instead of sending it as is, you can use Statistical.
Installation
Arduino IDE
- Open Library Manager in Arduino IDE.
- Type "Statistical" in the search box.
- Select the
Statistical(Author: Günce Akkoyun) library and Install.
Alternatively:
- Download
.zipfrom the Releases section on GitHub - You can add it manually via Sketch → Include Library → Add .ZIP Library….
PlatformIO
You can add it to your platformio.ini file as follows in the relevant environment (env):
[env:my_board]
platform = ...
board = ...
framework = arduino
lib_deps = akkoyun/Statistical
If you want to fix the version, you can add the version with @ (e.g. @^2.1.0).
Usage Scenarios
A few typical usage scenarios for it to be more clearly visualized in your mind:
- Median filtering: Suppressing spike values in measurements such as current, voltage, temperature.
- Normalizing sensor data: Obtaining more stable outputs with geometric mean or RMS average.
- Long-term logging: Reducing memory usage by recording periodic average/min/max/stddev instead of recording each data.
- Trend analysis: Tracking sensor behavior by calculating slope, offset and R² with linear regression.
Bu kütüphane, gerçek sahada kullanılan projelerden gelen ihtiyaçlara göre sürekli gelişen bir açık kaynak projedir. Kullanıcı geri bildirimleri, yeni fonksiyonların eklenmesi ve mevcut yapının iyileştirilmesi açısından kritik öneme sahiptir.
Bu kütüphaneyi hem kişisel hem de ticari projelerinde özgürce kullanabilirsin. Herhangi bir lisans kısıtı uygulanmamaktadır; amacım, bu kütüphanenin mümkün olduğunca fazla gerçek dünya projesinde yer almasıdır. Özel bir entegrasyon ihtiyacın, ticari bir planın veya teknik bir sorunun varsa bana e‑posta üzerinden her zaman ulaşabilirsin: akkoyun@me.com Geri bildirimlerini veya kullanım senaryolarını paylaşman, projeyi geliştirmem açısından büyük katkı sağlar.