Classes | |
class | AutoMap |
Automatically map an input value to an output range without knowing the precise range of inputs beforehand. More... | |
class | AutoRange< T > |
Keeps a running calculation of the range of the input values it receives. More... | |
class | OverSample< T, RESOLUTION_INCREASE_BITS > |
Enables the resolution of analog inputs to be increased by oversampling and decimation. More... | |
class | RollingAverage< T, WINDOW_LENGTH > |
Calculates a running average over a specified number of the most recent readings. More... | |
class | RollingStat< T, WINDOW_LENGTH > |
WARNING: this class is work in progress, don't use it yet. More... | |
class AutoMap |
Automatically map an input value to an output range without knowing the precise range of inputs beforehand.
Public Member Functions | |
AutoMap (int min_expected, int max_expected, int map_to_min, int map_to_max) | |
Constructor. More... | |
int | next (int n) |
Process the next value and return it mapped to the range which was set in the constructor. More... | |
int | operator() (int n) |
Process the next value and return it mapped to the range which was set in the constructor. More... | |
int | getMin () |
Returns the current minimum. More... | |
int | getMax () |
Returns the current maximum. More... | |
int | getRange () |
Returns the current range. More... | |
|
inline |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inline |
Process the next value and return it mapped to the range which was set in the constructor.
Can use the operator instead if you prefer, eg. myMap(n) instead of myMap.next(n).
n | the next value to process. |
|
inline |
Process the next value and return it mapped to the range which was set in the constructor.
This is an alternative to next() if you prefer, eg. myMap(n) instead of myMap.next(n).
n | the next value to process. |
class AutoRange |
Keeps a running calculation of the range of the input values it receives.
Definition at line 19 of file AutoRange.h.
Public Member Functions | |
AutoRange (T min_expected, T max_expected) | |
Constructor. More... | |
void | next (T n) |
Updates the current range. More... | |
T | getMin () |
Returns the current minimum. More... | |
T | getMax () |
Returns the current maximum. More... | |
T | getRange () |
Returns the current range. More... | |
Constructor.
T | the type of numbers to to use, eg. int, unsigned int, float etc. |
min_expected | the minimum possible input value. |
max_expected | the maximum possible input value. |
Definition at line 28 of file AutoRange.h.
|
inline |
|
inline |
|
inline |
|
inline |
Updates the current range.
n | the next value to include in the range calculation. |
Definition at line 36 of file AutoRange.h.
class OverSample |
Enables the resolution of analog inputs to be increased by oversampling and decimation.
Noise should be added to the input before it's digitised, then a succession of input readings are summed and finally divided to give a number with greater resolution than the ADC.
Often, noise in the Arduino system will be enough, but there are other practical methods described in Enhancing ADC Resolution by Oversampling, as well as an explanation of the overall approach.
RESOLUTION_INCREASE_BITS | how many extra bits of resolution to produce. The window length and the memory it needs increases quickly as the oversampling resolution increases. 1 bit = 4 unsigned ints (analog input between 0-1023) = 8 uint8_ts, 2 bits = 16 unsigned ints = 32 uint8_ts, 3 bits = 64 unsigned ints = 128 uint8_ts, More than 3 bits increase in resolution would require either using longs to store the readings, which would need 1024 uint8_ts for a 4 bit increase and 4096 uint8_ts for 5 bits (do any avr's have that much room?), or the average reading would have to be no more than 128 (for 4 bits increase), because 256 readings would be needed, and the sum of all 256 readings would have to fit into an int. (32767 / 256 = 128). Changing OverSample to use unsigned ints could enable an average reading of 256, but isn't tested properly yet. |
Definition at line 42 of file OverSample.h.
Public Member Functions | |
T | next (T input) |
Oversample and decimate the input to increase resolution by RESOLUTION_INCREASE_BITS;. More... | |
|
inline |
Oversample and decimate the input to increase resolution by RESOLUTION_INCREASE_BITS;.
input | an analog input to oversample. |
Definition at line 53 of file OverSample.h.
class RollingAverage |
Calculates a running average over a specified number of the most recent readings.
Like Smooth(), this is good for smoothing analog inputs in updateControl().
WINDOW_LENGTH | the number of readings to include in the rolling average. It must be a power of two (unless you're averaging floats). The higher the number, the more the readings will be smoothed, but the slower the output will respond to the input. |
Definition at line 36 of file RollingAverage.h.
Public Member Functions | |
RollingAverage () | |
Constructor. More... | |
T | next (T input) |
Give the average of the last WINDOW_LENGTH. More... | |
Protected Member Functions | |
T | add (T input) |
|
inline |
Constructor.
T | the type of numbers to average, eg. int, unsigned int, float etc. It will be relatively slow with floating point numbers, as it will use a divide operation for the averaging. Nevertheless, there might be a time when it's useful. |
WINDOW_LENGTH | the number of readings to keep track of. It must be a power of two (unless you're averaging floats). The higher the number, the more the readings will be smoothed, but the slower the output will respond to the input. |
Definition at line 50 of file RollingAverage.h.
|
inline |
Give the average of the last WINDOW_LENGTH.
input | a control signal such as an analog input which needs smoothing. |
Definition at line 63 of file RollingAverage.h.
class RollingStat |
WARNING: this class is work in progress, don't use it yet.
Calculates an approximation of the variance and standard deviation for a window of recent inputs.
T | the type of numbers to use. Choose unsigned int, int , uint8_t, int8_t, or float |
WINDOW_LENGTH | how many recent input values to include in the calculations. |
Definition at line 27 of file RollingStat.h.
Public Member Functions | |
RollingStat () | |
Constructor. | |
void | update (T x) |
Update the mean and variance given a new input value. More... | |
void | update (int8_t x) |
Update the mean and variance given a new input value. More... | |
T | getMean () const |
Return the mean of the last WINDOW_LENGTH number of inputs. More... | |
T | getVariance () const |
Return the approximate variance of the last WINDOW_LENGTH number of inputs. More... | |
T | getStandardDeviation () const |
Return the approximate standard deviation of the last WINDOW_LENGTH number of inputs. More... | |
|
inline |
Return the mean of the last WINDOW_LENGTH number of inputs.
Definition at line 60 of file RollingStat.h.
|
inline |
Return the approximate standard deviation of the last WINDOW_LENGTH number of inputs.
Definition at line 77 of file RollingStat.h.
|
inline |
Return the approximate variance of the last WINDOW_LENGTH number of inputs.
Definition at line 70 of file RollingStat.h.
|
inline |
Update the mean and variance given a new input value.
x | the next input value |
Definition at line 50 of file RollingStat.h.
|
inline |
Update the mean and variance given a new input value.
x | the next input value |
Definition at line 40 of file RollingStat.h.