Mozzi  version v1.1.0
sound synthesis library for Arduino
OverSample< T, RESOLUTION_INCREASE_BITS > Class Template Reference

Enables the resolution of analog inputs to be increased by oversampling and decimation. More...

#include <OverSample.h>

+ Inheritance diagram for OverSample< T, RESOLUTION_INCREASE_BITS >:

Public Member Functions

next (T input)
 Oversample and decimate the input to increase resolution by RESOLUTION_INCREASE_BITS;. More...
 

Protected Member Functions

add (T input)
 

Detailed Description

template<class T, const uint8_t RESOLUTION_INCREASE_BITS>
class OverSample< T, RESOLUTION_INCREASE_BITS >

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.

Template Parameters
RESOLUTION_INCREASE_BITShow 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.
Note
The higher the resolution, the more lag there will be. It's almost a RollingAverage filter, with the difference that OverSample doesn't divide by as much as you would for an average.

Definition at line 42 of file OverSample.h.

Member Function Documentation

◆ next()

template<class T , const uint8_t RESOLUTION_INCREASE_BITS>
T OverSample< T, RESOLUTION_INCREASE_BITS >::next ( input)
inline

Oversample and decimate the input to increase resolution by RESOLUTION_INCREASE_BITS;.

Parameters
inputan analog input to oversample.
Returns
the higher resolution result.
Note
timing 5.7us

Definition at line 53 of file OverSample.h.