Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gbj_running

The library statistically smooths a data serie by running statistics, namely average, median, minimum, or maximum. It calculates a new smoothed value from a couple of previously provided values.

Fundamental functionality

  • The library stores 5 recently provided values, e.g., samples from a sensor reading, and calculates particular statistical value right after it from those values.
  • The library instance object acts as a sample cache for recent samples.

Dependency

  • gbj_apphelpers: Library for generic logics and calculations loaded from file gbj_apphelpers.h.

Arduino platform

  • Arduino.h: Main include file for the Arduino SDK version greater or equal to 100.
  • inttypes.h: Integer type conversions. This header file includes the exact-width integer definitions and extends them with additional facilities provided by the implementation.

Espressif platform

  • Arduino.h: Main include file for the Arduino platform.

Interface

Main

Getters

average(), median(), minimum(), maximum()

Description

Particular constructor for desired statistic to be calculated. Each constructor initiates the internal data buffer acting as the cache within a class instance object, which keeps a serie of provided values, e.g., samples from a sensor's reading, for calculating a running statistic.

  • Running values of samples from sensor reading reduce excesses and extremes in the physical value measurement.

Syntax

gbj_running::average()
gbj_running::median()
gbj_running::minimum()
gbj_running::maximum()

Parameters

None

Returns

Object preforming a particular running statistic calculation.

Example

gbj_running runAvg = gbj_running::average();

Back to interface

init()

Description

The method initiates all internal resources of a class instance object to default values as they are right after creating a library instance object.

Syntax

void init()

Parameters

None

Returns

None

Back to interface

getValue()

Description

The method is overloaded and returns a result of the recent smoothing calculation.

  • If an input argument is provided, it calculates and returns a new running statistic from the input value and previously stored ones in the cache. This value is stored in the internal cache for the future calculation. At the same time the last value in the cache is removed.
  • If no input argument is provided, the method returns the recently calculated running statistic without need of new recalculation.
  • If the method without input value is used before the first using the method with input value since initiation either by creating the instance object or calling the method init(), the 0 is retuned as a default statistic value.
  • The method is useful if there is no variable used for the running statistic in an application and the recent statistic is needed.

Syntax

float getValue(float value)
float getValue()

Parameters

  • value: Value (sample) to be used for calculating a new running statistic.
    • Valid values: float
    • Default value: none

Returns

Running statistic of default statistic type or recently calculated running statistic.

Back to interface

getSamples()

Description

The method returns current number of samples in the internal cache, which are going to be used for calculating running statistics.

  • The calculation of a running value can be provided before the cache is full. It happens at start of the smoothing process after initialization by either creating the instance object or calling the method init(). In that case the method returns the number less than the length of the buffer.

Syntax

byte getSamples()

Parameters

None

Returns

Actual number of samples in the cache.

Back to interface

About

Library for calculating a running statistic value for 16-bit sensor data series.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages