Skip to content

Commit

Permalink
more comments, binary.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlyubimov committed Jul 2, 2017
1 parent cfc1fa2 commit 4281b96
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
10 changes: 7 additions & 3 deletions Hydra_EVSE/Hydra_EVSE.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@
// doe RB = 27 - Mega Hydra production
//#define CURRENT_SCALE_FACTOR 184

// Irregular-sampled EWA half-period for ammeter displays (the time after which data points a weighed 1/2
// w.r.t. most recent data point). This is for Ammeter display only, it does not affect current measurements
// for overdraw etc. purposes.
#define AMM_DISPLAY_HALF_PERIOD 1500



#define LOG_NONE 0
#define LOG_INFO 1
#define LOG_DEBUG 2
Expand Down Expand Up @@ -330,9 +337,6 @@ extern char p_buffer[];
#include "units.h"
#endif

// EWA half-period for ammeter displays
#define AMM_DISPLAY_HALF_PERIOD 3000

struct car_struct {
// CAR_A or CAR_B
unsigned char car;
Expand Down
2 changes: 1 addition & 1 deletion Hydra_EVSE/Hydra_EVSE.ino.standard.hex
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@
:104EE00010921503109216031092170310921803D4
:104EF0001092190310921A0310921B0310921C03B4
:104F000010921D0310921E0310921F031092210392
:104F1000109220038EEA90E4A7E8B5E48093220380
:104F1000109220038EEA90E4A7E0B5E48093220388
:104F200090932303A0932403B093250310922E03A0
:104F300010922F03109230031092310310922A0323
:104F400010922B0310922C0310922D031092260323
Expand Down
18 changes: 15 additions & 3 deletions Hydra_EVSE/onlineSum.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
#ifndef ___ONLINESUM_H___
#define ___ONLINESUM_H___

// Exponentially Weighted Average summarizer
///////////////////////////////////////////////////////////////////
// Exponentially Weighted Average summarizer for irregularly sampled data.
// References:
// http://tdunning.blogspot.com/2011/03/exponentially-weighted-averaging-for.html
// My mods for the updates-in-the past (ensures no NaNs created regardless of updates order):
// http://weatheringthrutechdays.blogspot.com/2011/04/follow-up-for-mean-summarizer-post.html

// T is double or float
Expand All @@ -33,8 +36,14 @@ class EWASum {
T w, s, tn;

public:
// tHalfPeriod is amount of t after which the observation is exponentially weighed at 0.5 of the current observation.
EWASum(T tHalfPeriod) : alpha(-tHalfPeriod / log((T)0.5)) {

// tHalfWeightPeriod is the amount of t (timeline point) in the past at which the observation is
// exponentially weighed at exactly 0.5 vs. any observation right now. Since it is weighed
// exponentially rather than linearly, observations at full period still do have a nonzero weight,
// and in general with this summarizer most recent observations are being discounted at fastest
// weight but never actually discounted completely (indefinite history), down to the precision of
// the arithmetics. At full period the weights are thus still coming in at exp(-2) = 0.135 (13.5%).
EWASum(T tHalfWeightPeriod) : alpha(-tHalfWeightPeriod / log((T)0.5)) {
reset();
};

Expand Down Expand Up @@ -63,6 +72,9 @@ void EWASum<T>::update(T x, T t) {

template <class T>
T EWASum<T>::ewa() {
// In this sum, weights low enough should not happen, as we never discount the most recent weight,
// which is at least one. So w>= 1 if there were at least one sample; and w = exactly 0 if there
// are no samples at all. With no samples, we just return 0.
return (abs(w) < 1e-6) ? 0 : s / w;
}

Expand Down

0 comments on commit 4281b96

Please sign in to comment.