Skip to content
Snippets Groups Projects
Commit ed1169f7 authored by Federico Lolli's avatar Federico Lolli
Browse files

[LowPass] added config constructor

parent 1fc1e275
Branches
Tags
1 merge request!227FFT and other Utilities (Filters and Windows)
...@@ -26,12 +26,19 @@ namespace Boardcore ...@@ -26,12 +26,19 @@ namespace Boardcore
{ {
// TODO: WARNING! initialized at 0 // 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) LowPass::LowPass(float gain, float cutoffFreq, float lambda)
: gain(gain), cutoffFreq(cutoffFreq), lambda(lambda), output(0) : 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) float LowPass::filter(float input)
{ {
output = lambda * output + (gain / cutoffFreq) * (1 - lambda) * input; output = lambda * output + (gain / cutoffFreq) * (1 - lambda) * input;
......
...@@ -25,21 +25,41 @@ ...@@ -25,21 +25,41 @@
namespace Boardcore namespace Boardcore
{ {
/**
* @brief Online Low Pass filter with frequency-aware parameters
*/
class LowPass class LowPass
{ {
public: 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 gain The gain of the filter
* @param cutoffFreq The cutoff frequency of the filter * @param cutoffFreq The cutoff frequency of the filter
* @param lambda The lambda parameter of the filter * @param lambda The lambda parameter of the filter
* *
* @note WARNING: Initialize output at 0 at first * @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); 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 * @brief Filter the input
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment