FastLED 3.9.15
Loading...
Searching...
No Matches
fl::detail::SpectralVarianceImpl< T > Class Template Reference

Detailed Description

template<typename T = float>
class fl::detail::SpectralVarianceImpl< T >

Multi-channel EMA with per-bin relative deviation measurement.

Smooths each channel (bin) with an exponential moving average, then computes the mean relative deviation of the current values from the smoothed values. Useful for detecting temporal instability in multi-dimensional signals (e.g., spectral bins, sensor arrays).

update(): O(N) Memory: N*T (one EMA state per channel)

SpectralVarianceImpl<float> sv(0.2f); // alpha=0.2, ~5 frame window float variance = sv.update(fftBins); // returns mean relative deviation

The alpha parameter controls the EMA speed:

  • alpha=0.1: slow tracking, 10-frame window, detects slower changes
  • alpha=0.2: moderate tracking, 5-frame window (default)
  • alpha=0.5: fast tracking, 2-frame window, detects rapid transients

The floor parameter prevents division by zero in near-silent channels. Channels below the floor are excluded from the deviation calculation.

Definition at line 29 of file spectral_variance_impl.h.

#include <spectral_variance_impl.h>

+ Inheritance diagram for fl::detail::SpectralVarianceImpl< T >:
+ Collaboration diagram for fl::detail::SpectralVarianceImpl< T >:

Public Member Functions

 SpectralVarianceImpl (T alpha=T(0.2f), T floor=T(1e-4f))
 
void reset ()
 Reset all internal state.
 
void setAlpha (T alpha)
 Change the EMA alpha (tracking speed).
 
void setFloor (T floor)
 Change the floor threshold for active channel detection.
 
fl::size size () const
 Get the number of channels being tracked.
 
update (fl::span< const T > bins)
 Feed a new frame of multi-channel data.
 
value () const
 Get the last computed variance without updating.
 

Private Attributes

mAlpha
 
mFloor
 
fl::vector< T > mSmoothed
 
mVariance
 

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