Normalizer

This filtering unit regularizes incoming signals by normalizing them around a target mean and standard deviation. It works by computing the normal distribution of the incoming data (mean and standard variation) and uses this information to re-normalize the data according to a different normal distribution (target mean and variance).

By default, the unit computes the mean and variance over all the data ever received. However, it can instead compute over a time window using an exponential moving average.

Example

Uses a normalizer to analyze input sensor values and detect extreme values.

#include <Plaquette.h>

// Analog sensor (eg. photocell or microphone).
AnalogIn sensor(A0);

// Creates a normalizer with mean 0 and standard deviation 1.
Normalizer normalizer(0, 1);

// Output indicator LED.
DigitalOut led(13);

void begin() {}

void step() {
  // Normalize value.
  sensor >> normalizer;

  // Light led if value differs from mean by more
  // than twice the standard deviation.
  (abs(normalizer) > 2.0) >> led;
}

Reference

class Normalizer : public MovingFilter, public MovingStats

Adaptive normalizer: normalizes values on-the-run using exponential moving averages over mean and standard deviation.

Public Functions

Normalizer()

Default constructor.

Will renormalize data around a mean of 0.5 and a standard deviation of 0.15.

Normalizer(float timeWindow)

Will renormalize data around a mean of 0.5 and a standard deviation of 0.15.

Parameters:

smoothWindow – specifies the approximate “time window” over which the normalization applies(in seconds)

Normalizer(float mean, float stdDev)

Constructor with infinite time window.

Parameters:
  • mean – the target mean

  • stdDev – the target standard deviation

  • smoothWindow – specifies the approximate “time window” over which the normalization applies(in seconds)

Normalizer(float mean, float stdDev, float timeWindow)

Constructor.

Parameters:
  • mean – the target mean

  • stdDev – the target standard deviation

  • smoothWindow – specifies the approximate “time window” over which the normalization applies(in seconds)

inline void targetMean(float mean)

Sets target mean of normalized values.

Parameters:

mean – the target mean

inline float targetMean() const

Returns target mean.

inline void targetStdDev(float stdDev)

Sets target standard deviation of normalized values.

Parameters:

stdDev – the target standard deviation

inline float targetStdDev() const

Returns target standard deviation.

virtual void infiniteTimeWindow()

Sets time window to infinite.

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 reset()

Resets the statistics.

virtual float put(float value)

Pushes value into the unit.

If isStarted() is false the filter will not be updated but will just return the filtered value.

Parameters:

value – the value sent to the unit

Returns:

the new value of the unit

virtual float lowOutlierThreshold(float nStdDev = 1.5f) const

Returns value above which value is considered to be a low outler (below average).

Parameters:

nStdDev – the number of standard deviations (typically between 1 and 3); low values = more sensitive

virtual float highOutlierThreshold(float nStdDev = 1.5f) const

Returns value above which value is considered to be a high outler (above average).

Parameters:

nStdDev – the number of standard deviations (typically between 1 and 3); low values = more sensitive

bool isClamped() const

Return true iff the normalized value is clamped within reasonable range.

void clamp(float nStdDev = NORMALIZER_DEFAULT_CLAMP_STDDEV)

Assign clamping value.

Values will then be clamped between reasonable range (targetMean() +/- nStdDev * targetStdDev()).

Parameters:

nStdDev – the number of standard deviations (default: 3.333333333)

void noClamp()

Remove clamping.

virtual void start()

Starts calibration.

When calibration is started, calls to put(value) will return normalized value AND update the normalization statistics.

virtual void stop()

Stops calibration.

When calibration is stopped, calls to put(value) will return normalized value without updating the normalization statistics.

virtual bool isStarted() const

Returns true iff the statistics have already been started.

inline virtual float get()

Returns value in [0, 1].

virtual bool isOutlier(float value, float nStdDev = 1.5f) const

Returns true if the value is considered an outlier.

Parameters:
  • value – the raw value to be tested (non-normalized)

  • nStdDev – the number of standard deviations (typically between 1 and 3); low values = more sensitive

Returns:

true if value is nStdDev number of standard deviations above or below mean

virtual bool isLowOutlier(float value, float nStdDev = 1.5f) const

Returns true if the value is considered a low outlier (below average).

Parameters:
  • value – the raw value to be tested (non-normalized)

  • nStdDev – the number of standard deviations (typically between 1 and 3); low values = more sensitive

Returns:

true if value is nStdDev number of standard deviations below mean

virtual bool isHighOutlier(float value, float nStdDev = 1.5f) const

Returns true if the value is considered a high outlier (above average).

Parameters:
  • value – the raw value to be tested (non-normalized)

  • nStdDev – the number of standard deviations (typically between 1 and 3); low values = more sensitive

Returns:

true if value is nStdDev number of standard deviations above mean

See Also