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

[LowPass] added first draft of LowPass filter

parent db2db92f
Branches
No related tags found
No related merge requests found
......@@ -43,6 +43,7 @@ foreach(OPT_BOARD ${BOARDS})
${SBS_BASE}/src/shared/algorithms/NAS/StateInitializer.cpp
${SBS_BASE}/src/shared/algorithms/SFD/SFDAscent.cpp
${SBS_BASE}/src/shared/algorithms/SFD/SFDDescent.cpp
${SBS_BASE}/src/shared/algorithms/Filters/LowPass.cpp
# Debug
${SBS_BASE}/src/shared/utils/Debug.cpp
......
/* Copyright (c) 2023 Skyward Experimental Rocketry
* Author: Federico Lolli
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "LowPass.h"
namespace Boardcore
{
// TODO: WARNING! initialized at 0
LowPass::LowPass(float gain, float cutoff_freq, float lambda)
: gain(gain), cutoff_freq(cutoff_freq), lambda(lambda), output(0)
{
}
float LowPass::filter(float input)
{
output = lambda * output + (gain / cutoff_freq) * (1 - lambda) * input;
return output;
}
} // namespace Boardcore
/* Copyright (c) 2023 Skyward Experimental Rocketry
* Author: Federico Lolli
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
namespace Boardcore
{
class LowPass
{
public:
/**
* @brief Construct a new Low Pass object
*
* @param gain The gain of the filter
* @param cutoff_freq The cutoff frequency of the filter
* @param lambda The lambda parameter of the filter
*
* @note WARNING: Initialize output at 0 at first
*/
LowPass(float gain, float cutoff_freq, float lambda);
/**
* @brief Filter the input
*
* @param input The input to filter
*/
float filter(float input);
private:
float cutoff_freq;
float lambda;
float gain;
float output;
};
} // namespace Boardcore
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment