Smoother

Smooths the incoming signal by removing fast variations and noise (high frequencies).

_images/Plaquette-Smooth.png

Example

Smooth a sensor over time.

#include <Plaquette.h>

AnalogIn sensor(A0);

// Smooths over time window of 10 seconds.
Smoother smoother(10.0);

StreamOut serialOut(Serial);

void begin() {}

void step() {
  // Smooth value and send it to serial output.
  sensor >> smoother >> serialOut;
}

Note

The filter uses an exponential moving average which corresponds to a form of low-pass filter.

Reference

class Smoother : public MovingFilter

Simple moving average transform filter.

Public Functions

Smoother(Engine &engine = Engine::primary())

Constructor with default smoothing.

Parameters

engine – the engine running this unit

Smoother(float smoothingWindow, Engine &engine = Engine::primary())

Constructor with smoothing window.

Parameters
  • smoothingWindow – the time window over which the smoothing applies (in seconds)

  • engine – the engine running this unit

virtual float put(float value)

Pushes value into the unit.

Parameters

value – the value sent to the unit

Returns

the new value of the unit

virtual float filter(float value)

Returns the filtered value (without calibrating).

virtual void reset()

Resets the filter.

virtual void reset(float estimatedMeanValue)

Resets the filter with a prior estimate of the mean value.

virtual void reset(float estimatedMinValue, float estimatedMaxValue)

Resets the moving filter with a prior estimate of the min and max values.

virtual void resumeCalibrating()

Switches to calibration mode (default).

Calls to put(value) will return filtered value AND update the normalization statistics.

virtual void pauseCalibrating()

Switches to non-calibration mode: calls to put(value) will return filtered value without updating the normalization statistics.

virtual void toggleCalibrating()

Toggles calibration mode.

virtual bool isCalibrating() const

Returns true iff the moving filter is in calibration mode.

inline unsigned int nSamples() const

Returns the number of samples that have been processed thus far.

inline virtual bool isPreInitialized() const

Returns true if the moving filter has been initialized with a starting range at reset.

inline virtual float get()

Returns value in [0, 1].

inline virtual float mapTo(float toLow, float toHigh)

Maps value to new range.

inline float seconds() const

Returns engine time in seconds.

inline uint32_t milliSeconds() const

Returns engine time in milliseconds.

inline uint64_t microSeconds() const

Returns engine time in microseconds.

inline unsigned long nSteps() const

Returns number of engine steps.

inline float sampleRate() const

Returns engine sample rate.

inline float samplePeriod() const

Returns enginesample period.

inline operator float()

Object can be used directly to access its value.

inline explicit operator bool()

Operator that allows usage in conditional expressions.

virtual void infiniteTimeWindow()

Sets time window to infinite.

virtual void noTimeWindow()

Sets time window to no time window.

virtual void timeWindow(float seconds)

Changes the time window (expressed in seconds).

inline virtual float timeWindow() const

Returns the time window (expressed in seconds).

inline virtual bool timeWindowIsInfinite() const

Returns true if time window is infinite.

virtual void cutoff(float hz)

Changes the time window cutoff frequency (expressed in Hz).

virtual float cutoff() const

Returns the time window cutoff frequency (expressed in Hz).

Public Static Functions

static inline bool analogToDigital(float f)

Converts analog (float) value to digital (bool) value.

static inline float digitalToAnalog(bool b)

Converts digital (bool) value to analog (float) value.

See Also