Plaquette
 
Loading...
Searching...
No Matches
MovingAverage.h
1/*
2 * MovingAverage.h
3 *
4 * Tool for moving averages.
5 *
6 * This file is part of Qualia https://github.com/sofian/qualia
7 *
8 * (c) 2011 Sofian Audry -- info(@)sofianaudry(.)com
9 * Inspired by code by Karsten Kutza
10 * http://www.ip-atlas.com/pub/nap/nn-src/bpn.txt
11 *
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 */
25#ifndef MOVINGAVERAGE_H_
26#define MOVINGAVERAGE_H_
27
28#include "PqCore.h"
29#include "pq_moving_average.h"
30
31namespace pq {
32
35public:
38 virtual ~MovingAverage() {}
39
41 void reset();
42
44 void reset(float initialValue);
45
47 virtual float update(float v, float alpha);
48
50 virtual float amend(float previousValue, float newValue, float alpha) ;
51
53 virtual float delta(float d);
54
56 float get() { return _value; }
57 float constGet() const { return _value; }
58
59protected:
60 // The current value of the exponential moving average.
61 float _value;
62};
63
64} // namespace pq
65
66#endif
An exponential moving average class.
Definition MovingAverage.h:34
MovingAverage()
Default constructor (infinite time window).
Definition MovingAverage.cpp:30
float get()
Returns the value of the moving average. This is undefined if isValid() == false.
Definition MovingAverage.h:56
virtual float delta(float d)
Applies a moving average step directly using a delta value.
Definition MovingAverage.cpp:50
void reset()
Resets the moving average.
Definition MovingAverage.cpp:34
virtual float update(float v, float alpha)
Updates the moving average with new value #v# (also returns the current value).
Definition MovingAverage.cpp:42
virtual float amend(float previousValue, float newValue, float alpha)
Amends the moving average latest update (needs to be called with same #alpha# parameter).
Definition MovingAverage.cpp:46