DIY Auto-Correlator 1.0
Auto-Correlator Card implementation using Teensy 4.x microcontrollers.
monitor_channel.hpp
Go to the documentation of this file.
1#pragma once
2#include <cstdint>
3#include <cmath>
4#include "./../types.hpp"
5
8template <bool MeanChannel=true>
10
12template<>
13class MonitorChannel<true>
14{
15using AccumulateType = float;
16public:
17
18 volatile AccumulateType Accumulate = 0.0;
19 volatile uint32_t Count = 0;
20
22 template<typename DataType>
23 void push_back(DataType data)// __attribute__((always_inline))
24 {
25 Accumulate += (float_t)data;
26 Count++;
27 //Expected Compiler optimization for integers → ++.
28 }
29
31 float_t mean() const __attribute__((always_inline))
32 {
33
34 return float_t(this->Accumulate)/ float_t(this->Count);
35 }
36
38 AccumulateType accumulate() const __attribute__((always_inline))
39 {
40 return Accumulate;
41 }
42
43 void reset()
44 {
45 Accumulate = 0.0;
46 Count = 0;
47 }
48
49};
50
52template <>
53class MonitorChannel<false>
54{
55public:
56 using AccumulateType = uint32_t;
57 volatile uint32_t Count = 0;
59
61 void push_back() __attribute__((always_inline))
62 {
63 Count++;
64 }
65
67 float_t mean() const __attribute__((always_inline))
68 {
69 return 1.0;
70 }
71
73 AccumulateType accumulate() const __attribute__((always_inline))
74 {
75 return Count;
76 }
77
78 void reset()
79 {
80 Count = 0;
81 }
82};
83
84
88{
89public:
90 float_t Second_Moment = 0;
91
92 void push_back(counter_t datum) __attribute__((always_inline))
93 {
94 Second_Moment += datum * datum;
95 }
96
97 float_t get_output() __attribute__((always_inline))
98 {
99 return Second_Moment;
100 }
101};
102
103
104
105
108{
109public:
110 float Accumulate = 0.0;
111 float Out = 0.0;
112 uint32_t UpdateCntr = 0;
113 const uint32_t CGFactor;
114 float Error = 0.0;
115
118 constexpr RTCoarseGrainer(float coarsing_interval, float minimum_resolution):
119 CGFactor(uint32_t(std::floor(coarsing_interval / minimum_resolution))), Error(coarsing_interval - CGFactor)
120 {}
121
124 constexpr RTCoarseGrainer(float coarsing_interval): CGFactor(uint32_t(std::floor(coarsing_interval))), Error(coarsing_interval - CGFactor)
125 {}
126
128 template <typename DataType>
129 void push_back(const DataType datum)
130 {
131 Accumulate += (datum);
132 UpdateCntr++;
133 if(UpdateCntr >= CGFactor)
134 {
135 Out = Accumulate;
136 Accumulate = 0.0;
137 UpdateCntr = 0;
138 }
139 }
140
142 float inline output() const
143 {
144 return Out;
145 }
146
148 float inline error() const
149 {
150 return Error;
151 }
152};
AccumulateType accumulate() const __attribute__((always_inline))
Returns the accumulate so far, which is the same as 'Count`.
Definition: monitor_channel.hpp:73
uint32_t AccumulateType
Definition: monitor_channel.hpp:56
void reset()
Definition: monitor_channel.hpp:78
void push_back() __attribute__((always_inline))
Definition: monitor_channel.hpp:61
float_t mean() const __attribute__((always_inline))
Definition: monitor_channel.hpp:67
void reset()
Definition: monitor_channel.hpp:43
void push_back(DataType data)
Adds datum to the channel.
Definition: monitor_channel.hpp:23
float_t mean() const __attribute__((always_inline))
Returns the estimated mean.
Definition: monitor_channel.hpp:31
AccumulateType accumulate() const __attribute__((always_inline))
Returns the Accumulate so far.
Definition: monitor_channel.hpp:38
float AccumulateType
Definition: monitor_channel.hpp:15
A simple Averager Class that calculates the estimated mean. Template parameter Construct specifies a ...
Definition: monitor_channel.hpp:9
An object that can accumulate data into a fixed size bin before changing its output value.
Definition: monitor_channel.hpp:108
float error() const
Returns the discretization error.
Definition: monitor_channel.hpp:148
float output() const
Returns the last available coarse-grained value.
Definition: monitor_channel.hpp:142
float Out
Last Ready Coarse Grained Value.
Definition: monitor_channel.hpp:111
constexpr RTCoarseGrainer(float coarsing_interval, float minimum_resolution)
Constructor that accepts a coarsening_interval and the minimum_resolution of data and assumes the coa...
Definition: monitor_channel.hpp:118
float Accumulate
Accumulate of the data.
Definition: monitor_channel.hpp:110
float Error
Error in the coarsening interval due to discretization.
Definition: monitor_channel.hpp:114
void push_back(const DataType datum)
Updates the RTCoarseGrainer object with the passed datum.
Definition: monitor_channel.hpp:129
const uint32_t CGFactor
Number of points that are coarse-grained together.
Definition: monitor_channel.hpp:113
uint32_t UpdateCntr
Local counter that keep tracks of the updates made.
Definition: monitor_channel.hpp:112
constexpr RTCoarseGrainer(float coarsing_interval)
Constructor that accepts a coarsening_interval and the minimum_resolution of data and assumes the coa...
Definition: monitor_channel.hpp:124
Measures the zeroth auto-correlation, which is equal to the second moment of the sampled time series....
Definition: monitor_channel.hpp:88
void push_back(counter_t datum) __attribute__((always_inline))
Definition: monitor_channel.hpp:92
float_t Second_Moment
Definition: monitor_channel.hpp:90
float_t get_output() __attribute__((always_inline))
Definition: monitor_channel.hpp:97
uint32_t counter_t
Data type received from the pulse counter. It is the fundamental type used for representing series da...
Definition: types.hpp:7