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

[SFD] respect naming guidelines and small const extraction refactor

parent 4545e041
No related branches found
No related tags found
1 merge request!224Draft: Sensor Fault Detection
......@@ -48,10 +48,7 @@ public:
float filter(float input);
private:
float cutoffFreq;
float lambda;
float gain;
float output;
float gain, cutoffFreq, lambda, output;
};
} // namespace Boardcore
......@@ -29,7 +29,7 @@
namespace Boardcore
{
SFDAscent::SFDAscent(const SFDAConfig& config) : svm(config.modelParameters) {}
SFDAscent::SFDAscent(const SFDAscentConfig& config) : svm(config.modelParameters) {}
SFDAscent::FeaturesVec SFDAscent::getFeatures(const VectorIn& input)
{
......@@ -41,17 +41,17 @@ SFDAscent::FeaturesVec SFDAscent::getFeatures(const VectorIn& input)
min = input.minCoeff();
max = input.maxCoeff();
delta = max - min;
for (int i = 0; i < lenChunk; i++)
for (int i = 0; i < LEN_CHUNK; i++)
data(i) = (input(i) - min) / (std::max(delta, 1e-25f) * 2) - 1;
u = data.mean();
x0 = data - u * VectorIn::Ones();
var = x0.squaredNorm() / lenChunk;
var = x0.squaredNorm() / LEN_CHUNK;
s2 = x0.array().pow(2).mean();
m4 = x0.array().pow(4).mean();
rfourier = FFT32::fft(data).real(); // TODO: fix complex -> float
rfmean = rfourier.mean();
rfvar = (rfourier - rfmean * VectorIn::Ones()).squaredNorm() / lenChunk;
rfvar = (rfourier - rfmean * VectorIn::Ones()).squaredNorm() / LEN_CHUNK;
features(0) = delta;
features(1) = var;
......
......@@ -28,25 +28,26 @@
#include <Eigen/Core>
#include "SFDCommon.h"
namespace Boardcore
{
class SFDAscent
{
public:
static constexpr int numFeatures = 6;
static constexpr int lenChunk = 32;
static constexpr int NUM_FEATURES = 6;
using SVMn = SVM<numFeatures>;
using FeaturesVec = Eigen::Vector<float, numFeatures>;
using VectorIn = Eigen::Vector<float, lenChunk>;
using SVMn = SVM<NUM_FEATURES>;
using FeaturesVec = Eigen::Vector<float, NUM_FEATURES>;
using VectorIn = Eigen::Vector<float, LEN_CHUNK>;
struct SFDAConfig
struct SFDAscentConfig
{
SVMn::SVMConfig modelParameters;
};
explicit SFDAscent(const SFDAConfig& config);
explicit SFDAscent(const SFDAscentConfig& config);
bool classify(const VectorIn& input);
......
/* 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
static constexpr int LEN_CHUNK = 32;
......@@ -27,7 +27,7 @@
namespace Boardcore
{
SFDDescent::SFDDescent(const SFDDConfig& config) : svm(config.modelParameters)
SFDDescent::SFDDescent(const SFDDescentConfig& config) : svm(config.modelParameters)
{
}
......@@ -41,7 +41,7 @@ SFDDescent::FeaturesVec SFDDescent::getFeatures(const VectorIn& input)
min = input.minCoeff();
max = input.maxCoeff();
delta = max - min;
for (int i = 0; i < lenChunk; i++)
for (int i = 0; i < LEN_CHUNK; i++)
data(i) = (input(i) - min) / (std::max(delta, 1e-25f) * 2) - 1;
u = data.mean();
x0 = data - u * VectorIn::Ones();
......
......@@ -28,25 +28,26 @@
#include <Eigen/Core>
#include "SFDCommon.h"
namespace Boardcore
{
class SFDDescent
{
public:
static constexpr int numFeatures = 5;
static constexpr int lenChunk = 32;
static constexpr int NUM_FEATURES = 5;
using SVMn = SVM<numFeatures>;
using FeaturesVec = Eigen::Vector<float, numFeatures>;
using VectorIn = Eigen::Vector<float, lenChunk>;
using SVMn = SVM<NUM_FEATURES>;
using FeaturesVec = Eigen::Vector<float, NUM_FEATURES>;
using VectorIn = Eigen::Vector<float, LEN_CHUNK>;
struct SFDDConfig
struct SFDDescentConfig
{
SVMn::SVMConfig modelParameters;
};
explicit SFDDescent(const SFDDConfig& config);
explicit SFDDescent(const SFDDescentConfig& config);
bool classify(const VectorIn& input);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment