Plaquette
 
Loading...
Searching...
No Matches
pq::Smoother Class Reference

Simple moving average transform filter. More...

#include <Smoother.h>

Inheritance diagram for pq::Smoother:
Collaboration diagram for pq::Smoother:

Public Member Functions

 Smoother (Engine &engine=Engine::primary())
 Constructor with default smoothing.
 
 Smoother (float smoothingWindow, Engine &engine=Engine::primary())
 Constructor with smoothing window.
 
virtual float put (float value)
 Pushes value into the unit.
 
virtual float get ()
 Returns smoothed value.
 
virtual void clearEvents ()
 
float seconds () const
 Returns engine time in seconds.
 
uint32_t milliSeconds () const
 Returns engine time in milliseconds.
 
uint64_t microSeconds () const
 Returns engine time in microseconds.
 
unsigned long nSteps () const
 Returns number of engine steps.
 
float sampleRate () const
 Returns engine sample rate.
 
float samplePeriod () const
 Returns enginesample period.
 
 operator float ()
 Object can be used directly to access its value.
 
virtual float mapTo (float toLow, float toHigh)
 Maps value to new range.
 
 operator bool ()
 Operator that allows usage in conditional expressions.
 
void infiniteTimeWindow ()
 Sets to "infinite" smoothing window.
 
void timeWindow (float seconds)
 Changes the smoothing window (expressed in seconds).
 
float timeWindow () const
 Returns the smoothing window (expressed in seconds).
 
bool timeWindowIsInfinite () const
 Returns true if time window is infinite.
 
void cutoff (float hz)
 Changes the smoothing window cutoff frequency (expressed in Hz).
 
float cutoff () const
 Returns the smoothing window cutoff frequency (expressed in Hz).
 
float alpha (float sampleRate) const
 Returns the alpha value computed from given sample rate.
 
void reset ()
 Resets the moving average.
 
virtual float update (float v, float sampleRate=1, bool forceAlpha=false)
 Updates the moving average with new value v# (also returns the current value).
 
float constGet () const
 
unsigned int nSamples () const
 Returns the number of samples processed since reset().
 
void amendUpdate (float previousValue, float newValue, float sampleRate=1, bool forceAlpha=false)
 Performs an amendment of latest update (needs to be called with same sampleRate# and forceAlpha# parameters).
 

Static Public Member Functions

static bool analogToDigital (float f)
 Converts analog (float) value to digital (bool) value.
 
static float digitalToAnalog (bool b)
 Converts digital (bool) value to analog (float) value.
 
static float alpha (float sampleRate, float timeWindow, unsigned int nSamples=UINT_MAX)
 Returns the alpha value computed from given sample rate, time window, and number of samples.
 
static void applyUpdate (float &runningValue, float newValue, float alpha)
 Applies a single update on runningValue# with new sample newValue# and mixing factor alpha#.
 
static void applyAmendUpdate (float &runningValue, float previousValue, float newValue, float alpha)
 Performs an amendment of latest update (needs to be called with same alpha# parameter).
 
static float computeUpdate (float runningValue, float newValue, float alpha)
 Computes a single update on runningValue# with new sample newValue# and mixing factor alpha#.
 

Protected Member Functions

virtual void step ()
 
virtual void begin ()
 
virtual bool eventTriggered (EventType eventType)
 Returns true iff an event of a certain type has been triggered.
 
virtual void onEvent (EventCallback callback, EventType eventType)
 Registers event callback.
 
Engineengine () const
 Returns the engine that owns this unit.
 

Protected Attributes

float _currentValueStep
 
uint8_t _nValuesStep
 
float _smoothTime
 
float _value
 
unsigned int _nSamples
 

Detailed Description

Simple moving average transform filter.

Constructor & Destructor Documentation

◆ Smoother() [1/2]

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

Constructor with default smoothing.

Parameters
enginethe engine running this unit

◆ Smoother() [2/2]

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

Constructor with smoothing window.

Parameters
smoothingWindowthe time window over which the smoothing applies (in seconds)
enginethe engine running this unit

Member Function Documentation

◆ eventTriggered()

virtual bool pq::Unit::eventTriggered ( EventType  eventType)
inlineprotectedvirtualinherited

Returns true iff an event of a certain type has been triggered.

Reimplemented in pq::AbstractWave, pq::Alarm, pq::Metronome, pq::PeakDetector, pq::DigitalSource, pq::Ramp, pq::StreamIn, and pq::TimeSliceField< COUNT >.

◆ get()

virtual float pq::Smoother::get ( )
inlinevirtual

Returns smoothed value.

Reimplemented from pq::Chainable.

◆ mapTo()

virtual float pq::Chainable::mapTo ( float  toLow,
float  toHigh 
)
inlinevirtualinherited

Maps value to new range.

This function guarantees that the value is within [toLow, toHigh]. If the unit's values are unbounded, returns get() constrained to [toLow, toHigh].

Reimplemented in pq::Normalizer, pq::DigitalUnit, pq::AnalogSource, pq::AnalogIn, pq::Ramp, pq::StreamIn, and pq::StreamOut.

◆ put()

float pq::Smoother::put ( float  value)
virtual

Pushes value into the unit.

Parameters
valuethe value sent to the unit
Returns
the new value of the unit

Reimplemented from pq::Chainable.

◆ step()

void pq::Smoother::step ( )
protectedvirtual

Reimplemented from pq::Unit.


The documentation for this class was generated from the following files: