-
Notifications
You must be signed in to change notification settings - Fork 2
/
sma_2d.h
67 lines (55 loc) · 2.29 KB
/
sma_2d.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/////////////////////////////////////////////////////////////////////////////
// Name: sma-2d
// Purpose: Simple Moving average over N values for R rows
/////////////////////////////////////////////////////////////////////////////
/*
* Copyright (C) 2023 Johannes Linkels <[email protected]>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _SMA_2D_
#define _SMA_2D_
#include <iostream>
#include <vector>
class SMA_2D {
public:
/// Constructors
SMA_2D(int numRecords, int numAverage);
~SMA_2D();
/// (Re)Initializes the data values
void Init(int numRecords, int numAverage);
/// Adds a new value to the average at record recordNum
int AddVal(int recordNum, double val);
/// Gets the current moving average value at record recordNum
double GetSMA(int recordNum);
/// Get the number of values in the moving average
int GetNumAverage();
/// Get the number of values summed;
int GetNumSummed(int recordNum);
/// Set the length of the moving average
void SetNumAverage(int numAverage);
/// Set the number of values summed;
void SetNumRecords(int numRecords);
private:
int m_NumRecords; // number of records (samples)
int m_NumAverage; // number of values used for the average
std::vector<int> index; // index points to latest value in each record
std::vector<int> numSummed; // number of values summed, avg = sum/numSummed
std::vector<double> sum; // current sum of values for each record
std::vector<std::vector<double>> prevValues; // the actual 2D store
};
#endif
// _SMA_2D