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

Regularizes signal into [0,1] using adaptive quantile tracking (robust to outliers). More...

#include <RobustScaler.h>

Inheritance diagram for pq::RobustScaler:
Collaboration diagram for pq::RobustScaler:

Public Member Functions

 RobustScaler (Engine &engine=Engine::primary())
 Default constructor.
 
 RobustScaler (float timeWindow, Engine &engine=Engine::primary())
 Constructor with custom quantile levels and time window.
 
 RobustScaler (float timeWindow, float span, Engine &engine=Engine::primary())
 Constructor with custom quantile levels and time window.
 
virtual void span (float span)
 Sets the span (in [0, 1]) of the quantile to track.
 
virtual float span () const
 Returns the current span.
 
virtual void lowQuantileLevel (float level)
 Sets the low quantile level (in [0, 0.5]). Low quantile will automatically be set to 1 - low.
 
virtual float lowQuantileLevel () const
 Returns the current low quantile level.
 
virtual void highQuantileLevel (float level)
 Sets the high quantile level (in [0.5, 1]). Low quantile will automatically be set to 1 - high.
 
virtual float highQuantileLevel () const
 Returns the current high quantile level.
 
virtual float lowQuantile () const
 Returns the current low quantile.
 
virtual float highQuantile () const
 Returns the current high quantile.
 
virtual float stdDev () const
 Returns the current standard deviation.
 
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 float get ()
 Returns value of scaler.
 
virtual float put (float value)
 Pushes a new value and returns the scaled output.
 
virtual float filter (float value)
 Returns the filtered value (without calibrating).
 
virtual void resumeCalibrating ()
 Switches to calibration mode (default).
 
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.
 
unsigned int nSamples () const
 Returns the number of samples that have been processed thus far.
 
virtual bool isPreInitialized () const
 Returns true if the moving filter has been initialized with a starting range at reset.
 
virtual float mapTo (float toLow, float toHigh)
 Maps value to new range.
 
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.
 
 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).
 
virtual float timeWindow () const
 Returns the time window (expressed in seconds).
 
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).
 

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.
 

Protected Member Functions

virtual void step ()
 
void _updateQuantile (float &q, float level, float eta, float x)
 
void _initializeRange (float minValue, float maxValue)
 
virtual void begin ()
 
virtual float alpha () const
 
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 _quantileLevel
 
float _lowQuantile
 
float _highQuantile
 
MovingAverage _stdDev
 
float _currentStdDevStep
 
bool _isCalibrating: 1
 
bool _isPreInitialized: 1
 
uint8_t _nValuesStep: 6
 
unsigned int _nSamples
 
float _value
 
float _timeWindow
 

Detailed Description

Regularizes signal into [0,1] using adaptive quantile tracking (robust to outliers).

Constructor & Destructor Documentation

◆ RobustScaler() [1/2]

pq::RobustScaler::RobustScaler ( float  timeWindow,
Engine engine = Engine::primary() 
)

Constructor with custom quantile levels and time window.

Parameters
timeWindowThe adaptation window in seconds.

◆ RobustScaler() [2/2]

pq::RobustScaler::RobustScaler ( float  timeWindow,
float  span,
Engine engine = Engine::primary() 
)

Constructor with custom quantile levels and time window.

Parameters
timeWindowThe adaptation window in seconds.
spanCorresponds to percentage coverage of value in [0, 1].

Member Function Documentation

◆ begin()

void pq::MovingFilter::begin ( )
protectedvirtualinherited

Reimplemented from pq::Unit.

◆ 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 >.

◆ filter()

float pq::RobustScaler::filter ( float  value)
virtual

Returns the filtered value (without calibrating).

Implements pq::MovingFilter.

◆ get()

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

Returns value of scaler.

Reimplemented from pq::AnalogSource.

◆ mapTo()

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

Maps value to new range.

Reimplemented from pq::Flowable.

Reimplemented in pq::Normalizer, pq::StreamIn, and pq::StreamOut.

◆ put()

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

Pushes a new value and returns the scaled output.

Reimplemented from pq::Flowable.

◆ reset() [1/3]

void pq::RobustScaler::reset ( )
virtual

Resets the filter.

Reimplemented from pq::MovingFilter.

◆ reset() [2/3]

void pq::RobustScaler::reset ( float  estimatedMeanValue)
virtual

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

Reimplemented from pq::MovingFilter.

◆ reset() [3/3]

void pq::RobustScaler::reset ( float  estimatedMinValue,
float  estimatedMaxValue 
)
virtual

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

Reimplemented from pq::MovingFilter.

◆ resumeCalibrating()

void pq::MovingFilter::resumeCalibrating ( )
virtualinherited

Switches to calibration mode (default).

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

◆ step()

void pq::RobustScaler::step ( )
protectedvirtual

Reimplemented from pq::Unit.


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