diff --git a/src/shared/algorithms/Filters/LowPass.cpp b/src/shared/algorithms/Filters/LowPass.cpp index 142c97f6c0505797b37e830a7387e62346c90a86..cdb97376f786b2d99e5ef4b4549b7f01cf96ea55 100644 --- a/src/shared/algorithms/Filters/LowPass.cpp +++ b/src/shared/algorithms/Filters/LowPass.cpp @@ -26,12 +26,19 @@ namespace Boardcore { // TODO: WARNING! initialized at 0 -// WARNING: frequency set by parameters, look for these anyway +// WARNING: frequency set by parameters, look for these in any case LowPass::LowPass(float gain, float cutoffFreq, float lambda) : gain(gain), cutoffFreq(cutoffFreq), lambda(lambda), output(0) { } +// TODO: WARNING! initialized at 0 +// WARNING: frequency set by parameters, look for these in any case +LowPass::LowPass(const LowPassConfig& config) + : LowPass(config.gain, config.cutoffFreq, config.lambda) +{ +} + float LowPass::filter(float input) { output = lambda * output + (gain / cutoffFreq) * (1 - lambda) * input; diff --git a/src/shared/algorithms/Filters/LowPass.h b/src/shared/algorithms/Filters/LowPass.h index 49f5c2b7e5fa5c5218b012ebd755ad9db72ced0a..ebd1ab7cdd441f8a48f40ad14c687fbd9586e422 100644 --- a/src/shared/algorithms/Filters/LowPass.h +++ b/src/shared/algorithms/Filters/LowPass.h @@ -25,21 +25,41 @@ namespace Boardcore { +/** + * @brief Online Low Pass filter with frequency-aware parameters + */ class LowPass { public: + struct LowPassConfig + { + float gain; + float cutoffFreq; + float lambda; + }; + /** - * @brief Construct a new Low Pass object + * @brief Construct an online Low Pass by providing each parameter * * @param gain The gain of the filter * @param cutoffFreq The cutoff frequency of the filter * @param lambda The lambda parameter of the filter * * @note WARNING: Initialize output at 0 at first - * @note WARNING: frequency set by parameters, look for these anyway + * @note WARNING: frequency set by parameters, look for these in any case */ LowPass(float gain, float cutoffFreq, float lambda); + /** + * @brief Construct an online Low Pass from a configuration + * + * @param config The configuration of the filter + * + * @note WARNING: Initialize output at 0 at first + * @note WARNING: frequency set by parameters, look for these in any case + */ + explicit LowPass(const LowPassConfig& config); + /** * @brief Filter the input *