GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - stonatm/python_filtering_data: Simple python library thats implemented EWMA, IIR and Average filter.

BranchesTags
Open more actions menu

Latest commit

 

History

18 Commits
18 Commits

Folders and files

NameName
Last commit message
Last commit date
examples
examples
 
 
res
res
 
 
README.md
README.md
 
 
filters.py
filters.py
 
 

Repository files navigation

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

About

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

Topics

alphaaveragedataewmaewma-filterfilteriiriir-filterlibrarymathplotlibmicropythonpython

Resources

Readme
Activity

Stars

4 stars

Watchers

1 watching

Forks

3 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.