Skip to content

BasilAvad/MovingAverage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Moving Average in C++

الوسط المتحرك

Filter your sensor data with moving average, making your system stable and easy to control.

Explanation of moving average formula

  • In Arabic.
- تعريف: الأوساط المتحركة تستخدم في توهين التعرجات الحادة في البيانات الرقمية بقصد معرفة الاتجاه العام لها..
لنفرض على سبيل المثال توافر البيانات التالية 
T [ 1 | 2 | 3 | 4  | 5 | 6  | 7 | 8  | 9  | 10| 11 | 12 | 13 ]
X [ 5 | 3 | 7 | 10 | 5 | 12 | 2 | 17 | 19 | 5 | 20 | 15 | 30 ]
حيث ترمز T للفترة الزمنية و X الى القيمة المقروءة من الحساس 

على سبيل المثال لو قمنا بحساب المتوسط للقيم الثلاث الأولى ثم الثلاث الثانية نحصل على السلسلة الآتية:
1-  ma(3) = (5 + 3 + 7 ) / 3 = 5.0000
2-  ma(3) = (3 + 7 + 10) / 3 = 6.6667
3-  ma(3) = (7 + 10 + 5) / 3 = 7.3333
.
.
.
.
10- ma(3) = (5 + 20 + 15) / 3 = 13.3333
11- ma(3) = (20 + 15 + 30) / 3 = 21.6667
كلما زاد عدد الفترات الداخلة في حساب المتوسط ازداد التوهين وقلت لاعوجاجات و الانكسارات في المنحنى الممثل لا الوسط المتحرك ال ان حساب الوسط المتحرك (3)ma يؤدي الى توهين النكسارات اكثر من (3)ma و (7)ma أكثر و أكثر....

-> Read More About: Moving Average .

Explanation and distribution of projects

 1- Support all arduino boards contain ADC.
 2- Support all Node MCU boards contain ADC like (ESP8266).
 1- Support all ESP32 boards contain ADC.

Installation

Use the Arduino IDE Arduino IDE or PlatformIO IDE in VS Code PlatformIO IDE to update this code.

git clone https://github.com/BasilAvad/MovingAverage

Usage

  • Include and Call the header file inside your project.
#include <movingaverage.h>
  • Create an object of MovingAverage using the constructor.
MovingAverage sensor1(20);
  • Call a member function of the object in the loop function.
void loop()
{
  int sensorValue1 = analogRead(MicrocontrollerADCPin);
  float result = sensor1.mafunc(sensorValue1);
  delay(2)
}

Moving Average Library Test and Result

  • 🟦 The blue line is sensor raw data.
  • 🟥 The red line is the sensor filtred data with a moving average.

COM4 6_15_2023 2_03_10 PM

  • For more watch the video -> Video

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

About

Moving Average Library for Embedded Systems

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages