Gaussian
The gaussian class provides an implementation of the gaussian function:
The class allows for dynamically changing the \(\alpha\), \(\beta\), and \(\gamma\) parameters.
API Reference
Header File
Classes
-
class Gaussian
Implements a gaussian function \(y(t)=\alpha\exp(-\frac{(t-\beta)^2}{2\gamma^2})\).
Alows you to store the alpha, beta, and gamma coefficients as well as update them dynamically.
Example
std::array<float, 4> gammas = { 0.10f, 0.15f, 0.20f, 0.25f, }; espp::Gaussian gaussian({ .gamma = gammas[0], .alpha = 1.0f, // default .beta = 0.5f, // default }); float t = 0; fmt::print("% t"); for (auto g : gammas) { fmt::print(", gaussian({})", g); } fmt::print("\n"); float increment = 0.05f; int num_increments = 1.0f / increment; for (int i = 0; i <= num_increments; i++) { fmt::print("{}", t); for (auto g : gammas) { // update the gamma gaussian.set_gamma(g); // evaluate it float v = gaussian(t); // print it fmt::print(", {}", v); } fmt::print("\n"); t += increment; }
Fade-In/Fade-Out Example
std::array<float, 8> gammas = { 0.10f, 0.15f, 0.20f, 0.25f, 0.30f, 0.35f, 0.40f, 0.45f, }; espp::Gaussian fade_in({ .gamma = gammas[0], .alpha = 1.0f, // default .beta = 1.0f, // default }); espp::Gaussian fade_out({ .gamma = gammas[0], .alpha = 1.0f, // default .beta = 0.0f, // default }); float t = 0; fmt::print("% t"); for (auto g : gammas) { fmt::print(", fade_in({}), fade_out({})", g, g); } fmt::print("\n"); float increment = 0.05f; int num_increments = 1.0f / increment; for (int i = 0; i <= num_increments; i++) { fmt::print("{}", t); for (auto g : gammas) { // update the gamma fade_in.set_gamma(g); fade_out.set_gamma(g); // evaluate it float in = fade_in(t); float out = fade_out(t); // print it fmt::print(", {}, {}", in, out); } fmt::print("\n"); t += increment; }
Public Functions
-
inline explicit Gaussian(const Config &config)
Construct the gaussian object, configuring its parameters.
- Parameters
config – Config structure for the gaussian.
-
inline float at(float t) const
Evaluate the gaussian at
t
.- Parameters
t – The evaluation parameter, [0, 1].
- Returns
The gaussian evaluated at
t
.
-
inline float operator()(float t) const
Evaluate the gaussian at
t
.Note
Convienience wrapper around the at() method.
- Parameters
t – The evaluation parameter, [0, 1].
- Returns
The gaussian evaluated at
t
.
-
inline void update(const Config &config)
Update the gaussian configuration.
- Parameters
config – The new configuration.
-
inline void set_config(const Config &config)
Set the configuration of the gaussian.
- Parameters
config – The new configuration.
-
inline Config get_config() const
Get the current configuration of the gaussian.
- Returns
The current configuration.
-
inline float get_gamma() const
Get the gamma value.
- Returns
The gamma value.
-
inline float get_alpha() const
Get the alpha value.
- Returns
The alpha value.
-
inline float get_beta() const
Get the beta value.
- Returns
The beta value.
-
inline void set_gamma(float gamma)
Set the gamma value.
- Parameters
gamma – The new gamma value.
-
inline void set_alpha(float alpha)
Set the alpha value.
- Parameters
alpha – The new alpha value.
-
inline void set_beta(float beta)
Set the beta value.
- Parameters
beta – The new beta value.
-
struct Config
Configuration structure for initializing the gaussian.
Public Members
-
float gamma
Slope of the gaussian, range [0, 1]. 0 is more of a thin spike from 0 up to max output (alpha), 1 is more of a small wave around the max output (alpha).
-
float alpha = {1.0f}
Max amplitude of the gaussian output, defautls to 1.0.
-
float beta{0.5f}
Beta value for the gaussian, default to be symmetric at 0.5 in range [0,1].
-
float gamma
-
inline explicit Gaussian(const Config &config)