GithubHelp home page GithubHelp logo

binarymaker / moving-average-filter Goto Github PK

View Code? Open in Web Editor NEW
18.0 1.0 6.0 3.76 MB

Moving average filter library

C 96.54% Assembly 2.33% C++ 1.13% Python 0.01% Batchfile 0.01%
stm32 cubemx filter adc moving-average running-average filter-library analog-filter

moving-average-filter's Introduction

Moving-average-filter

Average filter based on FIFO buffer

Library files

Concept block

                             input
                               +
                               |
                            +-----+ 
                            | S/H | <------------------ sampling time
                            +-----+ 
                               |
                               v
            +------------------+--------------------+
  index +-->+                 DEMUX                 |
            +----+------+------+----------------+---+
                 |      |      |                |
              +--+-+ +--+-+ +--+-+           +--+-+
              | B0 | | B1 | | B3 | . . . . . | Bn |   <- buffer
              +-+--+ +-+--+ +-+--+           +-+--+      n is size-1
                |      |      |                |
            +---+------+------+----------------+----+
            |              ACCUMULATOR              |
            +------------------+--------------------+
                               | <---------------------- sum
                               v
                      +--------+--------+
                      | divided by fill |
                      +--------+--------+
                               |
                               v
                            filtered
                             result
                             

Code usage

/* Include library */
#include "moving-average.h"

/* Filter objects */
movingAverage_t avg_filter;
movingAverage_t avg_filter_2;

void main()
{
   /* Initialization of filters */
   moving_average_create(&avg_filter, 10, 100);   /* filter size 10, sample time 100ms */
   moving_average_create(&avg_filter_2, 30, 150); /* filter size 30, sample time 150ms */

   /* wait for 1 maximum sample time */
   delay(150);

   while(1)
   {
      signal = signal_source();  /* signal source function may ADC, Capture count, sensor data*/

      /* Filter process
      * 
      * call this function maximum passible short time
      */
      moving_average_filter(&avg_filter, signal);
      moving_average_filter(&avg_filter_2, signal);

      process_or_print = avg_filter.filtered;
      process_or_print = avg_filter_2.filtered;
   }
}

Filter images

  • channel 0 - signal + noise (+/- 20)
  • channel 1 - filter size 10, sample time 100ms
  • channel 2 - filter size 30, sample time 100ms
  • channel 3 - filter size 50, sample time 100ms

alt text

alt text

Thank to Graph - serial plot tool

moving-average-filter's People

Contributors

binarymaker avatar gokulalucastvs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.