GithubHelp home page GithubHelp logo

stonatm / python_filtering_data Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 3.0 833 KB

Simple python library thats implemented EWMA, IIR and Average filter.

Python 100.00%
average iir ewma alpha python filter data mathplotlib library iir-filter

python_filtering_data's Introduction

A simple filter library written in micro python for use in microcontrollers like esp8266, esp32.

The filters.py library contains three types of filters:

  • Average filter
  • EWMA filter
  • IIR filter

Usage

Model of operation of filter functions: the first call to the NAME_filter function returns the value given as the input parameter input. This value is also stored for the next calculations for the next calls of this function. Next calls of this function continue calculations for input data for previously set filter parameters or defaults values (if parameters are not set). Using the NAME_filter_reset function returns this state to the beginning.

example code

# import library
import filters
# create sample input data table
input_data = [1, 2, 1, 4, 3, 4, 5, 2, 1, 2]
# create object
filtered = filters.filter
# set filter parameter
filtered.ewma_filter_reset(0.2)
# print input and filtered values
for i in range ( len(input_data) ):
  print('input= ' + input_data[i] + ' output= ' + filtered.ewma_filter(input_data[i]) )

other examples

link to more advanced examples

Average filter

average_filter_reset(nums=1)

Function resets the filter to initial state with optional parameter nums (if omnitet then default set 1 samples average calculation).

average_set_samples(nums)

The function sets the number of data samples for which the mathematical mean will be calculated. nums must be greather or equal 1.

average_filter(input)

The function returns the calculated value for the given input data.

IIR filter

iir_filter_reset(factor=1)

Function resets the filter to initial state with optional parameter factor (if omnitet then default value of factor is set to 1).

iir_set_factor(factor)

The function sets the factor parameter. factor must be greather or equal 1 and should not exceed the value of 32. The factor must be an integer.

iir_filter(input)

The function returns the calculated value for the given input data.

EWMA filter

ewma_filter_reset(alpha=1)

Function resets the filter to initial state with optional parameter alpha (if omnitet then default value of alpha is set to 1).

ewma_set_alpha(alpha)

The function sets the alpha parameter. alpha must be in range (0 < alpha < 1).

ewma_filter(input)

The function returns the calculated value for the given input data.

Graphical representation of Average filter working

How the nums of samples parameter affects the output.

X axis - number of data sample

Y axis - data value

res/average_data.png

res/average_sinus.png

Graphical representation of EWMA filter working

How the alpha parameter affects the output.

X axis - number of data sample

Y axis - data value

res/ewma_data.png

res/ewma_sinus.png

Graphical representation of IIR filter working

How the factor parameter affects the output.

X axis - number of data sample

Y axis - data value

res/iir_data.png

res/iir_sinus.png

python_filtering_data's People

Contributors

stonatm avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.